Skip to content
Merged
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
43 changes: 37 additions & 6 deletions src/TableEditColumn.js
Original file line number Diff line number Diff line change
Expand Up @@ -148,8 +148,8 @@ class TableEditColumn extends Component {
}

focusInEditor() {
if (Util.isFunction(this.refs.inputRef.focus)) {
this.refs.inputRef.focus();
if (this.inputRef && Util.isFunction(this.inputRef.focus)) {
this.inputRef.focus();
}
}

Expand All @@ -159,6 +159,30 @@ class TableEditColumn extends Component {
}
}

getInputRef = userRef => ref => {
this.inputRef = ref;
if (typeof userRef === 'string') {
throw new Error('Ref must be a function');
}
if (Util.isFunction(userRef)) {
userRef(ref);
}
}

getHandleKeyPress = userHandler => e => {
this.handleKeyPress(e);
if (Util.isFunction(userHandler)) {
userHandler(e);
}
}

getHandleBlur = userHandler => e => {
this.handleBlur(e);
if (Util.isFunction(userHandler)) {
userHandler(e);
}
}

render() {
const {
editable,
Expand All @@ -170,15 +194,22 @@ class TableEditColumn extends Component {
} = this.props;
const { shakeEditor } = this.state;
const attr = {
ref: 'inputRef',
onKeyDown: this.handleKeyPress,
onBlur: this.handleBlur
...editable.attrs,
ref: this.getInputRef(editable.attrs && editable.attrs.ref),
onKeyDown: this.getHandleKeyPress(editable.attrs && editable.attrs.onKeyDown),
onBlur: this.getHandleBlur(editable.attrs && editable.attrs.onBlur)
};
let style = { position: 'relative' };
let { fieldValue } = this.props;
let { className } = this.state;
// put placeholder if exist
editable.placeholder && (attr.placeholder = editable.placeholder);
if (editable.placeholder) {
attr.placeholder = editable.placeholder;
/* eslint-disable no-console */
console.warn(
'Setting editable.placeholder is deprecated. Use editable.attrs to set input attributes');
/* eslint-enable no-console */
}

const editorClass = classSet({ 'animated': shakeEditor, 'shake': shakeEditor });
fieldValue = fieldValue === 0 ? '0' : fieldValue;
Expand Down