Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Overlay cannot focus autofocus elements due to React behavior #4908

Open
michael-yx-wu opened this issue Sep 15, 2021 · 0 comments
Open

Overlay cannot focus autofocus elements due to React behavior #4908

michael-yx-wu opened this issue Sep 15, 2021 · 0 comments

Comments

@michael-yx-wu
Copy link
Contributor

michael-yx-wu commented Sep 15, 2021

Environment

  • Package version(s): @blueprintjs/[email protected]
  • Operating System: any
  • Browser name and version: any

Filling as a follow up to #4894 (comment)

When setting the autoFocus prop on a component, React chooses not to render it to the DOM (see facebook/react#11851 (comment)), so this selector will never find anything:

const autofocusElement = this.containerElement.querySelector("[autofocus]") as HTMLElement;

On initial open of the overlay, the autofocus element should get focus thanks to React calling Element#focus under the hood, but subsequent runs of this function will not focus the autofocus element. When returning focus back to the Overlay, do we always want to focus the first autofocus element? If so, we may need to consider using cloning children and replacing autoFocus with autofocus (no caps), but this will probably result console warnings. If not, we can just delete this line and rely on React.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants