Skip to content

Commit e40f89e

Browse files
authored
Merge pull request #1119 from rvsia/fixClearOptions
fix(common): handle isMulti and null change
2 parents f3872c0 + 602e87f commit e40f89e

File tree

2 files changed

+49
-2
lines changed

2 files changed

+49
-2
lines changed

packages/common/src/select/select.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,11 @@ const handleSelectChange = (option, simpleValue, isMulti, onChange, allOptions,
4242

4343
const sanitizedOption = !enhanceOption && isMulti ? [] : enhanceOption;
4444

45-
if (isMulti && enhanceOption.find(({ selectAll }) => selectAll)) {
45+
if (isMulti && sanitizedOption.find(({ selectAll }) => selectAll)) {
4646
return onChange(allOptions.filter(({ selectAll, selectNone }) => !selectAll && !selectNone).map(({ value }) => value));
4747
}
4848

49-
if (isMulti && enhanceOption.find(({ selectNone }) => selectNone)) {
49+
if (isMulti && sanitizedOption.find(({ selectNone }) => selectNone)) {
5050
return onChange([]);
5151
}
5252

packages/common/src/tests/select/select.test.js

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -314,6 +314,53 @@ describe('Select test', () => {
314314
expect(inputValue).toEqual(['d', 'c']);
315315
});
316316

317+
it('selects null value - clears selection', async () => {
318+
field = { ...field, isMulti: true };
319+
320+
await act(async () => {
321+
wrapper = mount(
322+
<FormRenderer
323+
{...rendererProps}
324+
schema={{
325+
fields: [
326+
{
327+
...field,
328+
component: componentTypes.SELECT,
329+
name: 'select'
330+
}
331+
]
332+
}}
333+
/>
334+
);
335+
});
336+
wrapper.update();
337+
338+
await act(async () => {
339+
wrapper
340+
.find('#onChange')
341+
.props()
342+
.onClick([{ value: 'd' }, { value: 'c' }]);
343+
});
344+
wrapper.update();
345+
346+
expect(state.value).toEqual([
347+
{ label: 'Dogs', value: 'd' },
348+
{ label: 'Cats', value: 'c' }
349+
]);
350+
expect(inputValue).toEqual(['d', 'c']);
351+
352+
await act(async () => {
353+
wrapper
354+
.find('#onChange')
355+
.props()
356+
.onClick(null);
357+
});
358+
wrapper.update();
359+
360+
expect(state.value).toEqual([]);
361+
expect(inputValue).toEqual([]);
362+
});
363+
317364
it('selects all values', async () => {
318365
field = { ...field, isMulti: true, options: [{ label: 'Select all', selectAll: true }, ...field.options] };
319366

0 commit comments

Comments
 (0)