Skip to content

[useToolbar] Two toolbar items receive focus event, instead of one. #5457

Open
@zaboco

Description

@zaboco

Provide a general summary of the issue here

In the toolbar, when controlling the focus programmatically, via JS event handlers, two items receive the focus event when navigating to the toolbar with Tab. See "Steps to reproduce" below for an example.

🤔 Expected Behavior?

See "Steps to reproduce" below

😯 Current Behavior

See "Steps to reproduce" below

💁 Possible Solution

From what I investigated in the code, that's because there are two focus events - One is sent programmatically in useToolbar from onFocus and the other bubbles to the last button. The solution would be to stop the event propagation from the toolbar's onFocus

🔦 Context

No response

🖥️ Steps to Reproduce

This sandbox illustrates the issue.

Steps to reproduce:

  • navigate to the toolbar using Tab
  • select the middle item ("Cut"). Notice that the button turns green (that's programmatically applied via JS)
  • navigate away from the toolbar using Tab
  • navigate back with Shift + Tab

Expected:

  • The previous item is selected (i.e. green), and only that one.

Actual

  • Both the previous item and the last item (i.e. "Paste") are selected (i.e. green)

Version

"@react-aria/toolbar": "3.0.0-beta.0"

What browsers are you seeing the problem on?

Chrome

If other, please specify.

No response

What operating system are you using?

MacOS

🧢 Your Company/Team

No response

🕷 Tracking Issue

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions