eui icon indicating copy to clipboard operation
eui copied to clipboard

[EuiDataGridColumnResizer] Migrate from class to function component

Open ragini-pandey opened this issue 6 months ago โ€ข 1 comments

Summary

What: Migrates EuiDataGridColumnResizer from a class component to a function component using useState, useCallback, and useRef.

Why: Closes #9470 โ€” part of the class component refactoring meta issue.

How:

  • initialX is now a useRef (no state needed โ€” it doesn't affect rendering) with synchronous mutation in onMouseDown, fixing stale-closure issues
  • offset uses both useState (for re-renders) and a useRef (for synchronous access in onMouseUp)
  • All prop refs (columnWidth, columnId, setColumnWidth) are kept in sync via direct assignment on each render (safe outside effects), so event listeners always read the latest prop values without being re-registered
  • Event handlers are stable useCallbacks with no deps (everything accessed via refs)
  • EuiDataGridColumnResizerState interface removed from data_grid_types.ts (no longer needed)

Test updates:

  • column_resizer.test.tsx: Replaced class-ref-based tests (classRef.onMouseDown(...)) with DOM event dispatch. Since pageX is a read-only computed property on MouseEvent, events use Object.defineProperty to set it
  • data_grid.test.tsx: Updated resizeColumn helper to use Enzyme .simulate() + window event dispatch instead of .instance()

API Changes

component / parent prop / child change description
EuiDataGridColumnResizerState โ€” Removed Internal type no longer needed; class state replaced by useRef/useState

Screenshots

N/A โ€” internal refactor with no visual changes.

Before After
Class component Function component

Impact Assessment

  • [ ] ๐Ÿ”ด Breaking changes โ€” EuiDataGridColumnResizerState was exported but only used internally; its removal is a technically breaking API change for anyone who imported it directly (unlikely in practice)
  • [x] ๐Ÿ’… Visual changes โ€” None
  • [x] ๐Ÿงช Test impact โ€” Tests updated; all pass
  • [x] ๐Ÿ”ง Hard to integrate โ€” None expected

Impact level: ๐ŸŸข Low

Release Readiness

  • ~~Documentation: N/A~~
  • ~~Figma: N/A~~
  • ~~Migration guide: N/A (internal type removal)~~
  • ~~Adoption plan: N/A~~

QA instructions for reviewer

  • Open any DataGrid story in Storybook that has resizable columns
  • [ ] Confirm column resize by drag still works correctly
  • [ ] Confirm the resize cursor appears during drag
  • [ ] Confirm the column snaps to minimum width (40px) when dragged far left
  • [ ] Confirm the DragOverlay (cursor lock) activates during drag

Checklist before marking Ready for Review

  • [x] 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
  • [x] Tests: Updated Jest tests
  • [x] Changelog: Added changelog entry
  • [ ] Breaking changes: N/A

ragini-pandey avatar May 27 '26 19:05 ragini-pandey

๐Ÿ‘‹ 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[bot] avatar May 27 '26 19:05 github-actions[bot]