[DataTableToolbar] Fix mobile single-row layout and add compactTrailing - #1790
[DataTableToolbar] Fix mobile single-row layout and add compactTrailing#1790KhushamBansal wants to merge 2 commits into
Conversation
Signed-off-by: KhushamBansal <kbkhushambansal@gmail.com>
📝 WalkthroughWalkthroughThe ChangesDataTableToolbar layout
Estimated code review effort: 3 (Moderate) | ~20 minutes Suggested reviewers: 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
@Uday9909 Could you review this when you get time? |
There was a problem hiding this comment.
@KhushamBansal The fix direction is perfect. Three tighten-ups plus one change that isn't needed.
trailingControlsin DataTableToolbar.tsx:189 has a dead guard: it's only rendered underhasTrailingControls, which already bakes in!compactTrailing, so thecompactTrailing ? null :branch can never fire.- The tests reach three levels deep via
parentElement?.parentElement?.parentElement(test:139, :164). That's testing DOM structure, not behavior, and any wrapper Box breaks them. GiveRightSectionandRightControlsGroupdata-testids and assert on those. The two "grouping" tests assert the same thing, collapse them. - Mobile
nowrap(line 24) flips non-adopting consumers from wrap to overflow. The component already tracksviewportWidth, so compacting off that beats pushingwidth < breakpoint && isSearchExpandedonto every consumer. If out of scope, note the change. justifyContent: 'space-between'on ToolbarRoot (line 15) isn't needed.RightSection'smarginLeft: 'auto'(line 38) already positions it, and auto margins win overjustify-contentin flexbox, so it never takes effect.
…bile compact logic Signed-off-by: KhushamBansal <kbkhushambansal@gmail.com>
|
@Uday9909 Thanks for reviewing. I have updated the PR. |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@src/custom/DataTableToolbar/DataTableToolbar.tsx`:
- Around line 87-89: Reset the column menu state when compact mode hides its
control: in the DataTableToolbar logic around effectiveCompactTrailing, clear
both dropdownOpen and anchorEl whenever effectiveCompactTrailing is true,
preventing a detached menu from reopening after the viewport widens. Add a
regression test covering an open menu followed by a narrow resize and subsequent
wide render.
🪄 Autofix
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro Plus
Run ID: 80fffe89-0936-4685-8938-3fa41f07a018
📒 Files selected for processing (3)
src/__testing__/DataTableToolbar.test.tsxsrc/custom/DataTableToolbar/DataTableToolbar.tsxsrc/custom/DataTableToolbar/DataTableToolbar.types.ts
🚧 Files skipped from review as they are similar to previous changes (1)
- src/custom/DataTableToolbar/DataTableToolbar.types.ts
| const isNarrowViewport = | ||
| viewportWidth > 0 && viewportWidth < theme.breakpoints.values.sm; | ||
| const effectiveCompactTrailing = compactTrailing ?? isNarrowViewport; |
There was a problem hiding this comment.
🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win
Reset the column menu state when compact mode hides the control.
effectiveCompactTrailing removes columnControl from the tree, but it does not reset dropdownOpen or anchorEl. If the menu is open before a narrow resize, the next wide render mounts PopperListener with open={true} and a detached anchor. The menu can reopen at an incorrect position.
Clear both states when effectiveCompactTrailing becomes true. Add a resize regression test.
Proposed state reset
const [dropdownOpen, setDropdownOpen] = React.useState(false);
const [anchorEl, setAnchorEl] = React.useState<HTMLElement | null>(null);
+
+ React.useEffect(() => {
+ if (effectiveCompactTrailing) {
+ setAnchorEl(null);
+ setDropdownOpen(false);
+ }
+ }, [effectiveCompactTrailing]);Also applies to: 199-201, 221-225
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@src/custom/DataTableToolbar/DataTableToolbar.tsx` around lines 87 - 89, Reset
the column menu state when compact mode hides its control: in the
DataTableToolbar logic around effectiveCompactTrailing, clear both dropdownOpen
and anchorEl whenever effectiveCompactTrailing is true, preventing a detached
menu from reopening after the viewport widens. Add a regression test covering an
open menu followed by a narrow resize and subsequent wide render.
|
LGTM!! |
Notes for Reviewers
This PR fixes #
Signed commits
Summary by CodeRabbit
New Features
Tests