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

First input in popup autofocuses #250

Open
qubal opened this issue Apr 2, 2021 · 9 comments
Open

First input in popup autofocuses #250

qubal opened this issue Apr 2, 2021 · 9 comments

Comments

@qubal
Copy link

qubal commented Apr 2, 2021

Greetings, traveller. Currently I'm facing a bug, which can shortly be described like: "First input in any popup autofocuses and neither "tabIndex: -1", nor "autofocus={'false'}" can help fixing it.

Version

2.0.4

Test Case

https://codesandbox.io/s/restless-shape-n5o0k?file=/src/index.tsx

Expected Behavior

I expect first input not to focus, i've already tried changing tabIndex and set autofocus false.

Actual Behavior

It, unexpectedly (wow!) autofocuses.

What can I do to fix it?

@RaphaelChauveau
Copy link

Hello, It seems to be the intended behaviour, for accessibility purpose.

Extract from https://react-popup.elazizi.com/react-popup-accessibility

✓ On Popup Open, we set focus to the first focusable element.
✓ On Popup Close, we return focus to the last focused element.

However, this feature is also causing some problems for me because despite restoring the first focused element on close, it loses the original selection...

@ronangaillard
Copy link

Yes, please add an optional prop to disable this 😞

@qubal
Copy link
Author

qubal commented Apr 15, 2021

@ronangaillard @RaphaelChauveau admit

@abdulsami822
Copy link

abdulsami822 commented May 10, 2021

Use a dummy input field like radio button without content as first input in form and make it "display:none" in css. Then the focus goes to that element instead of the first visible input.

@ronangaillard
Copy link

The problem is that the current focused element before opening gets unfocused on popup open.

In our projects this is a big issue as we have to refocus the previous focused element after opening popup.

@charlesrollin
Copy link

I have the same issue as @ronangaillard. I use a popup as the container for suggestions list on a search input. On first click on the search input, the following occurs :

  • text input is focused
  • then popup opens (with no suggestions and an initial loader)
  • then text input looses focus (because focus goes to the first item in the popup)

In terms of UX it means that the user has to click twice to effectively focus the text input at first !
I managed to find a messy fix using a controlled popup and a useEffect but adding a prop that allows to disable autofocus would be great !

@taj567
Copy link

taj567 commented Apr 11, 2023

Guy's me to has same bug,can anyone has solution to stop auto focus.

Screenshot 2023-04-11 at 4 21 03 PM

@ronangaillard
Copy link

Any update on this issue ?
Do you have tips of where to look to make a PR ?

@nikitadubyk
Copy link

I fixed this problem and open PR, hope it will be merged soon
#346

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

No branches or pull requests

7 participants