Closed
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