Skip to content

Conversation

@flutter-zl
Copy link
Contributor

This PR addresses issue #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/

@github-actions github-actions bot added the framework flutter/packages/flutter repository. See also f: labels. label Sep 30, 2025
@github-actions github-actions bot added the f: material design flutter/packages/flutter/material repository. label Sep 30, 2025
Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a 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.

@mdebbar
Copy link
Contributor

mdebbar commented Sep 30, 2025

It looks like the button flag was removed on purpose: #127620. I'll defer to @chunhtai to advise on the right path to take here.

@chunhtai chunhtai requested a review from QuncCccccc September 30, 2025 20:11
@chunhtai
Copy link
Contributor

@QuncCccccc Do you remember why we want to remove the button from the menu before?

@QuncCccccc
Copy link
Contributor

IIRC, menu items don't announce "button" on windows, so we removed it in that PR.

Copy link
Contributor

@mdebbar mdebbar left a 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,
Copy link
Contributor

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.

Copy link
Contributor Author

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.

@chunhtai
Copy link
Contributor

chunhtai commented Oct 1, 2025

I agree we may need to be platform adaptive on this, I think for now Web - isSemanticButton: true and null otherwise should be fine

label: semanticsLabel,
excludeSemantics: true,
enabled: isEnabled,
button: isSemanticButton,
Copy link
Contributor

@chunhtai chunhtai Oct 1, 2025

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

Copy link
Contributor Author

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
@flutter-zl flutter-zl requested review from chunhtai and mdebbar October 7, 2025 17:19
Copy link
Contributor

@mdebbar mdebbar left a 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,
Copy link
Contributor

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?

Copy link
Contributor Author

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,
Copy link
Contributor

Choose a reason for hiding this comment

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

Same question here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

good catch. updated.

@flutter-zl flutter-zl requested a review from mdebbar October 7, 2025 18:21
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Oct 10, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Oct 10, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Oct 11, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Oct 11, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Oct 12, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Oct 12, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Oct 12, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Oct 13, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Oct 13, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Oct 13, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Oct 14, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Oct 14, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Oct 14, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Oct 14, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Oct 14, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Oct 14, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Oct 15, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Oct 15, 2025
reidbaker pushed a commit to AbdeMohlbi/flutter that referenced this pull request Dec 10, 2025
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/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

f: material design flutter/packages/flutter/material repository. framework flutter/packages/flutter repository. See also f: labels.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants