1
0
Fork 0
mirror of https://github.com/TryGhost/Ghost-Admin.git synced 2023-12-14 02:33:04 +01:00
Ghost-Admin/app/components/gh-trim-focus-input.js
Greenkeeper 526a2392bb Update ember-one-way-controls to version 2.0.0 🚀 (#475)
* chore(package): update ember-one-way-controls to version 2.0.0
* update yarn.lock
* update `gh-trim-focus-input` for removal of `sanitizeInput` in `ember-one-way-controls`
2017-01-23 12:03:05 +00:00

55 lines
1.2 KiB
JavaScript

/* global device */
import computed from 'ember-computed';
import GhostInput from 'ghost-admin/components/gh-input';
/**
* This doesn't override the OneWayInput component because
* we need finer control. It borrows
* parts from both the OneWayInput component and Ember's default
* input component
*/
const TrimFocusInputComponent = GhostInput.extend({
shouldFocus: true,
attributeBindings: ['autofocus'],
autofocus: computed(function () {
if (this.get('shouldFocus')) {
return (device.ios()) ? false : 'autofocus';
}
return false;
}),
init() {
this._super(...arguments);
},
didInsertElement() {
this._super(...arguments);
this._focus();
},
focusOut(event) {
this._trimInput(event.target.value);
},
_trimInput(value) {
if (value && typeof value.trim === 'function') {
value = value.trim();
}
this._processNewValue(value);
},
_focus() {
// Until mobile safari has better support
// for focusing, we just ignore it
if (this.get('shouldFocus') && !device.ios()) {
this.element.focus();
}
}
});
export default TrimFocusInputComponent;