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

Commit

Permalink
Add shouldClearSelectionOnInput input on material auto suggest input.
Browse files Browse the repository at this point in the history
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
  • Loading branch information
cissyshi authored and nshahan committed Sep 25, 2018
1 parent 58ccdee commit 98f929a
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,6 @@ class MaterialAutoSuggestInputComponent extends MaterialSelectBase
RelativePosition.AdjacentTopRight
];

final SelectionModel _defaultSelection = SelectionModel.single();

final String popupId;
final String inputId;

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

bool _isInitialized = false;

/// Whether to clear the text once the item is selected from the menu.
/// Whether to clear the input text once the item is selected from the menu.
///
/// Defaults to false.
// TODO(google): rename this to shouldClearInputOnSelection.
@Input()
bool shouldClearOnSelection = false;

/// Whether to clear the selected value from the selection model when the
/// input text changes.
///
/// Defaults to true.
@Input()
bool shouldClearSelectionOnInput = true;

/// Whether to cause dropdown to be closed on activation.
///
/// Defaults to true.
@Input()
bool closeOnActivate = true;

/// Whether to hide the checkbox before the selection item for multi-select.
///
/// Defaults to false.
@Input()
bool hideCheckbox = false;

/// Whether the popup should automatically reposition itself based on space
/// available relative to the viewport.
///
/// Defaults to true.
@Input()
bool enforceSpaceConstraints = true;

/// Whether to clamp the popup position so that it never goes offscreen.
///
/// Defaults to false.
@Input()
bool constrainToViewport = false;

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

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

/// Whether to close on enter even for string non matching options.
///
/// Defaults to false.
@Input()
bool closeOnEnter = false;

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

/// Whether or not the suggestion popup width is at least as wide as the input
/// width.
///
/// Defaults to false.
@Input()
bool popupMatchInputWidth = false;

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

Expand Down Expand Up @@ -312,7 +336,7 @@ class MaterialAutoSuggestInputComponent extends MaterialSelectBase
if (_cd != null) {
_cd.valueAccessor = this;
}
selection = _defaultSelection;
selection = SelectionModel.single();
}

/// Publishes events when input text changes (on keypress.)
Expand Down Expand Up @@ -575,7 +599,7 @@ class MaterialAutoSuggestInputComponent extends MaterialSelectBase
return false;
}

if (selection != _defaultSelection &&
if (shouldClearSelectionOnInput &&
!shouldClearOnSelection &&
_lastSelectedItem != null) {
// deselect previously selected item as the component was not asked to
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ class MaterialAutoSuggestInputFullDemoComponent {
bool showClearIconTooltip = false;
bool hideCheckbox = false;
bool shouldClearOnSelection = false;
bool shouldClearSelectionOnInput = true;
bool useLabelFactory = false;
bool useFactoryRenderer = false;
bool disabled = false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ <h2>Multi selection</h2>
[clearIconTooltip]="clearIconTooltip"
[hideCheckbox]="hideCheckbox"
[shouldClearOnSelection]="shouldClearOnSelection"
[shouldClearSelectionOnInput]="shouldClearSelectionOnInput"
[label]="label"
[labelFactory]="labelFactory"
[leadingGlyph]="leadingGlyph"
Expand Down Expand Up @@ -80,7 +81,10 @@ <h3>Options</h3>
</material-checkbox>
<br>
<material-checkbox [(checked)]="shouldClearOnSelection">
Clear on selection
Clear input on selection
</material-checkbox>
<material-checkbox [(checked)]="shouldClearSelectionOnInput">
Clear selection on input
</material-checkbox>
<br>
<material-checkbox [(checked)]="popupMatchInputWidth">
Expand Down

0 comments on commit 98f929a

Please sign in to comment.