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

Issue with focus on a toolbar clicked button #6842

Closed
fcollonval opened this issue Sep 25, 2023 · 1 comment · Fixed by #6888
Closed

Issue with focus on a toolbar clicked button #6842

fcollonval opened this issue Sep 25, 2023 · 1 comment · Fixed by #6888

Comments

@fcollonval
Copy link
Contributor

In the toolbar, when a item is clicked, the event (if propagated) will be used to change the active index (expected behavior). Then if the active index changes, the clicked item is focused through:

this.focusableElements[this.activeIndex]?.focus();

That latter behavior can have inconsistent and unexpected result in the following case:

  • When a button in the toolbar has a mousedown listener changing the focus to a text area (outside the toolbar).

  • If clicking on the button

  • The focus is at the end on to the button (unexpected)

  • On a second click on the button, the focus is in the text area (expected) because the active index did not change on the toolbar (the snippet above has not been called).

If clicking on another item in the toolbar then back to the button, the case of first click occurs as the active index changes.

So I was wondering if it makes sense to not focus the active element either at all or at lease if the preventDefault was called on the click event.

Of note, most browsers are focusing a button on click. But this can be escaped by calling preventDefault on mousedown event.

Screencast of the issue

toolbar_item_focus

@fcollonval
Copy link
Contributor Author

fcollonval commented Jan 9, 2024

We are hitting that in jupyterlab/jupyterlab#15021

Work around for now (but it prevents updating the active index and the focusableElements):

https://github.com/jupyterlab/jupyterlab/pull/15021/files#diff-00e4c3dd1d53c87918423484191102bdfda9a86263e410a858ec62b1669bfbe1

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

Successfully merging a pull request may close this issue.

1 participant