Skip to content

Instantly share code, notes, and snippets.

@sly7-7
Created November 23, 2016 13:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sly7-7/3c68b4af55416ecc601a340d9e946695 to your computer and use it in GitHub Desktop.
Save sly7-7/3c68b4af55416ecc601a340d9e946695 to your computer and use it in GitHub Desktop.
ember-power-select-typeahead with allowClear
<input type="search"
value={{text}}
id="ember-power-select-typeahead-input-{{select.uniqueId}}"
class="ember-power-select-typeahead-input ember-power-select-search-input"
autocomplete="off"
placeholder={{placeholder}}
oninput={{onInput}}
onfocus={{onFocus}}
onblur={{onBlur}}
onkeydown={{action "handleKeydown"}}
onmousedown={{action "stopPropagation"}}>
{{#if canClear}}
<span class="ember-power-select-clear-btn" onmousedown={{action "clear"}} ontouchstart={{action "clear"}}>&times;</span>
{{/if}}
{{#if select.loading}}
<span class="ember-power-select-typeahead-loading-indicator"></span>
{{/if}}
import Ember from 'ember';
import EmberPowerSelectTypeaheadTrigger from 'ember-power-select-typeahead/components/power-select-typeahead/trigger';
export default EmberPowerSelectTypeaheadTrigger.extend({
canClear: Ember.computed('select.searchText', 'select.disabled', 'allowClear', function() {
return !Ember.isEmpty(this.get('select.searchText')) && !this.get('select.disabled') && this.get('allowClear');
}),
actions: {
clear(e) {
e.stopPropagation();
let input = document.querySelector(`#ember-power-select-typeahead-input-${this.get('select').uniqueId}`);
input.value = '';
this.get('select').actions.search('');
this.get('select').actions.close(this.get('select'), e);
if (e.type === 'touchstart') {
return false;
}
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment