Skip to content
This repository was archived by the owner on May 20, 2023. It is now read-only.

Commit 8f758ec

Browse files
Googlernshahan
authored andcommitted
[a11y] UP arrow should place focus on the LAST menu item (not first).
PiperOrigin-RevId: 225422235
1 parent cabbe15 commit 8f758ec

File tree

1 file changed

+18
-4
lines changed

1 file changed

+18
-4
lines changed

angular_components/lib/material_menu/material_fab_menu.dart

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -130,20 +130,25 @@ class MaterialFabMenuComponent extends Object
130130

131131
bool get hasIcons => _viewModel.hasIcons;
132132

133-
/// Keypress callback is used to handle Up and Down keys.
133+
/// Keypress callback is used to handle UP and DOWN keys.
134134
///
135135
/// Unprintable keys use this listener while printable keys
136136
/// use [handleKeyPress].
137137
/// Enabling [MaterialFabMenu] to be opened with the keyboard improves
138138
/// accessibility and improves with a11y navigation.
139139
@HostListener('keydown')
140140
void handleKeyDown(KeyboardEvent event) {
141-
if (event.keyCode == KeyCode.DOWN || event.keyCode == KeyCode.UP) {
142-
openMenuAndActivateFirstItem();
141+
switch (event.keyCode) {
142+
case KeyCode.UP:
143+
openMenuAndActivateLastItem();
144+
break;
145+
case KeyCode.DOWN:
146+
openMenuAndActivateFirstItem();
147+
break;
143148
}
144149
}
145150

146-
/// Keypress callback is used to handle Enter and Space keys.
151+
/// Keypress callback is used to handle ENTER and SPACE keys.
147152
@HostListener('keypress')
148153
void handleKeyPress(KeyboardEvent event) {
149154
if (event.keyCode == KeyCode.ENTER || isSpaceKey(event)) {
@@ -169,6 +174,15 @@ class MaterialFabMenuComponent extends Object
169174
_viewModel.trigger();
170175
}
171176

177+
/// Sets the [activeModel.menu] and activates the last item in the menu.
178+
void openMenuAndActivateLastItem() {
179+
if (hasMenu) {
180+
activeModel.menu = menuItem.subMenu;
181+
activeModel.activateLast();
182+
}
183+
_viewModel.trigger();
184+
}
185+
172186
void onPopupOpened() {
173187
if (_menuVisible) return;
174188
_menuVisible = true;

0 commit comments

Comments
 (0)