11import React from 'react' ;
2+ import PropTypes from 'prop-types' ;
23import { getColumnOptions } from 'dtable-utils' ;
34import classnames from 'classnames' ;
45import { KeyCodes , DELETED_OPTION_BACKGROUND_COLOR , DELETED_OPTION_TIPS } from '../../constants' ;
56import MultipleSelectEditor from '../../MultipleSelectEditor' ;
67import { getLocale } from '../../lang' ;
8+ import ObjectUtils from '../../utils/object-utils' ;
79
810import './index.css' ;
911
@@ -26,8 +28,8 @@ class RowExpandMultipleSelectEditor extends React.Component {
2628 }
2729
2830 UNSAFE_componentWillReceiveProps ( nextProps ) {
29- const { value } = nextProps ;
30- if ( value !== this . props . value ) {
31+ const { value, column } = nextProps ;
32+ if ( value !== this . props . value || ! ObjectUtils . isSameObject ( column , this . props . column ) ) {
3133 this . options = this . getOptions ( nextProps ) ;
3234 this . setState ( { value } ) ;
3335 }
@@ -69,7 +71,7 @@ class RowExpandMultipleSelectEditor extends React.Component {
6971 } ;
7072
7173 hideDropDownMenu = ( event ) => {
72- if ( ! event . target || event . target . tagName . toUpperCase ( ) === 'INPUT' ) return ;
74+ if ( ! event . target ) return ;
7375 if ( ! this . ref . contains ( event . target ) && this . state . showSelectPopover ) {
7476 const singleSelectEditor = document . getElementsByClassName ( 'dtable-ui-select-editor-container' ) [ 0 ] ;
7577 if ( singleSelectEditor && singleSelectEditor . contains ( event . target ) ) return ;
@@ -80,7 +82,8 @@ class RowExpandMultipleSelectEditor extends React.Component {
8082 onToggleSelect = ( e ) => {
8183 e . preventDefault ( ) ;
8284 e . stopPropagation ( ) ;
83- this . props . updateTabIndex ( this . props . columnIndex ) ;
85+ const { updateTabIndex, columnIndex } = this . props ;
86+ updateTabIndex && updateTabIndex ( columnIndex ) ;
8487 this . toggleSingleSelect ( true ) ;
8588 } ;
8689
@@ -89,7 +92,8 @@ class RowExpandMultipleSelectEditor extends React.Component {
8992 } ;
9093
9194 onFocus = ( ) => {
92- this . props . updateTabIndex ( this . props . columnIndex ) ;
95+ const { updateTabIndex, columnIndex } = this . props ;
96+ updateTabIndex && updateTabIndex ( columnIndex ) ;
9397 } ;
9498
9599 onChange = ( option ) => {
@@ -148,7 +152,7 @@ class RowExpandMultipleSelectEditor extends React.Component {
148152 } ;
149153
150154 renderOptions = ( ) => {
151- const { isEditorFocus } = this . props ;
155+ const { isEditorFocus, classNamePrefix , placeholder } = this . props ;
152156 const options = this . getMultipleSelectList ( ) ;
153157
154158 return (
@@ -157,15 +161,16 @@ class RowExpandMultipleSelectEditor extends React.Component {
157161 onFocus = { this . onFocus }
158162 onClick = { this . onToggleSelect }
159163 ref = { ref => this . multipleSelectOptionsRef = ref }
160- className = { classnames ( 'dtable-ui dtable-ui-row-expand-select-editor custom-select' , { 'focus' : isEditorFocus } ) }
164+ className = { classnames ( 'dtable-ui dtable-ui-row-expand-select-editor custom-select' , { 'focus' : isEditorFocus , [ ` ${ classNamePrefix } -select-editor` ] : classNamePrefix } ) }
161165 >
162- < div className = " dtable-ui-row-expand-select-editor-inner" >
163- < div >
166+ < div className = { classnames ( ' dtable-ui-row-expand-select-editor-inner' , { [ ` ${ classNamePrefix } -select-editor-inner` ] : classNamePrefix } ) } >
167+ < div className = { classnames ( '' , { [ ` ${ classNamePrefix } -select-editor-inner-container` ] : classNamePrefix } ) } >
164168 { options . length > 0 &&
165- < div className = " dtable-ui-row-expand-select-options" >
169+ < div className = { classnames ( ' dtable-ui-row-expand-select-options' , { [ ` ${ classNamePrefix } -select-editor-options` ] : classNamePrefix } ) } >
166170 { options }
167171 </ div >
168172 }
173+ { options . length === 0 && placeholder && ( < > { placeholder } </ > ) }
169174 </ div >
170175 < i aria-hidden = "true" className = "dtable-font dtable-icon-down3" > </ i >
171176 </ div >
@@ -174,7 +179,7 @@ class RowExpandMultipleSelectEditor extends React.Component {
174179 } ;
175180
176181 render ( ) {
177- const { column, isSupportNewOption, onAddNewOption } = this . props ;
182+ const { column, isSupportNewOption, onAddNewOption, classNamePrefix } = this . props ;
178183 const { showSelectPopover, value } = this . state ;
179184 return (
180185 < div className = "position-relative w-100" ref = { ref => this . ref = ref } >
@@ -188,6 +193,7 @@ class RowExpandMultipleSelectEditor extends React.Component {
188193 value = { value }
189194 valueKey = { this . key }
190195 target = { this . targetRef }
196+ classNamePrefix = { classNamePrefix }
191197 onCommit = { this . onChange }
192198 isSupportNewOption = { isSupportNewOption }
193199 onAddNewOption = { onAddNewOption }
@@ -200,4 +206,19 @@ class RowExpandMultipleSelectEditor extends React.Component {
200206
201207}
202208
209+ RowExpandMultipleSelectEditor . propTypes = {
210+ column : PropTypes . object ,
211+ value : PropTypes . array ,
212+ valueKey : PropTypes . string ,
213+ isSupportNewOption : PropTypes . bool ,
214+ onAddNewOption : PropTypes . func ,
215+ isEditorFocus : PropTypes . bool ,
216+ classNamePrefix : PropTypes . string ,
217+ placeholder : PropTypes . any ,
218+ columnIndex : PropTypes . number ,
219+ updateTabIndex : PropTypes . func ,
220+ onEditorOpen : PropTypes . func ,
221+ onEditorClose : PropTypes . func ,
222+ } ;
223+
203224export default RowExpandMultipleSelectEditor ;
0 commit comments