diff --git a/examples/style.scss b/examples/style.scss index cb371b3c..29738fff 100644 --- a/examples/style.scss +++ b/examples/style.scss @@ -450,7 +450,7 @@ a { } table:not(.table) { - word-break: normal; + word-break: break-word; } } } diff --git a/src/renderers/Form/NestedSelect.tsx b/src/renderers/Form/NestedSelect.tsx index 3f3a2fcf..f1bcb353 100644 --- a/src/renderers/Form/NestedSelect.tsx +++ b/src/renderers/Form/NestedSelect.tsx @@ -203,7 +203,6 @@ export default class NestedSelectControl extends React.Component< onChange, selectedOptions, joinValues, - valueField, delimiter, extractValue, withChildren, @@ -212,6 +211,8 @@ export default class NestedSelectControl extends React.Component< } = this.props; const {stack} = this.state; + let valueField = this.props.valueField || 'value'; + if ( !Array.isArray(option) && option.children && @@ -219,7 +220,7 @@ export default class NestedSelectControl extends React.Component< typeof index === 'number' ) { const checked = selectedOptions.some( - o => o.value == (option as Option).value + o => o[valueField] == (option as Option)[valueField] ); const uncheckable = cascade ? false @@ -245,60 +246,61 @@ export default class NestedSelectControl extends React.Component< newValue = items.length === option.length ? [] : option; } else if (Array.isArray(option.children)) { if (cascade) { - newValue = xorBy(items, [option], valueField || 'value'); + newValue = xorBy(items, [option], valueField); } else if (withChildren) { option = flattenTree([option]); const fn = option.every( - (opt: Option) => !!~items.findIndex(item => item.value === opt.value) + (opt: Option) => + !!~items.findIndex(item => item[valueField] === opt[valueField]) ) ? xorBy : unionBy; - newValue = fn(items, option as any, valueField || 'value'); + newValue = fn(items, option as any, valueField); } else { newValue = items.filter( item => - !~flattenTree([option], i => (i as Option).value).indexOf( - item.value + !~flattenTree([option], i => (i as Option)[valueField]).indexOf( + item[valueField] ) ); - !~items.map(item => item.value).indexOf(option.value) && + !~items.map(item => item[valueField]).indexOf(option[valueField]) && newValue.push(option); } } else { - newValue = xorBy(items, [option], valueField || 'value'); + newValue = xorBy(items, [option], valueField); } if (joinValues) { newValue = (newValue as Options) - .map(item => item[valueField || 'value']) + .map(item => item[valueField]) .join(delimiter || ','); } else if (extractValue) { - newValue = (newValue as Options).map(item => item[valueField || 'value']); + newValue = (newValue as Options).map(item => item[valueField]); } onChange(newValue); } allChecked(options: Options): boolean { - const {selectedOptions, withChildren} = this.props; + const {selectedOptions, withChildren, valueField} = this.props; return options.every(option => { if (withChildren && option.children) { return this.allChecked(option.children); } return selectedOptions.some( - selectedOption => selectedOption.value == option.value + item => item[valueField || 'value'] == option[valueField || 'value'] ); }); } partialChecked(options: Options): boolean { - const {selectedOptions, withChildren} = this.props; + const {selectedOptions, withChildren, valueField} = this.props; return options.some(option => { if (withChildren && option.children) { return this.partialChecked(option.children); } return selectedOptions.some( - selectedOption => selectedOption.value == option.value + item => item[valueField || 'value'] == option[valueField || 'value'] ); }); } @@ -394,8 +396,10 @@ export default class NestedSelectControl extends React.Component< disabled, searchable, searchPromptText, - translate: __ + translate: __, + labelField } = this.props; + const valueField = this.props.valueField || 'value'; const stack = this.state.stack; @@ -443,7 +447,7 @@ export default class NestedSelectControl extends React.Component< {options.map((option: Option, idx: number) => { const checked = selectedOptions.some( - o => o.value == option.value + o => o[valueField] == option[valueField] ); const selfChecked = !!option.uncheckable || checked; let nodeDisabled = !!option.uncheckable || !!disabled; @@ -452,7 +456,7 @@ export default class NestedSelectControl extends React.Component<