-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
bug(modal): the first press of shift + tab does not focus an element in the modal, focus is not trapped #2718
Comments
Trying to think about it, it does not sound like a bug to me ... Here are my thoughts about it: The library provides a way to open anything in a modal window, then it's up to people to implement what to be focused first when modal is open. The fact that it is working with Tab is for me a nice side-effect but it is not meant to be a feature. |
@benouat I don't understand. How come Tab is "a side-effect, not a feature", if focus trapping is intentional? ( by the way, when you call |
EDIT: the github @ suggestion fooled me
The fact that if you do open a modal without specifying an element to be focused is working when first pressing Tab is the side effect to me Ideally, the html5 💡Maybe we should implement a kind of |
I think you're wrong.
as a user of ng-bootstrap, I would not prefer to do that. I have over 30 modals in my project and it would be such a pain to manage the focus for each modal.
I don't think that this is a good idea. According to https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input#attr-autofocus
|
@Maxkorz visually-impaired or not, we do want our user to be "teleported" into the content of the modal. I still think the directive is a good idea, BTW material implemented it for their accessible focus management |
@benouat I just checked, ngbFocusTrap works fine in the datepicker: https://stackblitz.com/angular/nvpvpagxmoxo
(I updated my first message) |
yes it is working in the datepicker because of what I described:
In this case, it is not the user, but the datepicker itself that will focus the selected date when opened. Something is then initially focused, Again, issue for modal is that if you don't focus something when it is opened, |
@benouat I still think that the issue is in the Small fix in
What do you think? |
I am fine with this change, but if we decide to handle the case of I know that handling the other one with just Tab is already working (because this is the default browser behaviour), but for consistency, if we implement one, we have to implement the other one that will just override the default behaviour Something a bit like that : if ((focusedElement === first || focusedElement === element) && tabEvent.shiftKey) {
last.focus();
tabEvent.preventDefault();
}
if ((focusedElement === last || focusedElement === element) && !tabEvent.shiftKey) {
first.focus();
tabEvent.preventDefault();
} Nonetheless, documentation should clearly state that when using modal, user should take care (in a kind of mandatory way) of focusing something inside the modal. |
I agree 👍
I strongly disagree 👎 😃 |
We could strongly suggest this but IMO modal should have sensible defaults (ex. first focusable element or modal window itself (as today). |
@benouat can you open a PR with your solution? |
@Maxkorz yes sure, i will ! |
Hi Folks, Once inside the Modal, focus must be trapped; SHIFT-TAB immediately after entry would give focus to the last focusable item at the bottom/end of the Modal (wrap-around). Once the Modal is spawned, focus must go to the first actionable item - presumably the close (X) button. FYI, arbitrarily focusing some element in the middle of content could be troublesome to exit if the Modal was entered by error. A suggestion he made is to set the I hope this is helpful. |
Something like < div>< h1 id="M1">Modal title< /h1> Or if ARIA-describedby can't be used < div>< h1>Modal title |
Thanks for you input @mendeza ! Much appreciated here Now after a few days step back, let me try to explain why I am reluctant to perform the change I described and we discussed previously in this issue using your comments:
We are fine here,
This is what we thought would be enough by focusing the modal window (@pkozlowski-opensource we don't do first focusable). It is apparently not enough and should be changed (disclaimer, it is not a framework only task, ng-bootstrap user must also be involved)
|
@benouat Lets say you add the You saw the bug in the demo. You can focus an element "behind" the modal window. You can't blame a user for that. |
IMO we should do the following:
"we should focus first focusable element" will be painful to do, though, as it will require lots of low-level DOM querying. |
As everybody is commenting this, I'll leave my 2 cents too :)
Something like: modalService.open(content, {focusFirst: true}) This issue is not a bug to me, because ONCE anything is focused in the popup, focus is trapped. There is nothing focused initially. I prefer this to be closed as UPDATE: actually on reflection inversed version with |
Opened #2728 |
Hi folks, ref: React strap working impl: |
@peterblazejewicz here are a few highlight
This is a wrong assumption. Our focus-trap implementation works great with both Tab and Shift+Tab once and only once the focus is locted anywhere inside (not inclusive) the element that host the focus trap. @Maxkorz @peterblazejewicz You both seem to be against the usage of this [ngbAutofocus] feature we are about to introduce in #2728, so Let me try one more time to explain and justify our choices regarding this entire storyTo us, opening a dialog/modal (call it the name you want) is no different that open a new page/document inside a browser tab. When you initially navigate to a new page, browsers vendor won't take any assumption on what to be focused specifically, hence focus end up on document body. This is why HTML specs provide an We decided to follow the exact same path here in ng-bootstrap. Opening a modal won't focus anything special by default, hence our initial implementation giving focus to the modal window. Then we introduce Then, lat point, regarding focus trap, open a page in a browser, and using Shift+Tab won't cycle trough the document. User will end up inside the browser chrome. Here also we follow the same path. I know it might not suit everyone, but at least we are consistent. |
https://stackblitz.com/angular/ygpjvdbxbre
P.S. it works fine in Datepicker in a popup.
The text was updated successfully, but these errors were encountered: