Skip to content

Update aria-pressed state for ToolbarButton when pressed#17222

Merged
krassowski merged 5 commits into
jupyterlab:mainfrom
MUFFANUJ:fix-toolbar-area-pressed
Jan 7, 2026
Merged

Update aria-pressed state for ToolbarButton when pressed#17222
krassowski merged 5 commits into
jupyterlab:mainfrom
MUFFANUJ:fix-toolbar-area-pressed

Conversation

@MUFFANUJ

@MUFFANUJ MUFFANUJ commented Jan 26, 2025

Copy link
Copy Markdown
Member

References

This PR fixes #14464 where the "More commands" button in the toolbar overflow menu did not reflect its pressed state. The aria-pressed attribute is now correctly toggled when the button is clicked.

Code changes

  • Updated onClick logic to toggle the pressed state.
  • Ensured aria-pressed updates dynamically based on the button’s pressed state.

After necessary changes

Screen.Recording.2025-01-26.at.10.29.44.PM.mov

@jupyterlab-probot

Copy link
Copy Markdown

Thanks for making a pull request to jupyterlab!
To try out this branch on binder, follow this link: Binder

@MUFFANUJ

Copy link
Copy Markdown
Member Author

@meeseeksdev tag bug

@lumberbot-app lumberbot-app Bot added the bug label Jan 26, 2025
@krassowski krassowski added this to the 4.3.x milestone Jan 27, 2025
@krassowski

Copy link
Copy Markdown
Member

Does it also work when using Space to toggle it?

@MUFFANUJ

MUFFANUJ commented Jan 27, 2025

Copy link
Copy Markdown
Member Author

Does it also work when using Space to toggle it?

I have updated the function passed through props to handle both onClick and onKeyDown events, which will simply ensure it works everywhere it is used. While testing for Space and Enter functionality, I noticed a missing piece of code causing the action to behave inconsistently. Should I address this within the current issue or open a new one to formalize the fix?

Here Is the demo for the issue when I tried to toggle using space

Screen.Recording.2025-01-27.at.5.46.54.PM.mov

Issue lies here:

const handleKeyDown = (event: React.KeyboardEvent) => {
const { key } = event;
if (key === 'Enter' || key === ' ') {
props.onClick?.();
}
};

Proposed Solution

const handleKeyDown = props.noFocusOnClick ?? false ? (event: React.KeyboardEvent) => {
  const { key } = event;
  if (key === 'Enter' || key === ' ') {
    props.onClick?.();
  }
} : undefined;

This implementation works fine because it conditionally assigns handleKeyDown only if props.noFocusOnClick is true, ensuring the function exists only when needed.

In contrast, the code implementation used so far always defines handleKeyDown, even when it shouldn't be triggered (e.g. when props.noFocusOnClick is false). This could lead to unintended behavior, such as executing props.onClick unnecessarily.

@krassowski

Copy link
Copy Markdown
Member

I can reproduce the issue that you are referring to. I am not sure what solution would be the best so maybe let's open a new issue to discuss it first :)

@MUFFANUJ

Copy link
Copy Markdown
Member Author

I have opened a new issue for the same #17229

@MUFFANUJ

MUFFANUJ commented Jan 27, 2025

Copy link
Copy Markdown
Member Author

Hey @krassowski, After spending additional time investigating this issue, I have identified a relevant solution that addresses the underlying cause of the problem. I have also opened a pull request with the proposed fix (#17230). If the pull request is merged, we can close this one as well.

@MUFFANUJ

MUFFANUJ commented Dec 4, 2025

Copy link
Copy Markdown
Member Author

hey @krassowski @Darshan808 , since this is closed #17230 we can merge this one as well ?

@krassowski

Copy link
Copy Markdown
Member

Testing this on Binder I saw flickering between states when using keyboard, merging main branch in to make sure if this was because the other PR was not merged into this branch yet.

Comment thread packages/ui-components/src/components/toolbar.tsx Outdated
@krassowski

Copy link
Copy Markdown
Member

No, I still see that pressing space does not toggle it correctly when using this PR.

@MUFFANUJ

MUFFANUJ commented Dec 8, 2025

Copy link
Copy Markdown
Member Author

Yes i too tested on binder and see the flickering effect. Will see what needs to be fix and make the changes

@MUFFANUJ

MUFFANUJ commented Dec 27, 2025

Copy link
Copy Markdown
Member Author

hey @krassowski, checked on binder it seems to be working now :)

@MUFFANUJ MUFFANUJ requested a review from krassowski December 28, 2025 18:04
@krassowski krassowski modified the milestones: 4.3.x, 4.6.0 Jan 1, 2026

@krassowski krassowski left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you!

@krassowski krassowski changed the title Fix: Update aria-pressed state for ToolbarButton Fix: Update aria-pressed state for ToolbarButton Jan 7, 2026
@krassowski krassowski changed the title Fix: Update aria-pressed state for ToolbarButton Update aria-pressed state for ToolbarButton when pressed Jan 7, 2026
@krassowski krassowski merged commit 2a28541 into jupyterlab:main Jan 7, 2026
90 of 91 checks passed
@MUFFANUJ MUFFANUJ deleted the fix-toolbar-area-pressed branch January 7, 2026 14:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

More commands three dots button on toolbar does not reflect status

2 participants