Skip to content

Commit

Permalink
BUGFIX: WIP: Show if selectbox options mismatch with current value
Browse files Browse the repository at this point in the history
  • Loading branch information
mhsdesign committed Jun 12, 2023
1 parent 7ea5dd7 commit 033b086
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,11 @@ export default class MultiSelectBox_ListPreviewSortable extends PureComponent {

// Sorted options by draggable value ordering
const draggableOptions = draggableValues.map(value =>
options.find(option => optionValueAccessor(option) === value)
).filter(Boolean);
options.find(option => optionValueAccessor(option) === value) || {
label: `Invalid: "${value}"`,
icon: 'exclamation-triangle'
}
);

return draggableOptions.map(this.renderOption);
}
Expand Down
19 changes: 13 additions & 6 deletions packages/react-ui-components/src/SelectBox/selectBox.js
Original file line number Diff line number Diff line change
Expand Up @@ -266,12 +266,13 @@ export default class SelectBox extends PureComponent {
// Compare selected value less strictly: allow loose comparision and deep equality of objects
const selectedOption = options.find(option => optionValueAccessor(option) == value || isEqual(optionValueAccessor(option), value)); // eslint-disable-line eqeqeq

// check for null or undefined
/* eslint-disable no-eq-null, eqeqeq */
const valueIsEmpty = value == null || value === '';

if (
displaySearchBox && (
// check for null or undefined
/* eslint-disable no-eq-null, eqeqeq */
value == null ||
value === '' ||
valueIsEmpty ||
this.state.isExpanded ||
plainInputMode
)
Expand All @@ -287,12 +288,18 @@ export default class SelectBox extends PureComponent {
);
}

const showResetButton = Boolean(allowEmpty && !displayLoadingIndicator && value);
const mismatchOfValueInOptions = !valueIsEmpty && !selectedOption;
const showResetButton = (allowEmpty && !displayLoadingIndicator && !valueIsEmpty) || mismatchOfValueInOptions;

return (
<SelectBox_Header
{...this.props}
option={selectedOption}
option={mismatchOfValueInOptions
? {
label: `Invalid: "${value}"`,
icon: 'exclamation-triangle'
} : selectedOption
}
showResetButton={showResetButton}
onReset={this.handleDeleteClick}
onClick={onHeaderClick}
Expand Down

0 comments on commit 033b086

Please sign in to comment.