Skip to content

Commit 174dc19

Browse files
committed
support custom style on navigation cell
1 parent 8b52ab1 commit 174dc19

File tree

2 files changed

+26
-6
lines changed

2 files changed

+26
-6
lines changed

src/TableBody.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,9 @@ class TableBody extends Component {
3838
const customEditAndNavStyle = typeof keyBoardNav === 'object' ?
3939
keyBoardNav.customStyleOnEditCell :
4040
null;
41+
const customNavStyle = typeof keyBoardNav === 'object' ?
42+
keyBoardNav.customStyle :
43+
null;
4144
let expandColSpan = this.props.columns.filter(col => !col.hidden).length;
4245
if (isSelectRowDefined && !this.props.selectRow.hideSelectColumn) {
4346
expandColSpan += 1;
@@ -119,7 +122,9 @@ class TableBody extends Component {
119122
tabIndex={ (tabIndex++) + '' }
120123
isFocus={ isFocusCell }
121124
keyBoardNav={ enableKeyBoardNav }
122-
onKeyDown={ this.handleCellKeyDown }>
125+
onKeyDown={ this.handleCellKeyDown }
126+
customNavStyle={ customNavStyle }
127+
row={ data }>
123128
{ columnChild }
124129
</TableColumn>
125130
);

src/TableColumn.js

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -105,19 +105,19 @@ class TableColumn extends Component {
105105
style,
106106
isFocus,
107107
keyBoardNav,
108-
tabIndex
108+
tabIndex,
109+
customNavStyle,
110+
row
109111
} = this.props;
110112

111113
let { className } = this.props;
112114

113-
const tdStyle = {
115+
let tdStyle = {
114116
textAlign: dataAlign,
115117
display: hidden ? 'none' : null,
116118
...style
117119
};
118120

119-
className = isFocus ? `${className} default-focus-cell` : className;
120-
121121
const opts = {};
122122

123123
if (cellEdit) {
@@ -133,6 +133,19 @@ class TableColumn extends Component {
133133
if (keyBoardNav && isFocus) {
134134
opts.onKeyDown = this.handleKeyDown;
135135
}
136+
137+
if (isFocus) {
138+
if (customNavStyle) {
139+
const cusmtStyle = typeof customNavStyle === 'function' ?
140+
customNavStyle(children, row) : customNavStyle;
141+
tdStyle = {
142+
...tdStyle,
143+
...cusmtStyle
144+
};
145+
} else {
146+
className = `${className} default-focus-cell`;
147+
}
148+
}
136149
return (
137150
<td tabIndex={ tabIndex } style={ tdStyle }
138151
title={ columnTitle }
@@ -156,7 +169,9 @@ TableColumn.propTypes = {
156169
isFocus: PropTypes.bool,
157170
onKeyDown: PropTypes.func,
158171
tabIndex: PropTypes.string,
159-
keyBoardNav: PropTypes.oneOfType([ PropTypes.bool, PropTypes.object ])
172+
keyBoardNav: PropTypes.oneOfType([ PropTypes.bool, PropTypes.object ]),
173+
customNavStyle: PropTypes.oneOfType([ PropTypes.func, PropTypes.object ]),
174+
row: PropTypes.any /* only used on custom styling for navigation */
160175
};
161176

162177
TableColumn.defaultProps = {

0 commit comments

Comments
 (0)