Skip to content

Commit 8060397

Browse files
committed
[Controls] Fix deselecting (blank) option from options list (elastic#242036)
## Summary Closes elastic#241750 Fixes an error with deselecting a `(blank)` option from an options list. The same error when *selecting* the option was fixed in elastic#239791, but we missed fixing it for deselection. ### Checklist - [x] [Unit or functional tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html) were updated or added to match the most common scenarios (cherry picked from commit 783f287)
1 parent 28e490e commit 8060397

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

src/platform/plugins/shared/controls/public/controls/data_controls/options_list_control/get_options_list_control_factory.test.tsx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,11 @@ describe('Options List Control Api', () => {
269269
await waitFor(async () => {
270270
expect(option).toBeChecked();
271271
});
272+
273+
await userEvent.click(option);
274+
await waitFor(async () => {
275+
expect(option).not.toBeChecked();
276+
});
272277
});
273278

274279
test('clicking another option unselects "Exists"', async () => {

src/platform/plugins/shared/controls/public/controls/data_controls/options_list_control/get_options_list_control_factory.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -345,7 +345,7 @@ export const getOptionsListControlFactory = (): DataControlFactory<
345345
loadMoreSubject,
346346
deselectOption: (key: string | undefined) => {
347347
const field = api.field$.getValue();
348-
if (!key || !field) {
348+
if (key == null || !field) {
349349
api.setBlockingError(
350350
new Error(OptionsListStrings.control.getInvalidSelectionMessage())
351351
);

0 commit comments

Comments
 (0)