Skip to content

[EuiFilePicker] Migrate from class to function component - #9879

Merged
weronikaolejniczak merged 5 commits into
elastic:mainfrom
mehuljariwala:migrate-file-picker-function-component
Aug 11, 2026
Merged

weronikaolejniczak merged 5 commits into
elastic:mainfrom
mehuljariwala:migrate-file-picker-function-component

Conversation

@mehuljariwala

@mehuljariwala mehuljariwala commented Aug 8, 2026 •

Copy link
Copy Markdown
Contributor

Summary

What: Migrates EuiFilePicker from a class component to a function component.

Why: Closes #9495.

How:

Before After
class EuiFilePickerClass extends Component FunctionComponent<EuiFilePickerProps>
withEuiStylesMemoizer HOC + stylesMemoizer prop useEuiMemoizedStyles(euiFilePickerStyles)
static contextType = FormContext useFormContext()
static defaultProps destructuring defaults
fileInput instance field + callback ref useRef<HTMLInputElement>
this.state / setState useState ×2
componentDidUpdate useEffect keyed on files
htmlIdGenerator()() useGeneratedHtmlId()
<EuiI18n> render-prop wrapper useEuiI18n()

Two decisions worth flagging for reviewers:

  1. The files effect keeps a previous-value ref. A bare useEffect(..., [files]) also runs on mount, which would trigger a redundant second render in the multi-file case, since getPromptTextFromFileList returns a fresh EuiI18n element that can never reference-compare equal. The ref guard makes the effect fire only on an actual prop change, matching componentDidUpdate exactly.

  2. promptText is deliberately not derived during render. The existing test clears file name when clear button is clicked clears the input while the files prop is still set, so re-deriving from props on every render would resurrect the filename and break it.

The EuiFilePickerClass export is removed along with the HOC. It was never re-exported from index.ts (only EuiFilePicker and EuiFilePickerProps are public), so this stays internal-only.

I also swapped htmlIdGenerator()() for useGeneratedHtmlId() while here, which clears one more function-component usage tracked in #7093.

One note on the issue description: it lists the class as 262 lines with Lifecycle: None, but it is currently 382 lines and does have a componentDidUpdate, handled as described above.

API Changes

None — this is an internal refactor.

component / parent prop / child change description
EuiFilePicker — None Internal refactor only; no public API surface changed

Screenshots

No visual changes — rendered markup is identical, and the existing snapshot passes unmodified.

Impact Assessment

  • 🔴 Breaking changes
  • 💅 Visual changes
  • 🧪 Test impact
  • 🔧 Hard to integrate

Impact level: 🟢 None

Release Readiness

  • Documentation — no doc changes; behavior and API are unchanged
  • Figma — no design changes
  • Migration guide — no breaking or visual changes
  • Adoption plan — not a new feature

Changelog: this is an internal implementation change with no consumer-facing impact, so per the changelog guide I believe skip-changelog applies here — matching #9558, #9667 and #9831, which each migrated a component to a function component with no changelog entry. I'm happy to add one if you'd prefer; I can't apply the label myself.

QA instructions for reviewer

Open the EuiFilePicker Storybook stories:

  • Selecting a single file shows its filename in the prompt.
  • Selecting multiple files shows "N files selected".
  • The clear button appears once a file is selected, resets the prompt to initialPromptText, and calls onChange with null.
  • Dragging a file over the input applies the dropping state, and does not when disabled.
  • The files prop still controls displayed state, including when the prop reference changes.
  • fullWidth still inherits from a wrapping <EuiForm fullWidth>.
  • isLoading, isInvalid, compressed and display="default" render as before.

Checklist before marking Ready for Review

  • Filled out all sections above
  • QA: Tested light/dark modes, high contrast, mobile, Chrome/Safari/Edge/Firefox, keyboard-only, screen reader
  • QA: Tested in CodeSandbox and Kibana
  • QA: Tested docs changes — no docs changes
  • Tests: Existing Jest suite passes unchanged — 13 file_picker tests with the snapshot unmodified, and the full src/components/form suite (38 suites / 382 tests / 222 snapshots) green, plus tsc --noEmit and ESLint clean. No new tests added: the migration is behavior-preserving and the existing suite already covers the state and clear-button paths.
  • Changelog: see note above re skip-changelog
  • Breaking changes: label — none

@mehuljariwala
mehuljariwala requested a review from a team as a code owner August 8, 2026 11:02
@cla-checker-service

cla-checker-service Bot commented Aug 8, 2026 •

Copy link
Copy Markdown

💚 CLA has been signed

@github-actions

github-actions Bot commented Aug 8, 2026

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 8, 2026
@mehuljariwala mehuljariwala reopened this Aug 8, 2026
@github-actions

github-actions Bot commented Aug 8, 2026

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?

@weronikaolejniczak
weronikaolejniczak requested a lite review from Copilot August 10, 2026 07:40
@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 Aug 10, 2026

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.

Pull request overview

Migrates EuiFilePicker from a class component to a function component while preserving behavior, markup, and the existing test suite expectations for controlled files display state, clearing, and drag-over styling.

Changes:

  • Converted class lifecycle/state/refs to hooks (useState, useRef, useEffect, useCallback) while keeping the files-driven prompt text update semantics aligned with the prior componentDidUpdate.
  • Replaced legacy patterns with hook equivalents (useFormContext, useEuiMemoizedStyles, useGeneratedHtmlId, useEuiI18n) and removed the withEuiStylesMemoizer HOC/class export.
  • Kept prompt text state intentionally independent from files during render to preserve the existing “clear while files is still set” behavior covered by tests.

💡 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 refactor works great 💪🏻 I didn't notice any regression compared to prod and VRTs pass.

One improvement we could do: add a "MultipleFiles" story that passes the multiple prop or have the control to toggle this in "Playground" story.

Thanks for contributing, @mehuljariwala 🙌🏻

@mehuljariwala

Copy link
Copy Markdown
Contributor Author

Hello @weronikaolejniczak,

Thank you for taking the time to review this. I have a well-defined plan to migrate all the components one by one, which will allow us to maintain a clean codebase and ensure everything remains well-structured and manageable throughout the migration.

@weronikaolejniczak

Copy link
Copy Markdown
Contributor

@mehuljariwala please be aware we receive contributions only for issues labeled as "help wanted".

@mehuljariwala

Copy link
Copy Markdown
Contributor Author

@mehuljariwala please be aware we receive contributions only for issues labeled as "help wanted".

Yes sounds good

@weronikaolejniczak

Copy link
Copy Markdown
Contributor

@mehuljariwala there's a syntax error. I would advise to test your changes properly before pushing. Spin up Storybook, documentation website! 😄

@mehuljariwala

Copy link
Copy Markdown
Contributor Author

@mehuljariwala there's a syntax error. I would advise to test your changes properly before pushing. Spin up Storybook, documentation website! 😄

Yes done thank you @weronikaolejniczak

… style

The showDrop suggestion was applied over the useCallback body, leaving a
stray closing brace and dependency array behind, which broke parsing and
failed every Buildkite build.

Simplify hideDrop to match, and finish the typo fix by renaming the
icon style key itself from 'compresssed' to 'compressed'.
@weronikaolejniczak

Copy link
Copy Markdown
Contributor

buildkite test this

@mehuljariwala

Copy link
Copy Markdown
Contributor Author

Thanks for catching both of these, @weronikaolejniczak — and sorry for the noise on the previous pushes.

Both are now fixed in ccc16fbe:

  1. Syntax error — when I applied your showDrop suggestion it replaced only that line and left the old useCallback closing brace and dependency array behind, which is what broke the website and Storybook builds. Removed those, and simplified hideDrop the same way since you mentioned neither needs memoization:
const showDrop = () => !disabled && setIsHoveringDrop(true);

const hideDrop = () => setIsHoveringDrop(false);
  1. The typo — you were right that I'd only changed the usage. I've now renamed the key itself in file_picker.styles.ts (compresssed → compressed), so the definition and the usage match. It's the only reference to that key in the repo, so nothing else needed updating.

Verified locally this time before pushing: the full unit suite passes (5246 tests, 2750 snapshots), plus tsc --noEmit, eslint and stylelint are all clean.

The last Buildkite runs (#4653 / #7376) were against 3cfeffb8 and finished just before this fix landed, so they don't cover it. Could you kick off another build when you get a chance? 🙏

Happy to add the MultipleFiles story you suggested — just let me know whether you'd prefer it here or as a separate PR.

@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

Copy link
Copy Markdown
Contributor

Thanks for your contribution @mehuljariwala 🙏🏻

@weronikaolejniczak
weronikaolejniczak merged commit 16d27dd into elastic:main Aug 11, 2026
1 check passed
JoseLuisGJ pushed a commit to JoseLuisGJ/eui that referenced this pull request Aug 12, 2026
mgadewoll added a commit to elastic/kibana that referenced this pull request Aug 28, 2026
## Dependency updates

`@elastic/eui` - 119.0.0 ⏩ 119.1.0
`@elastic/eui-test-helpers` - 1.3.0 ⏩ 1.4.0

## Changes

- Updated usages of `EuiFilePickerClass` to `EuiFilePickerRef` after the
migration of `EuiFilePicker` from class to function component

## Package updates

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

- Updated `EuiFlyoutMenu` action icon spacing: `leadingActions` and
`trailingActions` icons are now grouped with a consistent gap between
each icon ([#9887](elastic/eui#9887))
- Updated `EuiFlyoutMenu` back button to show a tooltip with the
previous page title (e.g. "Back to Page 1") when history context is
available ([#9887](elastic/eui#9887))
- Added `cursorDefault`, `logIn`, and `routeSplit` glyphs to `EuiIcon`
([#9885](elastic/eui#9885))
- Updated `EuiSplitButton` to apply redesign style changes
([#9865](elastic/eui#9865))
- Added a development warning to `useGeneratedHtmlId` and
`htmlIdGenerator` when the passed `prefix`/`suffix` contains whitespace,
which generates invalid HTML IDs
([#9868](elastic/eui#9868))
- Updated `EuiButtonGroup`:
([#9862](elastic/eui#9862))
- Added `variant="segmented"` which renders the group as visually
connected control group
- Added `showDividers` prop to optionally render dividers between group
children
- Added `layout` prop to optionally render icon button groups vertically
    - Added `wrap` prop to manually control the group wrapping behavior

**Bug fixes**

- Fixed `EuiDataGrid` header cell actions popover not opening when
pressing Enter on a focused actions button
([#9931](elastic/eui#9931))
- Fixed `EuiFilePicker` losing imperative `ref` support when migrated
from class to function component
([#9879](elastic/eui#9879)). Use
`useRef<EuiFilePickerRef>()` where `useRef<EuiFilePickerClass>()` was
previously used. ([#9930](elastic/eui#9930))
- Fixed `EuiSplitButton` having a wrong `inline-size` when
`textProps={false}` is set on an action button that has `iconType`
([#9917](elastic/eui#9917))

### `@elastic/eui-test-helpers`
[v1.4.0](https://github.com/elastic/eui/blob/main/packages/test-helpers/changelogs/CHANGELOG_2026.md)

- Added `EuiSelectableObject` with `options`, `selectOption(label)` and
`search(term)` ([#9908](elastic/eui#9908))

---------

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: Hannah Mudge <[email protected]>
dej611 pushed a commit to dej611/kibana that referenced this pull request Aug 31, 2026
## Dependency updates

`@elastic/eui` - 119.0.0 ⏩ 119.1.0
`@elastic/eui-test-helpers` - 1.3.0 ⏩ 1.4.0

## Changes

- Updated usages of `EuiFilePickerClass` to `EuiFilePickerRef` after the
migration of `EuiFilePicker` from class to function component

## Package updates

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

- Updated `EuiFlyoutMenu` action icon spacing: `leadingActions` and
`trailingActions` icons are now grouped with a consistent gap between
each icon ([elastic#9887](elastic/eui#9887))
- Updated `EuiFlyoutMenu` back button to show a tooltip with the
previous page title (e.g. "Back to Page 1") when history context is
available ([elastic#9887](elastic/eui#9887))
- Added `cursorDefault`, `logIn`, and `routeSplit` glyphs to `EuiIcon`
([elastic#9885](elastic/eui#9885))
- Updated `EuiSplitButton` to apply redesign style changes
([elastic#9865](elastic/eui#9865))
- Added a development warning to `useGeneratedHtmlId` and
`htmlIdGenerator` when the passed `prefix`/`suffix` contains whitespace,
which generates invalid HTML IDs
([elastic#9868](elastic/eui#9868))
- Updated `EuiButtonGroup`:
([elastic#9862](elastic/eui#9862))
- Added `variant="segmented"` which renders the group as visually
connected control group
- Added `showDividers` prop to optionally render dividers between group
children
- Added `layout` prop to optionally render icon button groups vertically
    - Added `wrap` prop to manually control the group wrapping behavior

**Bug fixes**

- Fixed `EuiDataGrid` header cell actions popover not opening when
pressing Enter on a focused actions button
([elastic#9931](elastic/eui#9931))
- Fixed `EuiFilePicker` losing imperative `ref` support when migrated
from class to function component
([elastic#9879](elastic/eui#9879)). Use
`useRef<EuiFilePickerRef>()` where `useRef<EuiFilePickerClass>()` was
previously used. ([elastic#9930](elastic/eui#9930))
- Fixed `EuiSplitButton` having a wrong `inline-size` when
`textProps={false}` is set on an action button that has `iconType`
([elastic#9917](elastic/eui#9917))

### `@elastic/eui-test-helpers`
[v1.4.0](https://github.com/elastic/eui/blob/main/packages/test-helpers/changelogs/CHANGELOG_2026.md)

- Added `EuiSelectableObject` with `options`, `selectOption(label)` and
`search(term)` ([elastic#9908](elastic/eui#9908))

---------

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: Hannah Mudge <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

community contribution (Don't delete - used for automation) skip-changelog Use on PRs to skip changelog requirement (Don't delete - used for automation)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[EuiFilePicker] Migrate from class to function component

3 participants