-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Focus after exiting the modal #1174
Comments
Bootstrap's approach is a little different. They use data-toggle on the trigger/button with the value matching the id of the modal (the reverse of what you describe) and have the modal listen for click events which the data-toggle of it's id. It's slightly different, but the key difference is that bootstrap allows multiple triggers/buttons to launch the modal and is able to return focus to the specific trigger/button which launched the modal when the modal is dismissed. That ability to determine which element to return focus to is key. We can tie the modal to buttons in a similar way to bootstrap by having the modal add event listeners to the document and listen for elements with the data-toggle prop with the modal's id to be triggered and then launch the modal. That way the modal knows which element triggered it and which one to place focus on after it closes. OR, more simply, the modal could grab |
Is it possible to have a prop to manage this feature? It seems like it's causing a bit of weird behavior for me: |
@chriggi, check out the last example on https://reactstrap.github.io/components/modals/ |
Issue description
Modal
#6.3.x
#16.x.x
#4.1.x
What is happening?
Several prs fixed the focus thing inside the modal and trap the focus inside as well (##1165]. However, when you exit the modal the focus is no longer is not put back on the button that opened the modal.
What should be happening?
Once the modal is closed the focus should be put on the element that triggered the open
Question/Solution
Hey guys, I know how to fix this issue, but first I would like to know if you are ok with opening a pr to fix it. My idea to solve it is the following:
<button id="openModal">Open modal</button>
<Modal {...props} modalTrigger="openModal" />
isOpen===false
I will put the focus on the element with the passed id.Let me know what you think about it? Does it make sense?
The text was updated successfully, but these errors were encountered: