Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/dropdown_button2/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
- Upgrade minimum required Flutter SDK version to 3.32.0.
- Add `errorBuilder` support for DropdownButtonFormField2 [Flutter core].
- Add `forceErrorText` support for DropdownButtonFormField2 [Flutter core].
- Add ARIA menu roles to menu-related widgets for accessibility [Flutter core].

## 3.0.0

Expand Down
28 changes: 18 additions & 10 deletions packages/dropdown_button2/lib/src/dropdown_button2.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
*/

import 'dart:math' as math;
import 'dart:ui';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
Expand Down Expand Up @@ -419,7 +420,7 @@ class _DropdownButton2State<T> extends State<DropdownButton2<T>> with WidgetsBin
bool _isFocused = false;

// Using ValueNotifier for tracking when menu is open/close to update the button icon.
final ValueNotifier<bool> _isMenuOpen = ValueNotifier<bool>(false);
final ValueNotifier<bool> _isMenuExpanded = ValueNotifier<bool>(false);

final _buttonRectKey = GlobalKey();

Expand Down Expand Up @@ -463,7 +464,7 @@ class _DropdownButton2State<T> extends State<DropdownButton2<T>> with WidgetsBin
_removeDropdownRoute();
_focusNode.removeListener(_handleFocusChanged);
_internalNode?.dispose();
_isMenuOpen.dispose();
_isMenuExpanded.dispose();
_buttonRect.dispose();
super.dispose();
}
Expand Down Expand Up @@ -545,7 +546,7 @@ class _DropdownButton2State<T> extends State<DropdownButton2<T>> with WidgetsBin
}

void _programmaticallyOpenDropdown() {
if (_enabled && !_isMenuOpen.value) {
if (_enabled && !_isMenuExpanded.value) {
_handleTap();
}
}
Expand Down Expand Up @@ -707,7 +708,6 @@ class _DropdownButton2State<T> extends State<DropdownButton2<T>> with WidgetsBin
dropdownSeparator: separator,
);

_isMenuOpen.value = true;
_focusNode.requestFocus();
// This is a temporary fix for the "dropdown menu steal the focus from the
// underlying button" issue, until share focus is fixed in flutter (#106923).
Expand All @@ -717,11 +717,12 @@ class _DropdownButton2State<T> extends State<DropdownButton2<T>> with WidgetsBin
navigator.push(_dropdownRoute!).then<void>((_DropdownRouteResult<T>? newValue) {
_removeDropdownRoute();
if (mounted) {
_isMenuOpen.value = false;
_isMenuExpanded.value = false;
}
widget.onMenuStateChange?.call(false);
});

_isMenuExpanded.value = true;
widget.onMenuStateChange?.call(true);
}

Expand Down Expand Up @@ -898,10 +899,10 @@ class _DropdownButton2State<T> extends State<DropdownButton2<T>> with WidgetsBin
size: _iconStyle.iconSize,
),
child: ValueListenableBuilder<bool>(
valueListenable: _isMenuOpen,
builder: (BuildContext context, bool isOpen, _) {
valueListenable: _isMenuExpanded,
builder: (BuildContext context, bool isExpanded, _) {
return _iconStyle.openMenuIcon != null
? isOpen
? isExpanded
? _iconStyle.openMenuIcon!
: _iconStyle.icon
: _iconStyle.icon;
Expand Down Expand Up @@ -1018,8 +1019,15 @@ class _DropdownButton2State<T> extends State<DropdownButton2<T>> with WidgetsBin

final bool childHasButtonSemantic =
hintIndex != null || (_selectedIndex != null && widget.selectedItemBuilder == null);
return Semantics(
button: !childHasButtonSemantic,
return ValueListenableBuilder<bool>(
valueListenable: _isMenuExpanded,
builder: (BuildContext context, bool isExpanded, Widget? child) {
return Semantics(
button: !childHasButtonSemantic,
expanded: isExpanded,
child: child,
);
},
child: Actions(
actions: _actionMap,
child: result,
Expand Down
1 change: 1 addition & 0 deletions packages/dropdown_button2/lib/src/dropdown_menu.dart
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,7 @@ class _DropdownMenuState<T> extends State<_DropdownMenu<T>> {
textDirection: widget.textDirection,
),
child: Semantics(
role: SemanticsRole.menu,
scopesRoute: true,
namesRoute: true,
explicitChildNodes: true,
Expand Down
2 changes: 1 addition & 1 deletion packages/dropdown_button2/lib/src/dropdown_menu_item.dart
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,6 @@ class _DropdownItemButtonState<T> extends State<_DropdownItemButton<T>> {
child: child,
);
}
return child;
return Semantics(role: SemanticsRole.menuItem, child: child);
}
}
Loading
Loading