@@ -24,10 +24,9 @@ import {InteractivityChecker} from './interactivity-checker';
2424/**
2525 * Class that allows for trapping focus within a DOM element.
2626 *
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.
2828 * It assumes that the tab order is the same as DOM order, which is not necessarily true.
2929 * 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.
3130 */
3231export class FocusTrap {
3332 private _startAnchor : HTMLElement | null ;
@@ -169,7 +168,7 @@ export class FocusTrap {
169168
170169 /**
171170 * 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.
173172 */
174173 focusInitialElement ( ) : boolean {
175174 if ( ! this . _platform . isBrowser ) {
@@ -188,7 +187,7 @@ export class FocusTrap {
188187
189188 /**
190189 * 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.
192191 */
193192 focusFirstTabbableElement ( ) : boolean {
194193 const redirectToElement = this . _getRegionBoundary ( 'start' ) ;
@@ -202,7 +201,7 @@ export class FocusTrap {
202201
203202 /**
204203 * 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.
206205 */
207206 focusLastTabbableElement ( ) : boolean {
208207 const redirectToElement = this . _getRegionBoundary ( 'end' ) ;
@@ -287,14 +286,23 @@ export class FocusTrapFactory {
287286 private _platform : Platform ,
288287 private _ngZone : NgZone ) { }
289288
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 ) ;
292299 }
293300}
294301
295302
296303/**
297304 * Directive for trapping focus within a region.
305+ * @docs -private
298306 * @deprecated
299307 */
300308@Directive ( {
@@ -330,6 +338,7 @@ export class FocusTrapDeprecatedDirective implements OnDestroy, AfterContentInit
330338 exportAs : 'cdkTrapFocus' ,
331339} )
332340export class FocusTrapDirective implements OnDestroy , AfterContentInit {
341+ /** Underlying FocusTrap instance. */
333342 focusTrap : FocusTrap ;
334343
335344 /** Whether the focus trap is active. */
0 commit comments