Skip to content

Commit 6f82a4e

Browse files
[8.19] [Controls] Fix error when selecting "(blank)" value in options list (#239791) (#239812)
# Backport This will backport the following commits from `main` to `8.19`: - [[Controls] Fix error when selecting "(blank)" value in options list (#239791)](#239791) <!--- Backport version: 9.6.6 --> ### Questions ? Please refer to the [Backport tool documentation](https://github.com/sorenlouv/backport) <!--BACKPORT [{"author":{"name":"Nick Peihl","email":"nick.peihl@elastic.co"},"sourceCommit":{"committedDate":"2025-10-20T19:52:09Z","message":"[Controls] Fix error when selecting \"(blank)\" value in options list (#239791)\n\nFixes #239735\n\n## Summary\n\nFixes an error in the Options list control when selecting a \"(blank)\"\nvalue.\n\nMakes the boolean check for key more explicit using [loose equality to\ncheck if the key is null or\nundefined](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Equality_comparisons_and_sameness#loose_equality_using).\nWithout this, selecting a `\"\"` value causes the control to error.","sha":"36758259f660d3d512b5f90ee3f5dadd7c3114b9","branchLabelMapping":{"^v9.3.0$":"main","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:fix","Feature:Input Control","Team:Presentation","backport:version","v9.2.0","v9.3.0","v9.1.6","v8.19.6"],"title":"[Controls] Fix error when selecting \"(blank)\" value in options list","number":239791,"url":"https://github.com/elastic/kibana/pull/239791","mergeCommit":{"message":"[Controls] Fix error when selecting \"(blank)\" value in options list (#239791)\n\nFixes #239735\n\n## Summary\n\nFixes an error in the Options list control when selecting a \"(blank)\"\nvalue.\n\nMakes the boolean check for key more explicit using [loose equality to\ncheck if the key is null or\nundefined](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Equality_comparisons_and_sameness#loose_equality_using).\nWithout this, selecting a `\"\"` value causes the control to error.","sha":"36758259f660d3d512b5f90ee3f5dadd7c3114b9"}},"sourceBranch":"main","suggestedTargetBranches":["9.2","9.1","8.19"],"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/239791","number":239791,"mergeCommit":{"message":"[Controls] Fix error when selecting \"(blank)\" value in options list (#239791)\n\nFixes #239735\n\n## Summary\n\nFixes an error in the Options list control when selecting a \"(blank)\"\nvalue.\n\nMakes the boolean check for key more explicit using [loose equality to\ncheck if the key is null or\nundefined](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Equality_comparisons_and_sameness#loose_equality_using).\nWithout this, selecting a `\"\"` value causes the control to error.","sha":"36758259f660d3d512b5f90ee3f5dadd7c3114b9"}},{"branch":"9.1","label":"v9.1.6","branchLabelMappingKey":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"},{"branch":"8.19","label":"v8.19.6","branchLabelMappingKey":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"}]}] BACKPORT--> Co-authored-by: Nick Peihl <nick.peihl@elastic.co>
1 parent ee21ba1 commit 6f82a4e

2 files changed

Lines changed: 30 additions & 5 deletions

File tree

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

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -237,10 +237,35 @@ describe('Options List Control Api', () => {
237237
{ value: 'woof', docCount: 10 },
238238
{ value: 'bark', docCount: 15 },
239239
{ value: 'meow', docCount: 12 },
240+
{ value: '', docCount: 20 },
240241
],
241242
});
242243
});
243244

245+
test('renders a "(blank)" option', async () => {
246+
const { Component } = await factory.buildControl({
247+
initialState: {
248+
dataViewId: 'myDataViewId',
249+
fieldName: 'myFieldName',
250+
existsSelected: true,
251+
},
252+
finalizeApi,
253+
uuid,
254+
controlGroupApi,
255+
});
256+
257+
const control = render(<Component className={'controlPanel'} />);
258+
await userEvent.click(control.getByTestId(`optionsList-control-${uuid}`));
259+
await waitFor(() => {
260+
expect(control.getAllByRole('option').length).toBe(5);
261+
});
262+
const option = control.getByTestId('optionsList-control-selection-');
263+
await userEvent.click(option);
264+
await waitFor(async () => {
265+
expect(option).toBeChecked();
266+
});
267+
});
268+
244269
test('clicking another option unselects "Exists"', async () => {
245270
const { Component } = await factory.buildControl({
246271
initialState: {
@@ -256,7 +281,7 @@ describe('Options List Control Api', () => {
256281
const control = render(<Component className={'controlPanel'} />);
257282
await userEvent.click(control.getByTestId(`optionsList-control-${uuid}`));
258283
await waitFor(() => {
259-
expect(control.getAllByRole('option').length).toBe(4);
284+
expect(control.getAllByRole('option').length).toBe(5);
260285
});
261286

262287
expect(control.getByTestId('optionsList-control-selection-exists')).toBeChecked();
@@ -285,7 +310,7 @@ describe('Options List Control Api', () => {
285310
const control = render(<Component className={'controlPanel'} />);
286311
await userEvent.click(control.getByTestId(`optionsList-control-${uuid}`));
287312
await waitFor(() => {
288-
expect(control.getAllByRole('option').length).toEqual(4);
313+
expect(control.getAllByRole('option').length).toEqual(5);
289314
});
290315

291316
const existsOption = control.getByTestId('optionsList-control-selection-exists');
@@ -319,7 +344,7 @@ describe('Options List Control Api', () => {
319344
const control = render(<Component className={'controlPanel'} />);
320345
await userEvent.click(control.getByTestId(`optionsList-control-${uuid}`));
321346
await waitFor(() => {
322-
expect(control.getAllByRole('option').length).toEqual(4);
347+
expect(control.getAllByRole('option').length).toEqual(5);
323348
});
324349
await userEvent.click(control.getByTestId('optionsList-control-show-only-selected'));
325350

@@ -381,7 +406,7 @@ describe('Options List Control Api', () => {
381406

382407
await userEvent.click(control.getByTestId(`optionsList-control-${uuid}`));
383408
await waitFor(() => {
384-
expect(control.getAllByRole('option').length).toEqual(4);
409+
expect(control.getAllByRole('option').length).toEqual(5);
385410
});
386411
expect(control.getByTestId('optionsList-control-selection-woof')).toBeChecked();
387412
expect(control.queryByTestId('optionsList-control-selection-bark')).not.toBeChecked();

‎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
@@ -373,7 +373,7 @@ export const getOptionsListControlFactory = (): DataControlFactory<
373373
},
374374
makeSelection: (key: string | undefined, showOnlySelected: boolean) => {
375375
const field = api.field$.getValue();
376-
if (!key || !field) {
376+
if (key == null || !field) {
377377
api.setBlockingError(
378378
new Error(OptionsListStrings.control.getInvalidSelectionMessage())
379379
);

0 commit comments

Comments
 (0)