-
Notifications
You must be signed in to change notification settings - Fork 6.8k
feat(FocusTrap): focus methods should accept focus options #21767
Copy link
Copy link
Closed
Labels
P3An issue that is relevant to core functions, but does not impede progress. Important, but not urgentAn issue that is relevant to core functions, but does not impede progress. Important, but not urgentarea: cdk/a11yfeatureLabel used to distinguish feature request from other issuesLabel used to distinguish feature request from other issues
Description
Feature Description
FocusTrap methods should accept focus parameters.
Methods to change:
focusFirstTabbableElement()focusFirstTabbableElementWhenReady()focusInitialElement()focusInitialElementWhenReady()focusLastTabbableElement()focusLastTabbableElementWhenReady()
Example:
// Would like to be able to do something like the following
constructor(
private _elementRef: ElementRef,
private _focusTrapFactory: ConfigurableFocusTrapFactory,
) {
const focusTrap = this._focusTrapFactory.create(this._elementRef.nativeElement);
const focusOptions = { preventScroll: true };
focusTrap.focusFirstTabbableElementWhenReady(focusOptions);
}Use Case
Using a FocusTrap to focus an element that starts out of view can cause parent elements to shift as the browser tries to bring the element into view. Allowing focus parameters to be configured, will enable consumers to set the preventScroll option and prevent this behavior (in supporting browsers).
Stackblitz demoing a scenario where the ability to specify focus parameters would be helpful.
Maybe be related to #17863
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
P3An issue that is relevant to core functions, but does not impede progress. Important, but not urgentAn issue that is relevant to core functions, but does not impede progress. Important, but not urgentarea: cdk/a11yfeatureLabel used to distinguish feature request from other issuesLabel used to distinguish feature request from other issues