Skip to content

Commit 6ec3044

Browse files
kbejnarjosephschmitt
authored andcommitted
Add hideOnChosen option (#71)
The hideOnChosen option is handy when users want to be able to choose multiple suggestions at once, such as when the suggestions template is a checkbox list.
1 parent e7a168c commit 6ec3044

File tree

3 files changed

+12
-2
lines changed

3 files changed

+12
-2
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,8 @@ you need to support a "free-text" suggestion with multiple on, be sure to add it
184184
function as a suggestion.
185185
- `hideOnBlur {Boolean}`: Whether the list of suggestions should automatically hide when the
186186
component itself loses focus. Hitting ESC will always close the list of suggestions.
187+
- `hideOnChosen {Boolean}`: Whether the list of suggestions should automatically hide when the
188+
user chooses a suggestion. Defaults to true.
187189
- `isSelectable({suggestion, omnibox}) {Boolean}`: An expression that should evaluate to a Boolean
188190
that determines if a suggestion is able to be interacted with. This expression will be executed
189191
whenever a suggestion is attempted to be highlighted either by the keyboard or mouse. In its locals

src/angularComponent/ngcOmniboxComponent.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ import NgcOmniboxController from './ngcOmniboxController.js';
2525
* controls whether the `ngModel` will be an array (multiple is on) or a single choice (off).
2626
* - `hideOnBlur {Boolean}`: Whether the list of suggestions should automatically hide when the
2727
* component itself loses focus. Hitting ESC will always close the list of suggestions.
28+
* - `hideOnChosen {Boolean}`: Whether the list of suggestions should automatically hide when the
29+
* user chooses a suggestion. Defaults to true.
2830
* - `isSelectable({suggestion}) {Boolean}`: An expression that should evaluate to a Boolean that
2931
* determines if a suggestion is able to be interacted with. This expression will be executed
3032
* whenever a suggestion is attempted to be highlighted either by the keyboard or mouse. It
@@ -58,6 +60,7 @@ export default {
5860
ngDisabled: '&',
5961
multiple: '<?',
6062
hideOnBlur: '@',
63+
hideOnChosen: '<?',
6164
isSelectable: '&',
6265
canShowSuggestions: '&',
6366
requireMatch: '<?',

src/angularComponent/ngcOmniboxController.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,9 @@ export default class NgcOmniboxController {
5151
this.element.addEventListener('blur', (event) => {
5252
blurTimeout = setTimeout(() => {
5353
if (this.hideOnBlur !== 'false') {
54+
if (this.requireMatch && this.hideOnChosen === false) {
55+
this.query = '';
56+
}
5457
this.hideSuggestions = true;
5558
this.highlightedChoice = null;
5659
$scope.$apply();
@@ -413,9 +416,11 @@ export default class NgcOmniboxController {
413416
this.onChosen({choice: item, $event, omnibox: this});
414417
!$event.isDefaultPrevented && $event.performDefault();
415418

416-
this.query = '';
417419
shouldFocusField && this.focus();
418-
this.hideSuggestions = true;
420+
if (this.hideOnChosen !== false) {
421+
this.query = '';
422+
this.hideSuggestions = true;
423+
}
419424
}
420425
}
421426

0 commit comments

Comments
 (0)