Skip to content

Commit 8b52ab1

Browse files
committed
custom nav styling on cell editing
1 parent 776cf80 commit 8b52ab1

File tree

2 files changed

+52
-6
lines changed

2 files changed

+52
-6
lines changed

src/TableBody.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@ class TableBody extends Component {
3535
const inputType = this.props.selectRow.mode === Const.ROW_SELECT_SINGLE ? 'radio' : 'checkbox';
3636
const CustomComponent = this.props.selectRow.customComponent;
3737
const enableKeyBoardNav = (keyBoardNav === true || typeof keyBoardNav === 'object');
38+
const customEditAndNavStyle = typeof keyBoardNav === 'object' ?
39+
keyBoardNav.customStyleOnEditCell :
40+
null;
3841
let expandColSpan = this.props.columns.filter(col => !col.hidden).length;
3942
if (isSelectRowDefined && !this.props.selectRow.hideSelectColumn) {
4043
expandColSpan += 1;
@@ -74,7 +77,9 @@ class TableBody extends Component {
7477
fieldValue={ fieldValue }
7578
className={ column.editClassName }
7679
invalidColumnClassName={ column.invalidEditColumnClassName }
77-
beforeShowError={ beforeShowError } />
80+
beforeShowError={ beforeShowError }
81+
isFocus={ isFocusCell }
82+
customStyleWithNav={ customEditAndNavStyle } />
7883
);
7984
} else {
8085
// add by bluespring for className customize

src/TableEditColumn.js

Lines changed: 46 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import React, { Component, PropTypes } from 'react';
2+
import ReactDOM from 'react-dom';
23
import editor from './Editor';
34
import Notifier from './Notification.js';
45
import classSet from 'classnames';
@@ -111,8 +112,24 @@ class TableEditColumn extends Component {
111112
this.timeouteClear = 0;
112113
}
113114
}
115+
114116
componentDidMount() {
115117
this.refs.inputRef.focus();
118+
const dom = ReactDOM.findDOMNode(this);
119+
if (this.props.isFocus) {
120+
dom.focus();
121+
} else {
122+
dom.blur();
123+
}
124+
}
125+
126+
componentDidUpdate() {
127+
const dom = ReactDOM.findDOMNode(this);
128+
if (this.props.isFocus) {
129+
dom.focus();
130+
} else {
131+
dom.blur();
132+
}
116133
}
117134

118135
componentWillUnmount() {
@@ -126,22 +143,31 @@ class TableEditColumn extends Component {
126143
}
127144

128145
render() {
129-
const { editable, format, customEditor } = this.props;
130-
const { shakeEditor, className } = this.state;
146+
const {
147+
editable,
148+
format,
149+
customEditor,
150+
isFocus,
151+
customStyleWithNav,
152+
row
153+
} = this.props;
154+
const { shakeEditor } = this.state;
131155
const attr = {
132156
ref: 'inputRef',
133157
onKeyDown: this.handleKeyPress,
134158
onBlur: this.handleBlur
135159
};
160+
let style = { position: 'relative' };
136161
let { fieldValue } = this.props;
162+
let { className } = this.state;
137163
// put placeholder if exist
138164
editable.placeholder && (attr.placeholder = editable.placeholder);
139165

140166
const editorClass = classSet({ 'animated': shakeEditor, 'shake': shakeEditor });
141167
let cellEditor;
142168
if (customEditor) {
143169
const customEditorProps = {
144-
row: this.props.row,
170+
row,
145171
...attr,
146172
defaultValue: fieldValue || '',
147173
...customEditor.customEditorParameters
@@ -152,9 +178,22 @@ class TableEditColumn extends Component {
152178
cellEditor = editor(editable, attr, format, editorClass, fieldValue || '');
153179
}
154180

181+
if (isFocus) {
182+
if (customStyleWithNav) {
183+
const customStyle = typeof customStyleWithNav === 'function' ?
184+
customStyleWithNav(fieldValue, row) : customStyleWithNav;
185+
style = {
186+
...style,
187+
...customStyle
188+
};
189+
} else {
190+
className = `${className} default-focus-cell`;
191+
}
192+
}
193+
155194
return (
156195
<td ref='td'
157-
style={ { position: 'relative' } }
196+
style={ style }
158197
className={ className }
159198
onClick={ this.handleClick }>
160199
{ cellEditor }
@@ -187,7 +226,9 @@ TableEditColumn.propTypes = {
187226
PropTypes.object
188227
]),
189228
className: PropTypes.any,
190-
beforeShowError: PropTypes.func
229+
beforeShowError: PropTypes.func,
230+
isFocus: PropTypes.bool,
231+
customStyleWithNav: PropTypes.oneOfType([ PropTypes.func, PropTypes.object ])
191232
};
192233

193234

0 commit comments

Comments
 (0)