From ac3396eec94e3c683fc3216b42a4749f93d2b20a Mon Sep 17 00:00:00 2001 From: Cee Chen <549407+cee-chen@users.noreply.github.com> Date: Mon, 25 Mar 2024 12:57:03 -0700 Subject: [PATCH] [EuiSelectable] Fix non-virtualized lists causing Jest errors (#7618) --- changelogs/upcoming/7618.md | 3 +++ src/components/selectable/selectable_list/selectable_list.tsx | 4 +++- 2 files changed, 6 insertions(+), 1 deletion(-) create mode 100644 changelogs/upcoming/7618.md diff --git a/changelogs/upcoming/7618.md b/changelogs/upcoming/7618.md new file mode 100644 index 00000000000..3608623172a --- /dev/null +++ b/changelogs/upcoming/7618.md @@ -0,0 +1,3 @@ +**Bug fixes** + +- Fixed unvirtualized `EuiSelectable`s to not cause Jest/jsdom errors on active option change diff --git a/src/components/selectable/selectable_list/selectable_list.tsx b/src/components/selectable/selectable_list/selectable_list.tsx index 802c91dc77a..5f9a4a540b7 100644 --- a/src/components/selectable/selectable_list/selectable_list.tsx +++ b/src/components/selectable/selectable_list/selectable_list.tsx @@ -264,7 +264,9 @@ export class EuiSelectableList extends Component< const activeOptionId = `#${makeOptionId(activeOptionIndex)}`; const activeOptionEl = this.listBoxRef?.querySelector(activeOptionId); if (activeOptionEl) { - activeOptionEl.scrollIntoView({ block: 'nearest' }); + // TODO: we can remove scrollIntoView's conditional chaining once jsdom stubs it + // @see https://github.com/jsdom/jsdom/issues/1695 + activeOptionEl.scrollIntoView?.({ block: 'nearest' }); } } }