Skip to content

Fix Semantics expanded state not updating in PopupMenuButton and DropdownButton#183475

Merged
auto-submit[bot] merged 2 commits into
flutter:masterfrom
AhmedLSayed9:fix-menu-expanded-semantics
Mar 18, 2026
Merged

Fix Semantics expanded state not updating in PopupMenuButton and DropdownButton#183475
auto-submit[bot] merged 2 commits into
flutter:masterfrom
AhmedLSayed9:fix-menu-expanded-semantics

Conversation

@AhmedLSayed9

Copy link
Copy Markdown
Contributor

Fixes #183432

Description

_isMenuExpanded is updated without calling setState() in both PopupMenuButton and DropdownButton, so the Semantics(expanded: _isMenuExpanded) widget doesn't rebuild.

PopupMenuButton: The expanded state never updates at all since there is no setState() call anywhere in PopupMenuButtonState.

DropdownButton: Currently masked by _handleFocusChanged, which happens to call setState() whenever focus changes on open/close, but should not rely on this side effect.

Changes

  • Wrapped _isMenuExpanded assignments with setState() in both widgets.
  • For DropdownButton, moved _isMenuExpanded = false from _removeDropdownRoute() to the .then() callback with a mounted guard. This avoids unnecessary setState() calls when _removeDropdownRoute() is invoked during dispose() or orientation changes in build(), where the menu state isn't actually changing from user interaction.

Tests

Added regression tests for both PopupMenuButton and DropdownButton to verify the expanded semantics state updates correctly when the menu opens and closes.

Pre-launch Checklist

  • I read the [Contributor Guide] and followed the process outlined there for submitting PRs.
  • I read the [AI contribution guidelines] and understand my responsibilities, or I am not using AI tools.
  • I read the [Tree Hygiene] wiki page, which explains my responsibilities.
  • I read and followed the [Flutter Style Guide], including [Features we expect every widget to implement].
  • I signed the [CLA].
  • I listed at least one issue that this PR fixes in the description above.
  • I updated/added relevant documentation (doc comments with ///).
  • I added new tests to check the change I am making, or this PR is [test-exempt].
  • I followed the [breaking change policy] and added [Data Driven Fixes] where supported.
  • All existing and new tests are passing.

@github-actions github-actions Bot added framework flutter/packages/flutter repository. See also f: labels. f: material design flutter/packages/flutter/material repository. labels Mar 10, 2026

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

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 addresses an issue where the expanded state in the Semantics widget was not updating for PopupMenuButton and DropdownButton. The changes wrap the assignments to the _isMenuExpanded state variable within setState calls in both widgets. This ensures that the UI rebuilds to reflect the menu's expanded or collapsed state for accessibility services. For DropdownButton, the logic to set _isMenuExpanded to false upon menu closure has been moved from _removeDropdownRoute into the .then() callback of navigator.push, guarded by a mounted check. This prevents unnecessary setState calls during widget disposal or orientation changes. Regression tests have been added for both PopupMenuButton and DropdownButton to confirm that the expanded semantics state updates correctly.

Note: Security Review is unavailable for this PR.

@dkwingsmt dkwingsmt requested a review from QuncCccccc March 11, 2026 18:25

@QuncCccccc QuncCccccc left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM. Thanks for your contribution:)!

@hannah-hyj hannah-hyj 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.

LGTM

@QuncCccccc QuncCccccc added the CICD Run CI/CD label Mar 18, 2026
@QuncCccccc QuncCccccc force-pushed the fix-menu-expanded-semantics branch from 7ab0319 to cc69a93 Compare March 18, 2026 21:28
@github-actions github-actions Bot removed the CICD Run CI/CD label Mar 18, 2026
@QuncCccccc QuncCccccc added CICD Run CI/CD autosubmit Merge PR when tree becomes green via auto submit App labels Mar 18, 2026
@auto-submit auto-submit Bot added this pull request to the merge queue Mar 18, 2026
Merged via the queue into flutter:master with commit ad38919 Mar 18, 2026
79 checks passed
@flutter-dashboard flutter-dashboard Bot removed the autosubmit Merge PR when tree becomes green via auto submit App label Mar 18, 2026
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Mar 19, 2026
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Mar 19, 2026
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Mar 19, 2026
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Mar 19, 2026
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Mar 19, 2026
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Mar 19, 2026
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Mar 20, 2026
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Mar 20, 2026
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Mar 21, 2026
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Mar 21, 2026
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Mar 21, 2026
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Mar 22, 2026
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Mar 22, 2026
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Mar 23, 2026
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Mar 23, 2026
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Mar 23, 2026
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Mar 23, 2026
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Mar 24, 2026
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Mar 24, 2026
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Mar 24, 2026
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Mar 24, 2026
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Mar 24, 2026
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Mar 24, 2026
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Mar 25, 2026
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Mar 25, 2026
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Mar 25, 2026
mboetger pushed a commit to mboetger/flutter that referenced this pull request Mar 26, 2026
…downButton (flutter#183475)

Fixes flutter#183432

## Description

`_isMenuExpanded` is updated without calling `setState()` in both
`PopupMenuButton` and `DropdownButton`, so the `Semantics(expanded:
_isMenuExpanded)` widget doesn't rebuild.

**`PopupMenuButton`**: The `expanded` state never updates at all since
there is no `setState()` call anywhere in `PopupMenuButtonState`.

**`DropdownButton`**: Currently masked by `_handleFocusChanged`, which
happens to call `setState()` whenever focus changes on open/close, but
should not rely on this side effect.

### Changes

- Wrapped `_isMenuExpanded` assignments with `setState()` in both
widgets.
- For `DropdownButton`, moved `_isMenuExpanded = false` from
`_removeDropdownRoute()` to the `.then()` callback with a `mounted`
guard. This avoids unnecessary `setState()` calls when
`_removeDropdownRoute()` is invoked during `dispose()` or orientation
changes in `build()`, where the menu state isn't actually changing from
user interaction.

## Tests

Added regression tests for both `PopupMenuButton` and `DropdownButton`
to verify the `expanded` semantics state updates correctly when the menu
opens and closes.

## Pre-launch Checklist

- [x] I read the [Contributor Guide] and followed the process outlined
there for submitting PRs.
- [x] I read the [AI contribution guidelines] and understand my
responsibilities, or I am not using AI tools.
- [x] I read the [Tree Hygiene] wiki page, which explains my
responsibilities.
- [x] I read and followed the [Flutter Style Guide], including [Features
we expect every widget to implement].
- [x] I signed the [CLA].
- [x] I listed at least one issue that this PR fixes in the description
above.
- [x] I updated/added relevant documentation (doc comments with `///`).
- [x] I added new tests to check the change I am making, or this PR is
[test-exempt].
- [x] I followed the [breaking change policy] and added [Data Driven
Fixes] where supported.
- [x] All existing and new tests are passing.
ahmedsameha1 pushed a commit to ahmedsameha1/flutter that referenced this pull request Apr 14, 2026
…downButton (flutter#183475)

Fixes flutter#183432

## Description

`_isMenuExpanded` is updated without calling `setState()` in both
`PopupMenuButton` and `DropdownButton`, so the `Semantics(expanded:
_isMenuExpanded)` widget doesn't rebuild.

**`PopupMenuButton`**: The `expanded` state never updates at all since
there is no `setState()` call anywhere in `PopupMenuButtonState`.

**`DropdownButton`**: Currently masked by `_handleFocusChanged`, which
happens to call `setState()` whenever focus changes on open/close, but
should not rely on this side effect.

### Changes

- Wrapped `_isMenuExpanded` assignments with `setState()` in both
widgets.
- For `DropdownButton`, moved `_isMenuExpanded = false` from
`_removeDropdownRoute()` to the `.then()` callback with a `mounted`
guard. This avoids unnecessary `setState()` calls when
`_removeDropdownRoute()` is invoked during `dispose()` or orientation
changes in `build()`, where the menu state isn't actually changing from
user interaction.

## Tests

Added regression tests for both `PopupMenuButton` and `DropdownButton`
to verify the `expanded` semantics state updates correctly when the menu
opens and closes.

## Pre-launch Checklist

- [x] I read the [Contributor Guide] and followed the process outlined
there for submitting PRs.
- [x] I read the [AI contribution guidelines] and understand my
responsibilities, or I am not using AI tools.
- [x] I read the [Tree Hygiene] wiki page, which explains my
responsibilities.
- [x] I read and followed the [Flutter Style Guide], including [Features
we expect every widget to implement].
- [x] I signed the [CLA].
- [x] I listed at least one issue that this PR fixes in the description
above.
- [x] I updated/added relevant documentation (doc comments with `///`).
- [x] I added new tests to check the change I am making, or this PR is
[test-exempt].
- [x] I followed the [breaking change policy] and added [Data Driven
Fixes] where supported.
- [x] All existing and new tests are passing.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CICD Run CI/CD 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.

PopupMenuButton Semantics expanded state does not update

3 participants