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

Commit 1fc8ced

Browse files
TedSandernshahan
authored andcommitted
Fix bug where aria-activeDescendant can get out of sync on a mouse out of dropdown.
Also fix a null value producing an ID in active_item. PiperOrigin-RevId: 219596918
1 parent af4c478 commit 1fc8ced

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

angular_components/lib/material_select/material_dropdown_select.dart

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,15 @@ class MaterialDropdownSelectComponent extends MaterialSelectBase
251251
set visible(bool value) {
252252
super.visible = value;
253253
resetEnteredKeys();
254+
if (value) {
255+
// Ensure that the current active item matches the current value.
256+
// For instance it is cleared on mouse out.
257+
// Note we don't allow deactivation because some teams incorrectly use
258+
// activeItemLabel instead of selectedItemLabel, and this breaks them.
259+
// TODO(google): remove allowDeactivate when client tests are fixed.
260+
// https://test.corp.google.com/ui#id=OCL:219567674:BASE:219582901:1541045481973:dd9a971c
261+
_setInitialActiveItem(allowDeactivate: false);
262+
}
254263
}
255264

256265
/// Sets the available options for the selection component.
@@ -323,9 +332,9 @@ class MaterialDropdownSelectComponent extends MaterialSelectBase
323332
activeModel.items = items;
324333
}
325334

326-
void _setInitialActiveItem() {
335+
void _setInitialActiveItem({bool allowDeactivate = true}) {
327336
if (selection == null || selection.selectedValues.isEmpty) {
328-
activeModel.activate(null);
337+
if (allowDeactivate) activeModel.activate(null);
329338
} else if (activeModel.activeItem == null ||
330339
(showDeselectItem && activeModel.activeItem == deselectLabel) ||
331340
!selection.isSelected(activeModel.activeItem)) {

angular_components/lib/model/a11y/active_item.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,7 @@ class ActiveItemModel<T> {
133133

134134
/// Returns an unique id for [item].
135135
String id(T item) {
136+
if (item == null) return null;
136137
if (!_ids.containsKey(item)) {
137138
_ids[item] = _idGenerator.nextId();
138139
}

0 commit comments

Comments
 (0)