Skip to content

[EuiSuperSelect] Migrate to function component - #9972

Merged
weronikaolejniczak merged 8 commits into
elastic:mainfrom
mehuljariwala:fix/9485-super-select-hooks
Sep 8, 2026
Merged

weronikaolejniczak merged 8 commits into
elastic:mainfrom
mehuljariwala:fix/9485-super-select-hooks

Conversation

@mehuljariwala

@mehuljariwala mehuljariwala commented Aug 31, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • Converts EuiSuperSelect from a generic class component to a generic function component using useState, useRef, and useEffect.
  • Preserves the existing public props, default values, controlled isOpen behavior, option focus order, disabled-option skipping, and control-button focus restoration.
  • Keeps the imperative openPopover() / closePopover() API available on the component ref via forwardRef and useImperativeHandle, typed by the new exported EuiSuperSelectRef.
  • Sets the mount guard in an isomorphic layout effect (the EuiPortal pattern) so a fast post-mount interaction can't lose the deferred focus callback.
  • Keeps the screen-reader description ID stable for the lifetime of the component.
  • Updates the type-only test directives to match the more precise JSX diagnostic locations produced by a generic function component; the invalid generic values remain rejected.

Fixes #9485.

API Changes

component / parent prop / child change description
EuiSuperSelect ref Changed The ref is no longer the class instance. It is now an EuiSuperSelectRef object exposing openPopover() and closePopover(). Runtime calls are unchanged; TS consumers typing the ref as EuiSuperSelect<T> need to switch to EuiSuperSelectRef.
EuiSuperSelect EuiSuperSelectRef Added New exported type for the imperative ref handle.
EuiSuperSelect All props None Props, defaults, DOM structure, and behavior are unchanged.

Known downstream update (type-only) in Kibana:

  • alerts_solution_selector.tsx — forwardRef<EuiSuperSelect<RuleTypeSolution>, …> → forwardRef<EuiSuperSelectRef, …>
  • config_editor_content.tsx — useRef<EuiSuperSelect<RuleTypeSolution>>(null) → useRef<EuiSuperSelectRef>(null)

Screenshots

Not applicable. This is an implementation-only refactor with no intended visual or DOM changes; all 13 focused snapshots remain unchanged.

Impact Assessment

  • 🔴 Breaking changes — The ref type changed from the class instance to EuiSuperSelectRef. Runtime usage (ref.current.openPopover()) is unaffected.
  • 💅 Visual changes — None intended.
  • 🧪 Test impact — Type-only @ts-expect-error comments moved to the prop diagnostics emitted for a function component. Added a Jest test for the imperative ref. Runtime assertions and snapshots are otherwise unchanged.
  • 🔧 Hard to integrate — Two type-only lines in Kibana, listed above.

Impact level: 🟡 Medium
Kibana PR: elastic/kibana#288940

Release Readiness

QA instructions for reviewer

From packages/eui:

yarn build:workspaces
yarn test-unit super_select --runInBand
yarn test-cypress --spec src/components/form/super_select/super_select.spec.tsx
yarn lint

The Cypress spec checks the user-visible behaviors most at risk in this migration:

  • Open the popover with Arrow Up, Arrow Down, Space, and Enter.
  • Select the focused option with Enter and Tab.
  • Close with Escape without changing the selection.
  • Confirm arrow navigation stops at the first and last option.
  • Confirm disabled options are skipped.
  • Confirm form-row focus styling remains active while navigating the dropdown.

Local validation performed with Node 24.19.0 and React 18:

  • Focused Jest: 2 suites, 33 tests, and 13 snapshots passed.
  • Focused Cypress: 6 tests passed in headless Chrome with no retries.
  • Package TypeScript: passed.
  • ESLint on the changed files: zero errors (repository-wide existing warnings remain).
  • Pre-push yarn test-staged: 369 suites, 5,318 tests, and 2,759 snapshots passed; 1 suite and 21 tests were skipped by the repository configuration.

Checklist before marking Ready for Review

  • Filled out all sections above
  • QA: Covered keyboard-only behavior in headless Chrome through the existing Cypress component suite. No visual output changed.
  • QA: CodeSandbox and Kibana testing are not needed for this internal refactor with unchanged props, DOM snapshots, and browser behavior.
  • QA: No documentation changes.
  • Tests: Updated the generic typing assertions, added ref coverage, and ran the existing Jest and Cypress coverage for EuiSuperSelect. No VRT was run locally because there is no visual change.
  • Changelog: Added changelogs/upcoming/9972.md documenting the ref type change.
  • Breaking changes: Ref type change documented above and in the changelog.

Reviewer checklist

  • Approved Impact Assessment — Acceptable to merge given the consumer impact.
  • Approved Release Readiness — Docs, Figma, and migration info are sufficient to ship.

@mehuljariwala
mehuljariwala requested a review from a team as a code owner August 31, 2026 06:16
@github-actions

Copy link
Copy Markdown

👋 Since this is a community submitted pull request, a Buildkite build has not been started automatically. Would an Elastic organization member please verify the contents of this pull request and kick off a build manually?

@github-actions github-actions Bot added the community contribution (Don't delete - used for automation) label Aug 31, 2026
@weronikaolejniczak

Copy link
Copy Markdown
Contributor

buildkite test this

@weronikaolejniczak weronikaolejniczak added the skip-changelog Use on PRs to skip changelog requirement (Don't delete - used for automation) label Sep 2, 2026
@weronikaolejniczak
weronikaolejniczak requested a lite review from Copilot September 2, 2026 13:47

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

The new mount guard sets isMounted only in useEffect, which can prevent initial option focusing/onFocus in fast post-mount interactions and risks a behavioral regression.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Pull request overview

Refactors EuiSuperSelect from a generic class component to a generic function component using React hooks, aiming to preserve existing API and keyboard/focus behavior while modernizing the implementation.

Changes:

  • Migrated EuiSuperSelect to a hook-based function component (useState, useRef, useEffect) while keeping public props and DOM structure stable.
  • Preserved focus management behaviors (initial option focus, disabled-option skipping, focus restoration) with mount guarding for async RAF focus.
  • Updated type-only tests to align @ts-expect-error directives with JSX prop-level diagnostics.
File summaries
File Description
packages/eui/src/components/form/super_select/super_select.tsx Reimplements EuiSuperSelect as a function component with hook-based state, refs, and lifecycle equivalents.
packages/eui/src/components/form/super_select/super_select.test.tsx Adjusts TS typing assertion comments to match the new JSX error locations.
Review details
  • Files reviewed: 2/2 changed files
  • Comments generated: 1
  • Review effort level: Lite

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@weronikaolejniczak weronikaolejniczak left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The overall migration looks fine but we will break Kibana with this update if we don't forwardRef and useImperativeHandle({ openPopover, closePopover }). See https://github.com/elastic/kibana/blob/main/x-pack/platform/packages/shared/response-ops/alerts-filters-form/components/alerts_solution_selector.tsx

@mehuljariwala

Copy link
Copy Markdown
Contributor Author

Thanks @weronikaolejniczak — all three review points are addressed in 097ff56.

forwardRef + useImperativeHandle

EuiSuperSelect is now a forwardRef component that exposes openPopover() and closePopover() through a new exported EuiSuperSelectRef type. Both are wrapped in useCallback so the imperative handle only changes when its inputs do.

Since forwardRef erases the generic, the export is cast back to a generic signature — the same approach EuiFlyoutComponent already uses — so EuiSuperSelect<MyType> prop inference is unaffected:

export const EuiSuperSelect = forwardRef(EuiSuperSelectInner) as <T = string>(
  props: EuiSuperSelectProps<T> & { ref?: Ref<EuiSuperSelectRef> }
) => ReactElement;

Added a Jest test that opens and closes the listbox through the ref.

Kibana impact

The runtime call in config_editor_content.tsx (solutionSelectorRef.current?.openPopover()) keeps working. One type-only update is still needed there, because EuiSuperSelect is no longer a class and can't be used as a type:

  • alerts_solution_selector.tsx — forwardRef<EuiSuperSelect<RuleTypeSolution>, …> → forwardRef<EuiSuperSelectRef, …>
  • config_editor_content.tsx — useRef<EuiSuperSelect<RuleTypeSolution>>(null) → useRef<EuiSuperSelectRef>(null)

That matches what EuiFilePicker did in #9879 with EuiFilePickerRef, which Kibana already consumes in several places. I added changelogs/upcoming/9972.md under Breaking changes so the ref shape change is documented — happy to drop it back to skip-changelog if you'd prefer.

If you'd rather Kibana need no change at all, I can instead merge an interface EuiSuperSelect<T> declaration alongside the const so the old type reference keeps resolving. Let me know which you prefer.

Other two comments

Replied inline — RenderWithEuiStylesMemoizer is now useEuiMemoizedStyles, and the mount guard uses an isomorphic layout effect.

Validation on this branch (Node 24.19.0, React 18)

  • yarn test-unit super_select — 2 suites, 33 tests, 13 snapshots passed
  • yarn test-cypress --spec src/components/form/super_select/super_select.spec.tsx — 6/6 passed, no retries
  • Pre-push test-staged — 369 suites, 5,318 tests, 2,759 snapshots passed (1 suite / 21 tests skipped by repo config)
  • tsc --noEmit and eslint clean for the changed files

@weronikaolejniczak weronikaolejniczak added breaking change PRs with breaking changes. (Don't delete - used for automation) and removed skip-changelog Use on PRs to skip changelog requirement (Don't delete - used for automation) labels Sep 3, 2026
@github-actions

github-actions Bot commented Sep 3, 2026

Copy link
Copy Markdown

This PR contains breaking changes. The opener of this pull request is asked to perform the following due diligence steps below, to assist EUI in our next Kibana upgrade:

  • If this PR contains prop/API changes:
    • Search through Kibana for <EuiComponent usages (example search)
    • In the PR description or in a PR comment, include a count or list with the number of component usages in Kibana that will need to be updated (if that amount is "none", include that information as well)
  • If this PR contains CSS changes:
    • Search through Kibana for the changed EUI selectors, e.g. .euiComponent (example search)
    • In the PR description or in a PR comment, include a count or list with the number of custom CSS overrides in Kibana that will need to be updated (if that amount is "none", include that information as well)
  • 🔍 Tip: When searching through Kibana, consider excluding **/target, **/*.snap, **/*.storyshot files to reduce noise and only look at source code usages
  • ⚠️ For extremely risky changes, the EUI team should potentially consider the following precautions:
    • Using a pre-release release candidate to test Kibana CI ahead of time
    • Using kibana-a-la-carte for manual QA, and to give other Kibana teams a staging server to quickly test against

weronikaolejniczak added a commit to weronikaolejniczak/kibana that referenced this pull request Sep 3, 2026
Packed from mehuljariwala/eui#fix/9485-super-select-hooks (elastic/eui#9972) so Kibana CI can typecheck EuiSuperSelectRef before publish. Drop this commit from the real version bump.

Co-authored-by: Cursor <[email protected]>
weronikaolejniczak added a commit to weronikaolejniczak/kibana that referenced this pull request Sep 3, 2026
Packed from mehuljariwala/eui#fix/9485-super-select-hooks (elastic/eui#9972) so Kibana CI can typecheck EuiSuperSelectRef before publish. Drop this commit from the real version bump.

Co-authored-by: Cursor <[email protected]>
@weronikaolejniczak

Copy link
Copy Markdown
Contributor

buildkite test this

@weronikaolejniczak weronikaolejniczak left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the contribution @mehuljariwala 🙌🏻 The way you implemented it is great! I'll take it from here and add a small commit to the PR.

weronikaolejniczak added a commit to weronikaolejniczak/kibana that referenced this pull request Sep 4, 2026
Packed from mehuljariwala/eui#fix/9485-super-select-hooks (elastic/eui#9972).
Includes 120 i18n mapping for euiTimeWindowButtons.label so types pass against
this tarball. Drop this commit from the real version bump.

Co-authored-by: Cursor <[email protected]>
@weronikaolejniczak

Copy link
Copy Markdown
Contributor

buildkite test this

@infra-vault-gh-plugin-prod

Copy link
Copy Markdown

💚 Build Succeeded

History

@infra-vault-gh-plugin-prod

Copy link
Copy Markdown

💚 Build Succeeded

History

@weronikaolejniczak
weronikaolejniczak merged commit a9cce92 into elastic:main Sep 8, 2026
7 checks passed
eokoneyo added a commit to elastic/kibana that referenced this pull request Sep 17, 2026
## Dependency updates

`@elastic/eui` - v121.0.0 ⏩ v122.0.0
`@elastic/eui-illustrations` - v1.0.2 ⏩ v1.1.0
`@elastic/eui-test-helpers` - v1.6.0 ⏩ v1.7.0

## Changes

- Cherry-picked staged Kibana prep commits from `kibana-prep-commits`:
- #288940 (`1fdf41c`) — type `EuiSuperSelect` refs as
`EuiSuperSelectRef` following the breaking `ref` change in
elastic/eui#9972
- #290240 (`54cae3c`) — update tests, page objects, the
EUI i18n mapping, and translation files for the removed
`euiSelectableListItem.checkedOption` screen-reader text
(elastic/eui#9850)
- Synced EUI i18n tokens: added `euiKeyboardShortcuts.cmd`,
`euiKeyboardShortcuts.copyTitle`, and
`euiKeyboardShortcuts.copyDescription` to `i18n_eui_mapping.tsx` and
updated the `i18n_service` snapshot

## Package updates

### `@elastic/eui`
[v122.0.0](https://github.com/elastic/eui/blob/main/packages/eui/changelogs/CHANGELOG_2026.md)

- Added Ctrl/Cmd+C support on `EuiDataGrid` to copy the focused cell
value when no text is selected
([#9995](elastic/eui#9995))

**Bug fixes**

- Fixed `EuiDataGrid` copy/paste shifting body rows one column right of
the headers when control columns were present
([#9954](elastic/eui#9954))

**Breaking changes**

- Changed the `ref` of `EuiSuperSelect` from the class instance to an
`EuiSuperSelectRef` object, which exposes `openPopover()` and
`closePopover()` ([#9972](elastic/eui#9972))

**Accessibility**

- Improved the accessibility of `EuiSelectable` by removing redundant
"Checked option." screen-reader text (checked state is already conveyed
via `aria-checked`/`aria-selected`)
([#9850](elastic/eui#9850))
- Improved the accessibility of `EuiSelectable` and `EuiComboBox` by
moving the `title` attribute to the inner text element, preventing
duplicate screen-reader announcements of option names
([#9850](elastic/eui#9850))
### `@elastic/eui-illustrations`
[v1.1.0](https://github.com/elastic/eui/blob/main/packages/illustrations/changelogs/CHANGELOG_2026.md)

- Added `attachments`, `detection`, `discovery`, `fieldExtraction`,
`generatePreview`, `knowledgeIndicator`, `noData`, `processorsError`,
`processorsLoading`, and `processorsPreview` illustrations
([#10001](elastic/eui#10001))
### `@elastic/eui-test-helpers`
[v1.7.0](https://github.com/elastic/eui/blob/main/packages/test-helpers/changelogs/CHANGELOG_2026.md)

- Added `EuiTreeViewObject`, a Playwright Component Object for
`EuiTreeView` ([#10025](elastic/eui#10025))
- Added `EuiToolTipObject`, a Playwright Component Object for
`EuiToolTip` ([#10026](elastic/eui#10026))
- Added `EuiContextMenuObject`, a Playwright Component Object for
`EuiContextMenu` ([#10013](elastic/eui#10013))
- Added `EuiColorPickerObject`, a Playwright Component Object for
`EuiColorPicker` ([#10020](elastic/eui#10020))

**Bug fixes**

- Fixed Component Objects not finding components whose `data-test-subj`
holds several space-separated tokens, such as `EuiColorPicker`. The root
now matches one token, following Kibana's `data-test-subj` convention
([#10015](elastic/eui#10015))

---------

Co-authored-by: Weronika Olejniczak <[email protected]>
Co-authored-by: Cursor <[email protected]>
Co-authored-by: Alexey Antonov <[email protected]>
Co-authored-by: Lene Gadewoll <[email protected]>
Co-authored-by: Elastic Machine <[email protected]>
ppisljar pushed a commit to ppisljar/kibana that referenced this pull request Sep 21, 2026
## Dependency updates

`@elastic/eui` - v121.0.0 ⏩ v122.0.0
`@elastic/eui-illustrations` - v1.0.2 ⏩ v1.1.0
`@elastic/eui-test-helpers` - v1.6.0 ⏩ v1.7.0

## Changes

- Cherry-picked staged Kibana prep commits from `kibana-prep-commits`:
- elastic#288940 (`1fdf41c`) — type `EuiSuperSelect` refs as
`EuiSuperSelectRef` following the breaking `ref` change in
elastic/eui#9972
- elastic#290240 (`54cae3c`) — update tests, page objects, the
EUI i18n mapping, and translation files for the removed
`euiSelectableListItem.checkedOption` screen-reader text
(elastic/eui#9850)
- Synced EUI i18n tokens: added `euiKeyboardShortcuts.cmd`,
`euiKeyboardShortcuts.copyTitle`, and
`euiKeyboardShortcuts.copyDescription` to `i18n_eui_mapping.tsx` and
updated the `i18n_service` snapshot

## Package updates

### `@elastic/eui`
[v122.0.0](https://github.com/elastic/eui/blob/main/packages/eui/changelogs/CHANGELOG_2026.md)

- Added Ctrl/Cmd+C support on `EuiDataGrid` to copy the focused cell
value when no text is selected
([elastic#9995](elastic/eui#9995))

**Bug fixes**

- Fixed `EuiDataGrid` copy/paste shifting body rows one column right of
the headers when control columns were present
([elastic#9954](elastic/eui#9954))

**Breaking changes**

- Changed the `ref` of `EuiSuperSelect` from the class instance to an
`EuiSuperSelectRef` object, which exposes `openPopover()` and
`closePopover()` ([elastic#9972](elastic/eui#9972))

**Accessibility**

- Improved the accessibility of `EuiSelectable` by removing redundant
"Checked option." screen-reader text (checked state is already conveyed
via `aria-checked`/`aria-selected`)
([elastic#9850](elastic/eui#9850))
- Improved the accessibility of `EuiSelectable` and `EuiComboBox` by
moving the `title` attribute to the inner text element, preventing
duplicate screen-reader announcements of option names
([elastic#9850](elastic/eui#9850))
### `@elastic/eui-illustrations`
[v1.1.0](https://github.com/elastic/eui/blob/main/packages/illustrations/changelogs/CHANGELOG_2026.md)

- Added `attachments`, `detection`, `discovery`, `fieldExtraction`,
`generatePreview`, `knowledgeIndicator`, `noData`, `processorsError`,
`processorsLoading`, and `processorsPreview` illustrations
([elastic#10001](elastic/eui#10001))
### `@elastic/eui-test-helpers`
[v1.7.0](https://github.com/elastic/eui/blob/main/packages/test-helpers/changelogs/CHANGELOG_2026.md)

- Added `EuiTreeViewObject`, a Playwright Component Object for
`EuiTreeView` ([elastic#10025](elastic/eui#10025))
- Added `EuiToolTipObject`, a Playwright Component Object for
`EuiToolTip` ([elastic#10026](elastic/eui#10026))
- Added `EuiContextMenuObject`, a Playwright Component Object for
`EuiContextMenu` ([elastic#10013](elastic/eui#10013))
- Added `EuiColorPickerObject`, a Playwright Component Object for
`EuiColorPicker` ([elastic#10020](elastic/eui#10020))

**Bug fixes**

- Fixed Component Objects not finding components whose `data-test-subj`
holds several space-separated tokens, such as `EuiColorPicker`. The root
now matches one token, following Kibana's `data-test-subj` convention
([elastic#10015](elastic/eui#10015))

---------

Co-authored-by: Weronika Olejniczak <[email protected]>
Co-authored-by: Cursor <[email protected]>
Co-authored-by: Alexey Antonov <[email protected]>
Co-authored-by: Lene Gadewoll <[email protected]>
Co-authored-by: Elastic Machine <[email protected]>
weronikaolejniczak added a commit to boriskirov/eui that referenced this pull request Nov 11, 2026
Co-authored-by: Weronika Olejniczak <[email protected]>
Co-authored-by: Weronika Olejniczak <[email protected]>
Co-authored-by: Cursor <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

breaking change PRs with breaking changes. (Don't delete - used for automation) community contribution (Don't delete - used for automation)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[EuiSuperSelect] Migrate from class to function component

3 participants