Skip to content

Commit e02f20c

Browse files
committed
Merge branch 'v4.0.0-dev' of https://github.com/jspaine/react-bootstrap-table into jspaine-v4.0.0-dev
2 parents 9599450 + be82349 commit e02f20c

File tree

1 file changed

+37
-6
lines changed

1 file changed

+37
-6
lines changed

src/TableEditColumn.js

Lines changed: 37 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -148,8 +148,8 @@ class TableEditColumn extends Component {
148148
}
149149

150150
focusInEditor() {
151-
if (Util.isFunction(this.refs.inputRef.focus)) {
152-
this.refs.inputRef.focus();
151+
if (this.inputRef && Util.isFunction(this.inputRef.focus)) {
152+
this.inputRef.focus();
153153
}
154154
}
155155

@@ -159,6 +159,30 @@ class TableEditColumn extends Component {
159159
}
160160
}
161161

162+
getInputRef = userRef => ref => {
163+
this.inputRef = ref;
164+
if (typeof userRef === 'string') {
165+
throw new Error('Ref must be a function');
166+
}
167+
if (Util.isFunction(userRef)) {
168+
userRef(ref);
169+
}
170+
}
171+
172+
getHandleKeyPress = userHandler => e => {
173+
this.handleKeyPress(e);
174+
if (Util.isFunction(userHandler)) {
175+
userHandler(e);
176+
}
177+
}
178+
179+
getHandleBlur = userHandler => e => {
180+
this.handleBlur(e);
181+
if (Util.isFunction(userHandler)) {
182+
userHandler(e);
183+
}
184+
}
185+
162186
render() {
163187
const {
164188
editable,
@@ -170,15 +194,22 @@ class TableEditColumn extends Component {
170194
} = this.props;
171195
const { shakeEditor } = this.state;
172196
const attr = {
173-
ref: 'inputRef',
174-
onKeyDown: this.handleKeyPress,
175-
onBlur: this.handleBlur
197+
...editable.attrs,
198+
ref: this.getInputRef(editable.attrs && editable.attrs.ref),
199+
onKeyDown: this.getHandleKeyPress(editable.attrs && editable.attrs.onKeyDown),
200+
onBlur: this.getHandleBlur(editable.attrs && editable.attrs.onBlur)
176201
};
177202
let style = { position: 'relative' };
178203
let { fieldValue } = this.props;
179204
let { className } = this.state;
180205
// put placeholder if exist
181-
editable.placeholder && (attr.placeholder = editable.placeholder);
206+
if (editable.placeholder) {
207+
attr.placeholder = editable.placeholder;
208+
/* eslint-disable no-console */
209+
console.warn(
210+
'Setting editable.placeholder is deprecated. Use editable.attrs to set input attributes');
211+
/* eslint-enable no-console */
212+
}
182213

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

0 commit comments

Comments
 (0)