Ghost/ghost/admin/app/components/gh-trim-focus-input.js
Kevin Ansfield 245f4ea80e auto-expanding editor title input (#699)
closes https://github.com/TryGhost/Ghost/issues/8463
- move generic text input handling into `text-input` mixin so it applies to text inputs and textareas
- adds `autoExpand` property to `gh-textarea` that accepts a selector to watch for resize changes, if the property is set then auto-expanding behaviour is triggered any time the textarea value is changed or when the selector element is resized (this prevents change in textarea width from toggling nav or split screen mode resulting in textarea content being hidden or the textarea being taller than it's contents)
- adds `ember-element-resize-detector` addon to allow watching of element resizes rather than window resizes (this was already included as a sub-dependency via `ember-light-table`->`ember-scrollable`->`ember-element-resize-detector`)
2017-05-18 17:01:30 +09:00

27 lines
614 B
JavaScript

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,
focusOut(event) {
this._trimInput(event.target.value);
},
_trimInput(value) {
if (value && typeof value.trim === 'function') {
value = value.trim();
}
this._processNewValue(value);
}
});
export default TrimFocusInputComponent;