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

Commit 98f2b35

Browse files
cissyshinshahan
authored andcommitted
Add activateFirstOption input to material dropdown select.
PiperOrigin-RevId: 220513954
1 parent 89d8c1c commit 98f2b35

File tree

2 files changed

+9
-0
lines changed

2 files changed

+9
-0
lines changed

angular_components/lib/material_select/material_dropdown_select.dart

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,11 @@ class MaterialDropdownSelectComponent<T> extends MaterialSelectBase<T>
157157
// Whether a custom label render is used.
158158
bool get hasCustomLabelRenderer => labelFactory != null;
159159

160+
/// Whether to activate (visually focus but not select) the first available
161+
/// option when the dropdown opens.
162+
@Input()
163+
bool activateFirstOption = false;
164+
160165
/// CSS classes from the root element, passed to the popup to allow scoping of
161166
/// mixins.
162167
///
@@ -348,6 +353,9 @@ class MaterialDropdownSelectComponent<T> extends MaterialSelectBase<T>
348353
// item.
349354
activeModel.activate(selection.selectedValues.first);
350355
}
356+
if (activateFirstOption && activeModel.activeItem == null) {
357+
activeModel.activateFirst();
358+
}
351359
}
352360

353361
void _handleNavigationKey(KeyboardEvent event, Function activateFunction) {

examples/material_select_example/lib/material_dropdown_select_full_demo.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,7 @@ <h3>Multiple Selection w/ searchbox</h3>
141141
[selection]="multiSelectModel"
142142
[itemRenderer]="itemRenderer"
143143
[listAutoFocus]="false"
144+
[activateFirstOption]="true"
144145
(visibleChange)="onDropdownVisibleChange($event)">
145146
<div header>
146147
<material-select-searchbox

0 commit comments

Comments
 (0)