Skip to content

Commit ea15248

Browse files
[9.1] [Controls] Fix deselecting (blank) option from options list (#242036) (#242472)
# Backport This will backport the following commits from `main` to `9.1`: - [[Controls] Fix deselecting (blank) option from options list (#242036)](#242036) <!--- Backport version: 9.6.6 --> ### Questions ? Please refer to the [Backport tool documentation](https://github.com/sorenlouv/backport) <!--BACKPORT [{"author":{"name":"Zac Xeper","email":"[email protected]"},"sourceCommit":{"committedDate":"2025-11-10T19:31:00Z","message":"[Controls] Fix deselecting (blank) option from options list (#242036)\n\n## Summary\n\nCloses https://github.com/elastic/kibana/issues/241750\n\nFixes an error with deselecting a `(blank)` option from an options list.\n\nThe same error when *selecting* the option was fixed in\nhttps://github.com//pull/239791, but we missed fixing it\nfor deselection.\n\n\n### Checklist\n\n- [x] [Unit or functional\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\nwere updated or added to match the most common scenarios","sha":"783f287fb0ec41359eacc335f0258aaebeb377d1","branchLabelMapping":{"^v9.3.0$":"main","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:fix","Feature:Input Control","Team:Presentation","Project:Controls","backport:version","v9.2.0","v9.3.0","v8.19.7","v9.1.7"],"title":"[Controls] Fix deselecting (blank) option from options list","number":242036,"url":"https://github.com/elastic/kibana/pull/242036","mergeCommit":{"message":"[Controls] Fix deselecting (blank) option from options list (#242036)\n\n## Summary\n\nCloses https://github.com/elastic/kibana/issues/241750\n\nFixes an error with deselecting a `(blank)` option from an options list.\n\nThe same error when *selecting* the option was fixed in\nhttps://github.com//pull/239791, but we missed fixing it\nfor deselection.\n\n\n### Checklist\n\n- [x] [Unit or functional\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\nwere updated or added to match the most common scenarios","sha":"783f287fb0ec41359eacc335f0258aaebeb377d1"}},"sourceBranch":"main","suggestedTargetBranches":["9.2","8.19","9.1"],"targetPullRequestStates":[{"branch":"9.2","label":"v9.2.0","branchLabelMappingKey":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"},{"branch":"main","label":"v9.3.0","branchLabelMappingKey":"^v9.3.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/242036","number":242036,"mergeCommit":{"message":"[Controls] Fix deselecting (blank) option from options list (#242036)\n\n## Summary\n\nCloses https://github.com/elastic/kibana/issues/241750\n\nFixes an error with deselecting a `(blank)` option from an options list.\n\nThe same error when *selecting* the option was fixed in\nhttps://github.com//pull/239791, but we missed fixing it\nfor deselection.\n\n\n### Checklist\n\n- [x] [Unit or functional\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\nwere updated or added to match the most common scenarios","sha":"783f287fb0ec41359eacc335f0258aaebeb377d1"}},{"branch":"8.19","label":"v8.19.7","branchLabelMappingKey":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"},{"branch":"9.1","label":"v9.1.7","branchLabelMappingKey":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"}]}] BACKPORT--> Co-authored-by: Zac Xeper <[email protected]>
1 parent 28e490e commit ea15248

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)