Skip to content

[EuiFilePicker] Migrate from class to function component #9495

Closed

Description

@weronikaolejniczak

EuiFilePicker provides a file upload input with drag-and-drop support and visual feedback.

  • File: components/form/file_picker/file_picker.tsx
  • Class size: 262 lines
  • State: promptText, isHoveringDrop
  • Lifecycle:
    • componentDidUpdate

Migration notes:

State-only, no lifecycle. Drag-and-drop handlers and file input refs need conversion to useRef.

Acceptance criteria:

  • Convert to function component with useState and useRef
  • Maintain drag-and-drop behavior
  • All existing tests pass

Activity

  1. mehuljariwala commented on Aug 8, 2026

    @mehuljariwala
    Contributor

    I'd like to take this one — the migration is working locally and I'll open a PR shortly.

    Approach: useState for promptText/isHoveringDrop, useRef for the file input, useFormContext() in place of static contextType, and useEuiMemoizedStyles replacing the withEuiStylesMemoizer HOC (so the EuiFilePickerClass export goes away — it isn't re-exported from index.ts, so this stays internal-only).

    Two notes from working through it:

    1. The description lists Lifecycle: None, but there is a componentDidUpdate that re-derives promptText when the files prop changes (the file is 382 lines now, not 262). I've preserved the exact semantics with a useEffect plus a previous-value ref so it doesn't also fire on mount — a bare [files] effect would cause a redundant second render in the multi-file case, since getPromptTextFromFileList returns a fresh EuiI18n element each call.

    2. I also swapped htmlIdGenerator()() for useGeneratedHtmlId() here, which clears one more function-component usage tracked in [SSR] Replace htmlIdGenerator usages with useGeneratedHtmlId in all function components #7093.

    Verification so far: all 13 existing file_picker tests pass with the snapshot unchanged, and the wider src/components/form suite (38 suites / 382 tests / 222 snapshots) is green, along with tsc --noEmit and ESLint.

  2. weronikaolejniczak commented on Aug 10, 2026

    @weronikaolejniczak
    ContributorAuthor

    @mehuljariwala ah, all these were generated with an agent so there might be these small mistakes. Thanks for raising it, I updated in the description. Also, thank you for considering useGeneratedHtmlId() 🙏🏻 This is very important for us to move forward to SSR-friendly EUI.

  3. added
    help wanted
    low hanging fruit
    on Aug 10, 2026
  4. github-actions commented on Aug 10, 2026

    @github-actions

    👋 Thank you for your suggestion or request! While the EUI team agrees that it's valid, it's unlikely that we will prioritize this issue on our roadmap. We'll leave the issue open if you or anyone else in the community wants to implement it by contributing to EUI. If not, this issue will auto close in one year.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    help wantedlow hanging fruit

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions