feat: allow clear select value (#735)
This commit is contained in:
@@ -15,6 +15,7 @@ const ReactSelect: React.FC<Props> = (props) => {
|
||||
disabled = false,
|
||||
placeholder,
|
||||
isSearchable = true,
|
||||
isClearable,
|
||||
} = props;
|
||||
|
||||
const classes = [
|
||||
@@ -35,6 +36,7 @@ const ReactSelect: React.FC<Props> = (props) => {
|
||||
classNamePrefix="rs"
|
||||
options={options}
|
||||
isSearchable={isSearchable}
|
||||
isClearable={isClearable}
|
||||
/>
|
||||
);
|
||||
};
|
||||
|
||||
@@ -21,4 +21,5 @@ export type Props = {
|
||||
onMenuScrollToBottom?: () => void
|
||||
placeholder?: string
|
||||
isSearchable?: boolean
|
||||
isClearable?: boolean
|
||||
}
|
||||
|
||||
@@ -42,6 +42,7 @@ const SelectInput: React.FC<SelectInputProps> = (props) => {
|
||||
width,
|
||||
options,
|
||||
hasMany,
|
||||
isClearable,
|
||||
} = props;
|
||||
|
||||
const classes = [
|
||||
@@ -84,6 +85,7 @@ const SelectInput: React.FC<SelectInputProps> = (props) => {
|
||||
isDisabled={readOnly}
|
||||
options={options}
|
||||
isMulti={hasMany}
|
||||
isClearable={isClearable}
|
||||
/>
|
||||
<FieldDescription
|
||||
value={value}
|
||||
|
||||
@@ -34,6 +34,7 @@ const Select: React.FC<Props> = (props) => {
|
||||
description,
|
||||
condition,
|
||||
} = {},
|
||||
isClearable,
|
||||
} = props;
|
||||
|
||||
const path = pathFromProps || name;
|
||||
@@ -62,7 +63,9 @@ const Select: React.FC<Props> = (props) => {
|
||||
const onChange = useCallback((selectedOption) => {
|
||||
if (!readOnly) {
|
||||
let newValue;
|
||||
if (hasMany) {
|
||||
if (!selectedOption) {
|
||||
newValue = undefined;
|
||||
} else if (hasMany) {
|
||||
if (Array.isArray(selectedOption)) {
|
||||
newValue = selectedOption.map((option) => option.value);
|
||||
} else {
|
||||
@@ -96,6 +99,7 @@ const Select: React.FC<Props> = (props) => {
|
||||
className={className}
|
||||
width={width}
|
||||
hasMany={hasMany}
|
||||
isClearable={isClearable}
|
||||
/>
|
||||
);
|
||||
};
|
||||
|
||||
@@ -144,6 +144,7 @@ export const select = baseField.keys({
|
||||
joi.array().items(joi.string().allow('')),
|
||||
joi.func(),
|
||||
),
|
||||
isClearable: joi.boolean().default(false),
|
||||
});
|
||||
|
||||
export const radio = baseField.keys({
|
||||
|
||||
@@ -214,6 +214,7 @@ export type SelectField = FieldBase & {
|
||||
type: 'select'
|
||||
options: Option[]
|
||||
hasMany?: boolean
|
||||
isClearable?: boolean;
|
||||
}
|
||||
|
||||
export type RelationshipField = FieldBase & {
|
||||
|
||||
Reference in New Issue
Block a user