11import React from 'react' ;
2+ import PropTypes from 'prop-types' ;
23import { getColumnOptions } from 'dtable-utils' ;
34import { KeyCodes , DELETED_OPTION_BACKGROUND_COLOR , DELETED_OPTION_TIPS } from '../../constants' ;
45import classnames from 'classnames' ;
56import SingleSelectEditor from '../../SingleSelectEditor' ;
67import { getLocale } from '../../lang' ;
8+ import ObjectUtils from '../../utils/object-utils' ;
79
810import './index.css' ;
911
@@ -27,8 +29,8 @@ class RowExpandSingleSelectEditor extends React.Component {
2729 }
2830
2931 UNSAFE_componentWillReceiveProps ( nextProps ) {
30- const { value } = nextProps ;
31- if ( value !== this . props . value ) {
32+ const { value, column } = nextProps ;
33+ if ( value !== this . props . value || ! ObjectUtils . isSameObject ( column , this . props . column ) ) {
3234 this . options = this . getOptions ( nextProps ) ;
3335 this . setState ( { value, showSelectPopover : false } ) ;
3436 }
@@ -88,7 +90,7 @@ class RowExpandSingleSelectEditor extends React.Component {
8890
8991 hideDropDownMenu = ( event ) => {
9092 if ( ! event . target ) return ;
91- if ( ! this . singleSelectContainer . contains ( event . target ) && this . state . showSelectPopover ) {
93+ if ( ! this . ref . contains ( event . target ) && this . state . showSelectPopover ) {
9294 const singleSelectEditor = document . getElementsByClassName ( 'dtable-ui-select-editor-container' ) [ 0 ] ;
9395 if ( singleSelectEditor && singleSelectEditor . contains ( event . target ) ) return ;
9496 this . toggleSingleSelect ( false ) ;
@@ -116,7 +118,7 @@ class RowExpandSingleSelectEditor extends React.Component {
116118 } ;
117119
118120 renderOption = ( ) => {
119- const { isEditorFocus } = this . props ;
121+ const { isEditorFocus, classNamePrefix , placeholder } = this . props ;
120122 const { value } = this . state ;
121123 const option = this . options . find ( o => o [ this . key ] === value ) ;
122124 const optionStyle = option ?
@@ -130,15 +132,16 @@ class RowExpandSingleSelectEditor extends React.Component {
130132 onFocus = { this . onFocus }
131133 onClick = { this . onToggleSelect }
132134 ref = { ref => this . selectRef = ref }
133- className = { classnames ( 'dtable-ui dtable-ui-row-expand-select-editor custom-select' , { 'focus' : isEditorFocus } ) }
135+ className = { classnames ( 'dtable-ui dtable-ui-row-expand-select-editor custom-select' , { 'focus' : isEditorFocus , [ ` ${ classNamePrefix } -select-editor` ] : classNamePrefix } ) }
134136 >
135- < div className = " dtable-ui-row-expand-select-editor-inner" >
136- < div >
137+ < div className = { classnames ( ' dtable-ui-row-expand-select-editor-inner' , { [ ` ${ classNamePrefix } -select-editor-inner` ] : classNamePrefix } ) } >
138+ < div className = { classnames ( '' , { [ ` ${ classNamePrefix } -select-editor-inner-container` ] : classNamePrefix } ) } >
137139 { value && (
138140 < div className = "dtable-ui-select-option" style = { optionStyle } title = { optionName } >
139141 { optionName }
140142 </ div >
141143 ) }
144+ { ! value && placeholder && ( < > { placeholder } </ > ) }
142145 </ div >
143146 < i aria-hidden = "true" className = "dtable-font dtable-icon-down3" > </ i >
144147 </ div >
@@ -147,10 +150,10 @@ class RowExpandSingleSelectEditor extends React.Component {
147150 } ;
148151
149152 render ( ) {
150- const { isSupportNewOption, onAddNewOption, column } = this . props ;
153+ const { isSupportNewOption, onAddNewOption, column, classNamePrefix } = this . props ;
151154 const { showSelectPopover, value } = this . state ;
152155 return (
153- < div className = "position-relative w-100" ref = { ref => this . singleSelectContainer = ref } >
156+ < div className = "position-relative w-100" ref = { ref => this . ref = ref } >
154157 { this . renderOption ( ) }
155158 < span ref = { ref => this . targetRef = ref } > </ span >
156159 { showSelectPopover && (
@@ -161,6 +164,7 @@ class RowExpandSingleSelectEditor extends React.Component {
161164 value = { value }
162165 valueKey = { this . key }
163166 target = { this . targetRef }
167+ classNamePrefix = { classNamePrefix }
164168 onCommit = { this . onChange }
165169 isSupportNewOption = { isSupportNewOption }
166170 onAddNewOption = { onAddNewOption }
@@ -173,4 +177,19 @@ class RowExpandSingleSelectEditor extends React.Component {
173177
174178}
175179
180+ RowExpandSingleSelectEditor . propTypes = {
181+ column : PropTypes . object ,
182+ value : PropTypes . array ,
183+ valueKey : PropTypes . string ,
184+ isSupportNewOption : PropTypes . bool ,
185+ onAddNewOption : PropTypes . func ,
186+ isEditorFocus : PropTypes . bool ,
187+ classNamePrefix : PropTypes . string ,
188+ placeholder : PropTypes . any ,
189+ columnIndex : PropTypes . number ,
190+ updateTabIndex : PropTypes . func ,
191+ onEditorOpen : PropTypes . func ,
192+ onEditorClose : PropTypes . func ,
193+ } ;
194+
176195export default RowExpandSingleSelectEditor ;
0 commit comments