@@ -24,10 +24,9 @@ import {InteractivityChecker} from './interactivity-checker';
24
24
/**
25
25
* Class that allows for trapping focus within a DOM element.
26
26
*
27
- * NOTE: This class currently uses a very simple (naive) approach to focus trapping.
27
+ * This class currently uses a relatively simple approach to focus trapping.
28
28
* It assumes that the tab order is the same as DOM order, which is not necessarily true.
29
29
* Things like tabIndex > 0, flex `order`, and shadow roots can cause to two to misalign.
30
- * This will be replaced with a more intelligent solution before the library is considered stable.
31
30
*/
32
31
export class FocusTrap {
33
32
private _startAnchor : HTMLElement | null ;
@@ -169,7 +168,7 @@ export class FocusTrap {
169
168
170
169
/**
171
170
* Focuses the element that should be focused when the focus trap is initialized.
172
- * @returns Returns whether focus was moved successfuly.
171
+ * @returns Whether focus was moved successfuly.
173
172
*/
174
173
focusInitialElement ( ) : boolean {
175
174
if ( ! this . _platform . isBrowser ) {
@@ -188,7 +187,7 @@ export class FocusTrap {
188
187
189
188
/**
190
189
* Focuses the first tabbable element within the focus trap region.
191
- * @returns Returns whether focus was moved successfuly.
190
+ * @returns Whether focus was moved successfuly.
192
191
*/
193
192
focusFirstTabbableElement ( ) : boolean {
194
193
const redirectToElement = this . _getRegionBoundary ( 'start' ) ;
@@ -202,7 +201,7 @@ export class FocusTrap {
202
201
203
202
/**
204
203
* Focuses the last tabbable element within the focus trap region.
205
- * @returns Returns whether focus was moved successfuly.
204
+ * @returns Whether focus was moved successfuly.
206
205
*/
207
206
focusLastTabbableElement ( ) : boolean {
208
207
const redirectToElement = this . _getRegionBoundary ( 'end' ) ;
@@ -287,14 +286,23 @@ export class FocusTrapFactory {
287
286
private _platform : Platform ,
288
287
private _ngZone : NgZone ) { }
289
288
290
- create ( element : HTMLElement , deferAnchors : boolean = false ) : FocusTrap {
291
- return new FocusTrap ( element , this . _platform , this . _checker , this . _ngZone , deferAnchors ) ;
289
+ /**
290
+ * Creates a focus-trapped region around the given element.
291
+ * @param element The element around which focus will be trapped.
292
+ * @param deferCaptureElements Defers the creation of focus-capturing elements to be done
293
+ * manually by the user.
294
+ * @returns The created focus trap instance.
295
+ */
296
+ create ( element : HTMLElement , deferCaptureElements : boolean = false ) : FocusTrap {
297
+ return new FocusTrap (
298
+ element , this . _platform , this . _checker , this . _ngZone , deferCaptureElements ) ;
292
299
}
293
300
}
294
301
295
302
296
303
/**
297
304
* Directive for trapping focus within a region.
305
+ * @docs -private
298
306
* @deprecated
299
307
*/
300
308
@Directive ( {
@@ -330,6 +338,7 @@ export class FocusTrapDeprecatedDirective implements OnDestroy, AfterContentInit
330
338
exportAs : 'cdkTrapFocus' ,
331
339
} )
332
340
export class FocusTrapDirective implements OnDestroy , AfterContentInit {
341
+ /** Underlying FocusTrap instance. */
333
342
focusTrap : FocusTrap ;
334
343
335
344
/** Whether the focus trap is active. */
0 commit comments