2018-02-28 14:44:03 +03:00
|
|
|
import GhostTextInput from 'ghost-admin/components/gh-text-input';
|
2022-02-01 12:34:03 +03:00
|
|
|
import classic from 'ember-classic-decorator';
|
2015-10-28 14:36:45 +03:00
|
|
|
|
2016-06-18 14:44:23 +03:00
|
|
|
/**
|
|
|
|
* 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
|
|
|
|
*/
|
2022-02-01 12:34:03 +03:00
|
|
|
@classic
|
|
|
|
class TrimFocusInputComponent extends GhostTextInput {
|
|
|
|
shouldFocus = true;
|
2016-06-18 14:44:23 +03:00
|
|
|
|
2017-01-23 15:03:05 +03:00
|
|
|
focusOut(event) {
|
2018-02-28 14:44:03 +03:00
|
|
|
this._trimInput(event.target.value, event);
|
2022-02-01 12:34:03 +03:00
|
|
|
super.focusOut(...arguments);
|
|
|
|
}
|
2017-01-23 15:03:05 +03:00
|
|
|
|
2018-02-28 14:44:03 +03:00
|
|
|
_trimInput(value, event) {
|
2017-01-23 15:03:05 +03:00
|
|
|
if (value && typeof value.trim === 'function') {
|
|
|
|
value = value.trim();
|
2016-07-22 16:36:50 +03:00
|
|
|
}
|
2017-01-23 15:03:05 +03:00
|
|
|
|
2018-02-28 14:44:03 +03:00
|
|
|
this.element.value = value;
|
|
|
|
this._elementValueDidChange(event);
|
|
|
|
|
2019-03-06 16:53:54 +03:00
|
|
|
let inputMethod = this.input;
|
2018-02-28 14:44:03 +03:00
|
|
|
if (inputMethod) {
|
|
|
|
inputMethod(event);
|
|
|
|
}
|
2015-12-15 14:09:34 +03:00
|
|
|
}
|
2022-02-01 12:34:03 +03:00
|
|
|
}
|
2016-06-18 14:44:23 +03:00
|
|
|
|
|
|
|
export default TrimFocusInputComponent;
|