Re-focus dropdown button before closing menu with keyboard #40
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "singingwolfboy/prosemirror-menu:dropdown-focus-before-close"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
We are using this code in our project -- thanks so much for sharing it! I've found an interesting accessibility bug where closing a dropdown menu using the keyboard causes the focus to move to the root of the document, rather than returning to the dropdown button. It appears to be because we are using CSS to hide the menu when the editor is not focused, using CSS rules like these:
When the existing code closes the dropdown menu, the focused element is removed from the DOM, which causes the focus to move to the root of the document. This causes the
display: noneto apply, because the focus is no longer within the menubar. Then, the JS tries to move the focus to the button in the menubar, but it can't, because the browser won't move focus to an element that hasdisplay: none.Switching the order of these statements appears to make it work as expected. In most cases, it shouldn't matter in what order these statements execute; do you mind making the
btn.focus()line run first, so that it properly handles this edge case?Thanks! This looks like a good idea.
I've tagged this in prosemirror-menu 1.3.1
Thank you!