-
Notifications
You must be signed in to change notification settings - Fork 29.7k
Improve menu item accessibility semantics #176255
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
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code Review
This pull request improves the accessibility of MenuItemButton and SubmenuButton by ensuring they are correctly identified as buttons with their enabled/disabled state announced by screen readers. This is achieved by wrapping the internal _MenuItemLabel with a Semantics widget, setting the button property to true, and passing the enabled state. The logic correctly handles merging semantics from child widgets when no explicit semantics label is provided. The associated tests have been updated to reflect these changes and new tests for the disabled states have been added, ensuring the new behavior is well-covered. The changes are well-implemented and effectively address the accessibility issue.
|
@QuncCccccc Do you remember why we want to remove the button from the menu before? |
|
IIRC, menu items don't announce "button" on windows, so we removed it in that PR. |
mdebbar
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@chunhtai @QuncCccccc do you think isSemanticButton should be configurable by the user, or just default to the right value for each platform (or both)?
Default value per platform would be:
- Windows -
isSemanticButton: null - Web -
isSemanticButton: true - Others - ??
| label: semanticsLabel, | ||
| excludeSemantics: true, | ||
| enabled: isEnabled, | ||
| button: isSemanticButton, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure that this is the right place to set the semantics button property. I think we should be replacing the isSemanticButton: null passed to TextButton above (line 1886).
Same for enabled.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great suggestion. I updated the PR.
|
I agree we may need to be platform adaptive on this, I think for now Web - |
| label: semanticsLabel, | ||
| excludeSemantics: true, | ||
| enabled: isEnabled, | ||
| button: isSemanticButton, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we should programatically assign the button: true based on kIsWeb, this is not something developer can easily pick and know about the consequence, and it seems like there may not be a good reason to provide the flexibility
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great suggestion. I updated the PR.
- Rename semantics tests to clarify they test platform-adaptive behavior - Remove redundant default semantics tests that would fail on web - Remove out-of-scope disabled semantics tests to keep PR focused - Platform-adaptive tests with `if (kIsWeb)` cover all platforms
615ba1d to
36fe1f8
Compare
mdebbar
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We changed the value on other platform from null to false. If those are equivalent, then the PR looks good to me!
| statesController: widget.statesController, | ||
| clipBehavior: widget.clipBehavior, | ||
| isSemanticButton: null, | ||
| isSemanticButton: kIsWeb, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is null equivalent to false?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
good catch. updated.
| onFocusChange: _enabled ? widget.onFocusChange : null, | ||
| onPressed: _enabled ? toggleShowMenu : null, | ||
| isSemanticButton: null, | ||
| isSemanticButton: kIsWeb, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same question here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
good catch. updated.
This PR addresses issue flutter#171231 by enhancing the accessibility semantics for `MenuItemButton` and `SubmenuButton`. Previously, screen readers did not correctly announce the disabled state of these menu items. This ensures that menu items are correctly identified as buttons and their enabled/disabled state is communicated to assistive technologies. **Before change** https://button-0923-before.web.app/ **After change** https://button-0923-after.web.app/
This PR addresses issue #171231 by enhancing the accessibility semantics for
MenuItemButtonandSubmenuButton. Previously, screen readers did not correctly announce the disabled state of these menu items.This ensures that menu items are correctly identified as buttons and their enabled/disabled state is communicated to assistive technologies.
Before change
https://button-0923-before.web.app/
After change
https://button-0923-after.web.app/