This repository was archived by the owner on May 20, 2023. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +12
-2
lines changed Expand file tree Collapse file tree 2 files changed +12
-2
lines changed Original file line number Diff line number Diff 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)) {
Original file line number Diff line number Diff 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 }
You can’t perform that action at this time.
0 commit comments