Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions src/RIEStatefulBase.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,20 @@ export default class RIEStatefulBase extends RIEBase {
else if (event.keyCode === 27) { this.cancelEditing() } // Escape
};

keyUp = () => {
debug('keyUp')
this.resizeInput(this.refs.input);
};

resizeInput = (input) => {
if (!input.startW) { input.startW = input.offsetWidth; }
const style = input.style;
style.width = 0; // recalculate from 0, in case characters are deleted
let desiredW = input.scrollWidth;
desiredW += input.offsetHeight; // pad to reduce jerkyness when typing
style.width = Math.max(desiredW, input.startW) + 'px';
}

textChanged = (event) => {
debug('textChanged(${event.target.value})')
this.doValidations(event.target.value.trim());
Expand All @@ -56,6 +70,7 @@ export default class RIEStatefulBase extends RIEBase {
if (this.state.editing && !prevState.editing) {
debug('entering edit mode')
inputElem.focus();
this.resizeInput(inputElem);
this.selectInputText(inputElem);
} else if (this.state.editing && prevProps.text != this.props.text) {
debug('not editing && text not equal previous props -- finishing editing')
Expand All @@ -73,6 +88,7 @@ export default class RIEStatefulBase extends RIEBase {
onBlur={this.elementBlur}
ref="input"
onKeyDown={this.keyDown}
onKeyUp={this.keyUp}
{...this.props.editProps} />;
};

Expand Down