Skip to content

Commit

Permalink
show md-show-clear-button only when button is visible
Browse files Browse the repository at this point in the history
  • Loading branch information
miguelcobain committed Sep 28, 2017
1 parent 3a5f301 commit 41765e6
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 5 deletions.
27 changes: 24 additions & 3 deletions addon/components/paper-autocomplete-trigger.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,20 @@ const { Component, isPresent, isBlank, run, get, computed } = Ember;
export default Component.extend({
layout,
tagName: 'md-autocomplete-wrap',
classNames: ['md-show-clear-button'],
classNameBindings: ['noLabel:md-whiteframe-z1', 'select.isOpen:md-menu-showing'],
classNameBindings: ['noLabel:md-whiteframe-z1', 'select.isOpen:md-menu-showing', 'showingClearButton:md-show-clear-button'],

noLabel: computed.not('extra.label'),
_innerText: computed.oneWay('searchText'),

showingClearButton: computed('allowClear', 'disabled', 'resetButtonDestroyed', function() {
// make room for clear button:
// - if we're enabled
// - or if we're disabled but the button still wasn't destroyed
return this.get('allowClear') && (
!this.get('disabled') || (this.get('disabled') && !this.get('resetButtonDestroyed'))
);
}),

text: computed('selected', 'searchText', '_innerText', {
get() {
let {
Expand Down Expand Up @@ -56,11 +64,13 @@ export default Component.extend({
let oldSelect = this.get('_oldSelect');
let oldLastSearchedText = this.get('_lastSearchedText');
let oldLoading = this.get('_loading');
let oldDisabled = this.get('_lastDisabled');

let select = this.get('select');
let loading = this.get('loading');
let searchText = this.get('searchText');
let lastSearchedText = this.get('lastSearchedText');
let disabled = this.get('disabled');

if (oldSelect && oldSelect.isOpen && !select.isOpen && !loading && searchText) {
this.set('text', this.getSelectedAsText());
Expand All @@ -78,10 +88,15 @@ export default Component.extend({
run.schedule('actions', null, select.actions.open);
}

if (oldDisabled && !disabled) {
this.set('resetButtonDestroyed', false);
}

this.setProperties({
_oldSelect: select,
_lastSearchedText: lastSearchedText,
_loading: loading
_loading: loading,
_lastDisabled: disabled
});
},

Expand Down Expand Up @@ -119,6 +134,12 @@ export default Component.extend({
}
this.get('onInput')(e.target ? e : { target: { value: e } });
this.set('text', e.target ? e.target.value : e);
},

resetButtonDestroyed() {
if (this.get('disabled')) {
this.set('resetButtonDestroyed', true);
}
}
},
// Methods
Expand Down
6 changes: 5 additions & 1 deletion addon/components/paper-reset-button.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ export default Component.extend(TransitionMixin, {
return;
}
onReset(e);
}
},

didTransitionOut() {
this._super(...arguments);
this.sendAction('onDidTransitionOut');
}
});
2 changes: 1 addition & 1 deletion addon/templates/components/paper-autocomplete-trigger.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
{{paper-progress-linear classNameBindings="extra.label:md-inline"}}
{{/if}}
{{#if (and (or selected text) allowClear (not select.disabled))}}
{{#paper-reset-button onReset=(action "clear") tabindex="-1"}}
{{#paper-reset-button onReset=(action "clear") onDidTransitionOut=(action "resetButtonDestroyed") tabindex="-1"}}
{{paper-icon "close"}}
{{/paper-reset-button}}
{{/if}}

0 comments on commit 41765e6

Please sign in to comment.