Skip to content

Commit

Permalink
feat(md-select): forward blur events
Browse files Browse the repository at this point in the history
  • Loading branch information
Ullfis committed Sep 2, 2016
1 parent ddacfbd commit f219752
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions src/select/select.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,14 @@ export class MdSelect {
@bindable() label = '';
_suspendUpdate = false;
subscriptions = [];
input = null;
constructor(element, logManager, bindingEngine, taskQueue) {
this.element = element;
this.taskQueue = taskQueue;
this.handleChangeFromViewModel = this.handleChangeFromViewModel.bind(this);
this.handleChangeFromNativeSelect = this.handleChangeFromNativeSelect.bind(this);
this.handleBlur = this.handleBlur.bind(this);
this.log = LogManager.getLogger('md-select');
this.bindingEngine = bindingEngine;
}
Expand Down Expand Up @@ -46,6 +48,7 @@ export class MdSelect {
detached() {
$(this.element).off('change', this.handleChangeFromNativeSelect);
this.attachBlur(false);
$(this.element).material_select('destroy');
this.subscriptions.forEach(sub => sub.dispose());
}
Expand All @@ -56,6 +59,10 @@ export class MdSelect {
});
}
handleBlur() {
fireEvent(this.element, 'blur');
}
disabledChanged(newValue) {
this.toggleControl(newValue);
}
Expand Down Expand Up @@ -97,11 +104,30 @@ export class MdSelect {
}
}
attachBlur(attach) {
if (attach) {
let $wrapper = $(this.element).parent('.select-wrapper');
if ($wrapper.length > 0) {
this.input = $('input.select-dropdown:first', $wrapper);
if (this.input) {
this.input.on('blur', this.handleBlur);
}
}
} else {
if (this.input) {
this.input.off('blur', this.handleBlur);
this.input = null;
}
}
}
createMaterialSelect(destroy) {
this.attachBlur(false);
if (destroy) {
$(this.element).material_select('destroy');
}
$(this.element).material_select();
this.toggleControl(this.disabled);
this.attachBlur(true);
}
}

0 comments on commit f219752

Please sign in to comment.