-
Notifications
You must be signed in to change notification settings - Fork 6.8k
Description
Bug, feature request, or proposal:
Proposal
What is the current behavior?
Currently there is only the following options in the focus-trap to give focus:
focusInitialElementWhenReady()
focusFirstTabbableElementWhenReady()
focusLastTabbableElementWhenReady()
focusInitialElement()
focusFirstTabbableElement()
focusLastTabbableElement()
What I would like to do is add something like this to the focus-trap.ts
NOTE: naming is obviously subject to change and would make it whatever you guys would like
/** Focuses the specified element passed in. */
focusSpecifiedElement(focusElement: string) {
let redirectToElement = this._element.querySelector(
focusElement
) as HTMLElement;
if (redirectToElement) {
redirectToElement.focus();
}
}
So what this would allow for is in dialog-config for example to have a variable where the user can specify a element to give focus to:
/** Specify the element that should receive focus on load */
focusElement?: string;
Thoughts?
I have already implemented a version in a fork of mine and it seems to work really well. I would like to make it officially available in material2. Mainly wanted to get your guys opinion before I go through all the work to put up a PR and such on if you would even accept something like this.
Let me know!
Will put up a PR very soon if you guys would welcome a update like this.
What is the use-case or motivation for changing an existing behavior?
Would like to be able to give focus to a element I specify.