Repository navigation
[EuiFilePicker] Migrate from class to function component - #9879
weronikaolejniczak merged 5 commits into
Conversation
|
💚 CLA has been signed |
|
👋 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? |
|
👋 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? |
|
buildkite test this |
There was a problem hiding this comment.
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 thefiles-driven prompt text update semantics aligned with the priorcomponentDidUpdate. - Replaced legacy patterns with hook equivalents (
useFormContext,useEuiMemoizedStyles,useGeneratedHtmlId,useEuiI18n) and removed thewithEuiStylesMemoizerHOC/class export. - Kept prompt text state intentionally independent from
filesduring render to preserve the existing “clear whilefilesis 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
left a comment
There was a problem hiding this comment.
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 🙌🏻
Co-authored-by: Weronika Olejniczak <[email protected]>
Co-authored-by: Weronika Olejniczak <[email protected]>
|
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. |
|
@mehuljariwala please be aware we receive contributions only for issues labeled as "help wanted". |
Yes sounds good |
|
@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'.
|
buildkite test this |
|
Thanks for catching both of these, @weronikaolejniczak — and sorry for the noise on the previous pushes. Both are now fixed in
const showDrop = () => !disabled && setIsHoveringDrop(true);
const hideDrop = () => setIsHoveringDrop(false);
Verified locally this time before pushing: the full unit suite passes (5246 tests, 2750 snapshots), plus The last Buildkite runs (#4653 / #7376) were against Happy to add the |
💚 Build Succeeded
History
|
💚 Build Succeeded
History
|
|
Thanks for your contribution @mehuljariwala 🙏🏻 |
Co-authored-by: Weronika Olejniczak <[email protected]>
## 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]>
## 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]>
Summary
What: Migrates
EuiFilePickerfrom a class component to a function component.Why: Closes #9495.
How:
class EuiFilePickerClass extends ComponentFunctionComponent<EuiFilePickerProps>withEuiStylesMemoizerHOC +stylesMemoizerpropuseEuiMemoizedStyles(euiFilePickerStyles)static contextType = FormContextuseFormContext()static defaultPropsfileInputinstance field + callback refuseRef<HTMLInputElement>this.state/setStateuseState×2componentDidUpdateuseEffectkeyed onfileshtmlIdGenerator()()useGeneratedHtmlId()<EuiI18n>render-prop wrapperuseEuiI18n()Two decisions worth flagging for reviewers:
The
fileseffect keeps a previous-value ref. A bareuseEffect(..., [files])also runs on mount, which would trigger a redundant second render in the multi-file case, sincegetPromptTextFromFileListreturns a freshEuiI18nelement that can never reference-compare equal. The ref guard makes the effect fire only on an actual prop change, matchingcomponentDidUpdateexactly.promptTextis deliberately not derived during render. The existing testclears file name when clear button is clickedclears the input while thefilesprop is still set, so re-deriving from props on every render would resurrect the filename and break it.The
EuiFilePickerClassexport is removed along with the HOC. It was never re-exported fromindex.ts(onlyEuiFilePickerandEuiFilePickerPropsare public), so this stays internal-only.I also swapped
htmlIdGenerator()()foruseGeneratedHtmlId()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.
EuiFilePickerScreenshots
No visual changes — rendered markup is identical, and the existing snapshot passes unmodified.
Impact Assessment
Impact level: 🟢 None
Release Readiness
Documentation— no doc changes; behavior and API are unchangedFigma— no design changesMigration guide— no breaking or visual changesAdoption plan— not a new featureChangelog: this is an internal implementation change with no consumer-facing impact, so per the changelog guide I believe
skip-changelogapplies 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:
initialPromptText, and callsonChangewithnull.disabled.filesprop still controls displayed state, including when the prop reference changes.fullWidthstill inherits from a wrapping<EuiForm fullWidth>.isLoading,isInvalid,compressedanddisplay="default"render as before.Checklist before marking Ready for Review
QA: Tested docs changes— no docs changesfile_pickertests with the snapshot unmodified, and the fullsrc/components/formsuite (38 suites / 382 tests / 222 snapshots) green, plustsc --noEmitand ESLint clean. No new tests added: the migration is behavior-preserving and the existing suite already covers the state and clear-button paths.skip-changelogBreaking changes: label— none