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

Commit 98f929a

Browse files
cissyshinshahan
cissyshi
authored andcommitted
Add shouldClearSelectionOnInput input on material auto suggest input.
This used be a hidden configuration based on whether a selection model is set. For places where a selection model was explicitly passed, this makes no difference. For places where a selection model wasn't explicitly passed, this will cause the selection item to be deselected in the popup UI when input is changed after selection. But no output will be changed. PiperOrigin-RevId: 214308663
1 parent 58ccdee commit 98f929a

File tree

3 files changed

+35
-6
lines changed

3 files changed

+35
-6
lines changed

angular_components/lib/material_input/material_auto_suggest_input.dart

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -124,8 +124,6 @@ class MaterialAutoSuggestInputComponent extends MaterialSelectBase
124124
RelativePosition.AdjacentTopRight
125125
];
126126

127-
final SelectionModel _defaultSelection = SelectionModel.single();
128-
129127
final String popupId;
130128
final String inputId;
131129

@@ -135,24 +133,42 @@ class MaterialAutoSuggestInputComponent extends MaterialSelectBase
135133

136134
bool _isInitialized = false;
137135

138-
/// Whether to clear the text once the item is selected from the menu.
136+
/// Whether to clear the input text once the item is selected from the menu.
137+
///
138+
/// Defaults to false.
139+
// TODO(google): rename this to shouldClearInputOnSelection.
139140
@Input()
140141
bool shouldClearOnSelection = false;
141142

143+
/// Whether to clear the selected value from the selection model when the
144+
/// input text changes.
145+
///
146+
/// Defaults to true.
147+
@Input()
148+
bool shouldClearSelectionOnInput = true;
149+
142150
/// Whether to cause dropdown to be closed on activation.
151+
///
152+
/// Defaults to true.
143153
@Input()
144154
bool closeOnActivate = true;
145155

146156
/// Whether to hide the checkbox before the selection item for multi-select.
157+
///
158+
/// Defaults to false.
147159
@Input()
148160
bool hideCheckbox = false;
149161

150162
/// Whether the popup should automatically reposition itself based on space
151163
/// available relative to the viewport.
164+
///
165+
/// Defaults to true.
152166
@Input()
153167
bool enforceSpaceConstraints = true;
154168

155169
/// Whether to clamp the popup position so that it never goes offscreen.
170+
///
171+
/// Defaults to false.
156172
@Input()
157173
bool constrainToViewport = false;
158174

@@ -187,6 +203,8 @@ class MaterialAutoSuggestInputComponent extends MaterialSelectBase
187203
/// [selection] are changed:
188204
/// 1) first selected value in [selection] is active in [options]
189205
/// 2) if [selection] has no selected values, nothing is active in [options]
206+
///
207+
/// Defaults to false.
190208
@Input()
191209
bool initialActivateSelection = false;
192210

@@ -195,10 +213,13 @@ class MaterialAutoSuggestInputComponent extends MaterialSelectBase
195213
/// Allow filtering of suggestions as the user is typing.
196214
///
197215
/// When `false` always show the full list of suggestions.
216+
/// Defaults to true.
198217
@Input()
199218
bool filterSuggestions = true;
200219

201220
/// Whether to close on enter even for string non matching options.
221+
///
222+
/// Defaults to false.
202223
@Input()
203224
bool closeOnEnter = false;
204225

@@ -208,6 +229,8 @@ class MaterialAutoSuggestInputComponent extends MaterialSelectBase
208229

209230
/// Whether or not the suggestion popup width is at least as wide as the input
210231
/// width.
232+
///
233+
/// Defaults to false.
211234
@Input()
212235
bool popupMatchInputWidth = false;
213236

@@ -231,6 +254,7 @@ class MaterialAutoSuggestInputComponent extends MaterialSelectBase
231254
/// Show or hide the trailing close icon.
232255
///
233256
/// Clicking on the icon clears the input text and hides the popup.
257+
/// Defaults to false.
234258
@Input()
235259
bool showClearIcon = false;
236260

@@ -312,7 +336,7 @@ class MaterialAutoSuggestInputComponent extends MaterialSelectBase
312336
if (_cd != null) {
313337
_cd.valueAccessor = this;
314338
}
315-
selection = _defaultSelection;
339+
selection = SelectionModel.single();
316340
}
317341

318342
/// Publishes events when input text changes (on keypress.)
@@ -575,7 +599,7 @@ class MaterialAutoSuggestInputComponent extends MaterialSelectBase
575599
return false;
576600
}
577601

578-
if (selection != _defaultSelection &&
602+
if (shouldClearSelectionOnInput &&
579603
!shouldClearOnSelection &&
580604
_lastSelectedItem != null) {
581605
// deselect previously selected item as the component was not asked to

examples/material_input_example/lib/material_auto_suggest_input_full_demo.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ class MaterialAutoSuggestInputFullDemoComponent {
112112
bool showClearIconTooltip = false;
113113
bool hideCheckbox = false;
114114
bool shouldClearOnSelection = false;
115+
bool shouldClearSelectionOnInput = true;
115116
bool useLabelFactory = false;
116117
bool useFactoryRenderer = false;
117118
bool disabled = false;

examples/material_input_example/lib/material_auto_suggest_input_full_demo.html

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ <h2>Multi selection</h2>
4242
[clearIconTooltip]="clearIconTooltip"
4343
[hideCheckbox]="hideCheckbox"
4444
[shouldClearOnSelection]="shouldClearOnSelection"
45+
[shouldClearSelectionOnInput]="shouldClearSelectionOnInput"
4546
[label]="label"
4647
[labelFactory]="labelFactory"
4748
[leadingGlyph]="leadingGlyph"
@@ -80,7 +81,10 @@ <h3>Options</h3>
8081
</material-checkbox>
8182
<br>
8283
<material-checkbox [(checked)]="shouldClearOnSelection">
83-
Clear on selection
84+
Clear input on selection
85+
</material-checkbox>
86+
<material-checkbox [(checked)]="shouldClearSelectionOnInput">
87+
Clear selection on input
8488
</material-checkbox>
8589
<br>
8690
<material-checkbox [(checked)]="popupMatchInputWidth">

0 commit comments

Comments
 (0)