Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions packages/common/src/select/select.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,11 @@ const handleSelectChange = (option, simpleValue, isMulti, onChange, allOptions,

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

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

if (isMulti && enhanceOption.find(({ selectNone }) => selectNone)) {
if (isMulti && sanitizedOption.find(({ selectNone }) => selectNone)) {
return onChange([]);
}

Expand Down
47 changes: 47 additions & 0 deletions packages/common/src/tests/select/select.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,53 @@ describe('Select test', () => {
expect(inputValue).toEqual(['d', 'c']);
});

it('selects null value - clears selection', async () => {
field = { ...field, isMulti: true };

await act(async () => {
wrapper = mount(
<FormRenderer
{...rendererProps}
schema={{
fields: [
{
...field,
component: componentTypes.SELECT,
name: 'select'
}
]
}}
/>
);
});
wrapper.update();

await act(async () => {
wrapper
.find('#onChange')
.props()
.onClick([{ value: 'd' }, { value: 'c' }]);
});
wrapper.update();

expect(state.value).toEqual([
{ label: 'Dogs', value: 'd' },
{ label: 'Cats', value: 'c' }
]);
expect(inputValue).toEqual(['d', 'c']);

await act(async () => {
wrapper
.find('#onChange')
.props()
.onClick(null);
});
wrapper.update();

expect(state.value).toEqual([]);
expect(inputValue).toEqual([]);
});

it('selects all values', async () => {
field = { ...field, isMulti: true, options: [{ label: 'Select all', selectAll: true }, ...field.options] };

Expand Down