Skip to content

Commit 75e5c51

Browse files
authored
Merge pull request #353 from AhmedLSayed9/add_semantics_to_dropdown_items
Add semantics to dropdown menu items [Flutter core]
2 parents 7825db8 + 1029282 commit 75e5c51

File tree

3 files changed

+10
-4
lines changed

3 files changed

+10
-4
lines changed

packages/dropdown_button2/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
- Implement switch expressions.
88
- Fix memory leak in CurvedAnimation [Flutter core].
99
- Avoid Container objects when possible for better performance [Flutter core].
10+
- Add semantics to dropdown menu items [Flutter core].
1011

1112
## 3.0.0-beta.21
1213

packages/dropdown_button2/lib/src/dropdown_button2.dart

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -882,8 +882,10 @@ class _DropdownButton2State<T> extends State<DropdownButton2<T>>
882882
);
883883
}
884884

885+
final bool childHasButtonSemantic = hintIndex != null ||
886+
(_selectedIndex != null && widget.selectedItemBuilder == null);
885887
return Semantics(
886-
button: true,
888+
button: !childHasButtonSemantic,
887889
child: Actions(
888890
actions: _actionMap,
889891
child: InkWell(

packages/dropdown_button2/lib/src/dropdown_menu_item.dart

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -111,9 +111,12 @@ class _DropdownMenuItemContainer extends StatelessWidget {
111111

112112
@override
113113
Widget build(BuildContext context) {
114-
return SizedBox(
115-
height: intrinsicHeight ? null : height,
116-
child: Align(alignment: alignment, child: child),
114+
return Semantics(
115+
button: true,
116+
child: SizedBox(
117+
height: intrinsicHeight ? null : height,
118+
child: Align(alignment: alignment, child: child),
119+
),
117120
);
118121
}
119122
}

0 commit comments

Comments
 (0)