11import React , { Component , PropTypes } from 'react' ;
2+ import ReactDOM from 'react-dom' ;
23import editor from './Editor' ;
34import Notifier from './Notification.js' ;
45import 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