[composite] Collapse grid navigation identity transform#5027
Conversation
commit: |
Bundle size
PerformanceTotal duration: 1,245.03 ms -209.22 ms(-14.4%) | Renders: 50 (+0) | Paint: 1,891.14 ms -293.25 ms(-13.4%)
9 tests within noise — details Check out the code infra dashboard for more information about this PR. |
✅ Deploy Preview for base-ui ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
There was a problem hiding this comment.
Pull request overview
This PR simplifies the grid navigator injected into useListNavigation by removing the unused “cell map” indirection (which is an identity transform for the 1×1 uniform grid used there) and calling getGridNavigatedIndex directly, while preserving the prior out-of-bounds/-1 sentinel behavior.
Changes:
- Refactor
hooks/gridNavigation.tsto callgetGridNavigatedIndexdirectly and translate out-of-bounds results toundefined. - Remove now-unused cell-map helpers/constants imports to improve tree-shaking for grid-combobox consumers.
- Rename a
useListNavigationgrid testdescribelabel to reflect the actual fixture scenario.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| packages/react/src/floating-ui-react/hooks/gridNavigation.ts | Collapses identity cell-map logic into a direct getGridNavigatedIndex call and preserves sentinel behavior via isIndexOutOfListBounds. |
| packages/react/src/floating-ui-react/hooks/useListNavigation.test.tsx | Updates a grid navigation describe block name for clarity/accuracy. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
The injected grid navigator always runs on a uniform 1x1 grid, so the cell-map machinery (createGridCellMap/getGridCellIndexOfCorner/getGridCellIndices) is an identity transform. Collapse it to a direct getGridNavigatedIndex call: lets those helpers tree-shake out of grid-combobox bundles and drops the per-keystroke O(n) getComputedStyle scan. Also rename the stale 'different sizes' grid test (sizes support is gone; the fixture is a uniform multi-column grid).
ca44119 to
77ade07
Compare
Summary
The grid navigator injected into
useListNavigationonly ever operates on a uniform 1×1 grid (sizes are always1×1, packing is never dense), so the cell-map machinery is an identity transform:createGridCellMapreturns[0..n-1], all corners coincide, the recomputed min/max equal the values passed in, and the disabled-index expansion is equivalent to passingdisabledIndicesstraight through.Collapsing it to a single
getGridNavigatedIndexcall:createGridCellMap/getGridCellIndexOfCorner/getGridCellIndicesout of grid-combobox bundles (they remain used by the real multi-cell composite grid navigator ininternals/composite/root);O(n)getComputedStylescan the old min/max recomputation ran on every key;cellMap[...]out-of-bounds behavior viaisIndexOutOfListBounds, so a-1sentinel still surfaces as "no navigation" rather than highlighting index-1.Also renames a stale grid test
describeblock (sizes support is gone; the fixture is a uniform multi-column grid).The
useListNavigationand combobox suites pass; typecheck/eslint clean. Based on currentmaster.