@@ -130,7 +130,7 @@ export class FocusTrap {
130
130
* Waits for the zone to stabilize, then either focuses the first element that the
131
131
* user specified, or the first tabbable element.
132
132
* @returns Returns a promise that resolves with a boolean, depending
133
- * on whether focus was moved successfuly .
133
+ * on whether focus was moved successfully .
134
134
*/
135
135
focusInitialElementWhenReady ( ) : Promise < boolean > {
136
136
return new Promise < boolean > ( resolve => {
@@ -142,7 +142,7 @@ export class FocusTrap {
142
142
* Waits for the zone to stabilize, then focuses
143
143
* the first tabbable element within the focus trap region.
144
144
* @returns Returns a promise that resolves with a boolean, depending
145
- * on whether focus was moved successfuly .
145
+ * on whether focus was moved successfully .
146
146
*/
147
147
focusFirstTabbableElementWhenReady ( ) : Promise < boolean > {
148
148
return new Promise < boolean > ( resolve => {
@@ -154,7 +154,7 @@ export class FocusTrap {
154
154
* Waits for the zone to stabilize, then focuses
155
155
* the last tabbable element within the focus trap region.
156
156
* @returns Returns a promise that resolves with a boolean, depending
157
- * on whether focus was moved successfuly .
157
+ * on whether focus was moved successfully .
158
158
*/
159
159
focusLastTabbableElementWhenReady ( ) : Promise < boolean > {
160
160
return new Promise < boolean > ( resolve => {
@@ -195,11 +195,11 @@ export class FocusTrap {
195
195
196
196
/**
197
197
* Focuses the element that should be focused when the focus trap is initialized.
198
- * @returns Whether focus was moved successfuly .
198
+ * @returns Whether focus was moved successfully .
199
199
*/
200
200
focusInitialElement ( ) : boolean {
201
201
// Contains the deprecated version of selector, for temporary backwards comparability.
202
- const redirectToElement = this . _element . querySelector ( `[cdk-focus-initial], ` +
202
+ let redirectToElement = this . _element . querySelector ( `[cdk-focus-initial], ` +
203
203
`[cdkFocusInitial]` ) as HTMLElement ;
204
204
205
205
if ( redirectToElement ) {
@@ -217,6 +217,16 @@ export class FocusTrap {
217
217
console . warn ( `Element matching '[cdkFocusInitial]' is not focusable.` , redirectToElement ) ;
218
218
}
219
219
220
+ if ( ! this . _checker . isFocusable ( redirectToElement ) ) {
221
+ redirectToElement = this . _getFirstTabbableElement ( redirectToElement ) as HTMLElement ;
222
+ if ( redirectToElement ) {
223
+ redirectToElement . focus ( ) ;
224
+ return true ;
225
+ } else {
226
+ return false ;
227
+ }
228
+ }
229
+
220
230
redirectToElement . focus ( ) ;
221
231
return true ;
222
232
}
@@ -226,7 +236,7 @@ export class FocusTrap {
226
236
227
237
/**
228
238
* Focuses the first tabbable element within the focus trap region.
229
- * @returns Whether focus was moved successfuly .
239
+ * @returns Whether focus was moved successfully .
230
240
*/
231
241
focusFirstTabbableElement ( ) : boolean {
232
242
const redirectToElement = this . _getRegionBoundary ( 'start' ) ;
@@ -240,7 +250,7 @@ export class FocusTrap {
240
250
241
251
/**
242
252
* Focuses the last tabbable element within the focus trap region.
243
- * @returns Whether focus was moved successfuly .
253
+ * @returns Whether focus was moved successfully .
244
254
*/
245
255
focusLastTabbableElement ( ) : boolean {
246
256
const redirectToElement = this . _getRegionBoundary ( 'end' ) ;
@@ -253,7 +263,7 @@ export class FocusTrap {
253
263
}
254
264
255
265
/**
256
- * Checks whether the focus trap has successfuly been attached.
266
+ * Checks whether the focus trap has successfully been attached.
257
267
*/
258
268
hasAttached ( ) : boolean {
259
269
return this . _hasAttached ;
@@ -396,7 +406,7 @@ export class CdkTrapFocus implements OnDestroy, AfterContentInit, OnChanges, DoC
396
406
set enabled ( value : boolean ) { this . focusTrap . enabled = coerceBooleanProperty ( value ) ; }
397
407
398
408
/**
399
- * Whether the directive should automatially move focus into the trapped region upon
409
+ * Whether the directive should automatically move focus into the trapped region upon
400
410
* initialization and return focus to the previous activeElement upon destruction.
401
411
*/
402
412
@Input ( 'cdkTrapFocusAutoCapture' )
0 commit comments