Skip to content

Commit aaf54ea

Browse files
committed
fix(input-select): Allows the input to keep it's value when the user selects an option when disableCloseOnSelect is true
1 parent c2ba728 commit aaf54ea

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

packages/ui-components/src/lib/inputs/InputSelect/InputSelect.tsx

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@ export const InputSelect: FC<InputSelectProps> = ({
5454
...props
5555
}) => {
5656
const formContext = useFormContext();
57+
const [inputValue, setInputValue] = useState('');
58+
5759
if (!props.formikProps && formContext) props.formikProps = formContext;
5860

5961
const allowCustomValue = autocompleteConfig?.freeSolo || allowCreateOption;
@@ -160,6 +162,8 @@ export const InputSelect: FC<InputSelectProps> = ({
160162

161163
// Note: This function only exists to handle auto-filling right now.
162164
const handleInputChange = (event: ChangeEvent<HTMLInputElement | HTMLTextAreaElement>) => {
165+
setInputValue(event.target.value);
166+
163167
const selectedOption = event.target.value ? findOptionByValueOrLabel(event.target.value) : null;
164168

165169
if (props.inputProps?.autoComplete !== 'off' && selectedOption && isAutoFilling)
@@ -291,6 +295,15 @@ export const InputSelect: FC<InputSelectProps> = ({
291295
...autocompleteConfig
292296
};
293297

298+
// Allows the input to keep it's value when the user selects an option when disableCloseOnSelect is true
299+
if (isMultiselect && autocompleteProps.disableCloseOnSelect) {
300+
autocompleteProps.inputValue = inputValue;
301+
autocompleteProps.onBlur = event => {
302+
setInputValue('');
303+
if (autocompleteProps.onBlur) autocompleteProps.onBlur(event);
304+
};
305+
}
306+
294307
return (
295308
<Autocomplete
296309
className={classNames('lc-input-select', className, { 'lc-input-multiselect': isMultiselect })}

packages/ui-components/src/lib/inputs/InputSelect/input-select-documentation/input-select.stories.mdx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,7 @@ import dedent from 'string-dedent';
301301
{ label: 'Option 5', value: 5 }
302302
]}
303303
formikProps={formikProps}
304-
autocompleteConfig={{ multiple: true }}
304+
autocompleteConfig={{ multiple: true, disableCloseOnSelect: true }}
305305
/>
306306
</>
307307
);
@@ -332,7 +332,7 @@ import dedent from 'string-dedent';
332332
{ label: 'Option 5', value: 5 }
333333
]}
334334
formikProps={formikProps}
335-
autocompleteConfig={{ multiple: true }}
335+
autocompleteConfig={{ multiple: true, disableCloseOnSelect: true }}
336336
/>
337337
</>
338338
);

0 commit comments

Comments
 (0)