1
- import { Component , BaseOptions , InitElements , MElement , Openable } from './component' ;
1
+ import { Component , BaseOptions , InitElements , MElement , Openable } from "./component" ;
2
+ import { Utils } from './utils' ;
2
3
3
4
export interface FloatingActionButtonOptions extends BaseOptions {
4
5
/**
@@ -62,10 +63,16 @@ export class FloatingActionButton
62
63
this . offsetX = 0 ;
63
64
64
65
this . el . classList . add ( `direction-${ this . options . direction } ` ) ;
65
- if ( this . options . direction === 'top' ) this . offsetY = 40 ;
66
- else if ( this . options . direction === 'right' ) this . offsetX = - 40 ;
67
- else if ( this . options . direction === 'bottom' ) this . offsetY = - 40 ;
68
- else this . offsetX = 40 ;
66
+ this . _anchor . tabIndex = 0 ;
67
+ this . _menu . ariaExpanded = 'false' ;
68
+ if ( this . options . direction === 'top' )
69
+ this . offsetY = 40 ;
70
+ else if ( this . options . direction === 'right' )
71
+ this . offsetX = - 40 ;
72
+ else if ( this . options . direction === 'bottom' )
73
+ this . offsetY = - 40 ;
74
+ else
75
+ this . offsetX = 40 ;
69
76
this . _setupEventHandlers ( ) ;
70
77
}
71
78
@@ -119,6 +126,7 @@ export class FloatingActionButton
119
126
} else {
120
127
this . el . addEventListener ( 'click' , this . _handleFABClick ) ;
121
128
}
129
+ this . el . addEventListener ( 'keypress' , this . _handleFABKeyPress ) ;
122
130
}
123
131
124
132
_removeEventHandlers ( ) {
@@ -128,9 +136,20 @@ export class FloatingActionButton
128
136
} else {
129
137
this . el . removeEventListener ( 'click' , this . _handleFABClick ) ;
130
138
}
139
+ this . el . removeEventListener ( 'keypress' , this . _handleFABKeyPress ) ;
131
140
}
132
141
133
142
_handleFABClick = ( ) => {
143
+ this . _handleFABToggle ( )
144
+ }
145
+
146
+ _handleFABKeyPress = ( e ) => {
147
+ if ( Utils . keys . ENTER . includes ( e . key ) ) {
148
+ this . _handleFABToggle ( ) ;
149
+ }
150
+ }
151
+
152
+ _handleFABToggle = ( ) => {
134
153
if ( this . isOpen ) {
135
154
this . close ( ) ;
136
155
} else {
@@ -169,6 +188,7 @@ export class FloatingActionButton
169
188
170
189
_animateInFAB ( ) {
171
190
this . el . classList . add ( 'active' ) ;
191
+ this . _menu . ariaExpanded = 'true' ;
172
192
const delayIncrement = 40 ;
173
193
const duration = 275 ;
174
194
@@ -186,19 +206,24 @@ export class FloatingActionButton
186
206
el . style . transition = `opacity ${ duration } ms ease, transform ${ duration } ms ease` ;
187
207
el . style . opacity = '1' ;
188
208
el . style . transform = 'translate(0, 0) scale(1)' ;
209
+ el . tabIndex = 0 ;
189
210
} , 1 ) ;
190
211
} , delay ) ;
191
212
} ) ;
192
213
}
193
214
194
215
_animateOutFAB ( ) {
195
216
const duration = 175 ;
196
- setTimeout ( ( ) => this . el . classList . remove ( 'active' ) , duration ) ;
217
+ setTimeout ( ( ) => {
218
+ this . el . classList . remove ( 'active' ) , duration ;
219
+ this . _menu . ariaExpanded = 'false' ;
220
+ } ) ;
197
221
this . _floatingBtnsReverse . forEach ( ( el ) => {
198
222
el . style . transition = `opacity ${ duration } ms ease, transform ${ duration } ms ease` ;
199
223
// to
200
224
el . style . opacity = '0' ;
201
225
el . style . transform = `translate(${ this . offsetX } px, ${ this . offsetY } px) scale(0.4)` ;
226
+ el . tabIndex = - 1 ;
202
227
} ) ;
203
228
}
204
229
@@ -228,6 +253,7 @@ export class FloatingActionButton
228
253
this . el . style . left = '0' ;
229
254
this . el . style . transform = 'translateX(' + this . offsetX + 'px)' ;
230
255
this . el . style . transition = 'none' ;
256
+ this . _menu . ariaExpanded = 'true' ;
231
257
232
258
this . _anchor . style . transform = `translateY(${ this . offsetY } px` ;
233
259
this . _anchor . style . transition = 'none' ;
@@ -248,9 +274,10 @@ export class FloatingActionButton
248
274
backdrop . style . transform = 'scale(' + scaleFactor + ')' ;
249
275
backdrop . style . transition = 'transform .2s cubic-bezier(0.550, 0.055, 0.675, 0.190)' ;
250
276
251
- this . _menu
252
- . querySelectorAll ( 'li > a' )
253
- . forEach ( ( a : HTMLAnchorElement ) => ( a . style . opacity = '1' ) ) ;
277
+ this . _menu . querySelectorAll ( 'li > a' ) . forEach ( ( a : HTMLAnchorElement ) => {
278
+ a . style . opacity = '1' ;
279
+ a . tabIndex = 0 ;
280
+ } ) ;
254
281
255
282
// Scroll to close.
256
283
window . addEventListener ( 'scroll' , this . close , true ) ;
0 commit comments