eui
eui copied to clipboard
[EuiDataGridColumnResizer] Migrate from class to function component
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:
initialXis now auseRef(no state needed โ it doesn't affect rendering) with synchronous mutation inonMouseDown, fixing stale-closure issuesoffsetuses bothuseState(for re-renders) and auseRef(for synchronous access inonMouseUp)- 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) EuiDataGridColumnResizerStateinterface removed fromdata_grid_types.ts(no longer needed)
Test updates:
column_resizer.test.tsx: Replaced class-ref-based tests (classRef.onMouseDown(...)) with DOM event dispatch. SincepageXis a read-only computed property onMouseEvent, events useObject.definePropertyto set itdata_grid.test.tsx: UpdatedresizeColumnhelper 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 โ
EuiDataGridColumnResizerStatewas 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
๐ 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?