-
Notifications
You must be signed in to change notification settings - Fork 232
[DataTableToolbar] Fix mobile single-row layout and add compactTrailing #1790
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
e170fb2
c786863
70ede88
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -20,8 +20,7 @@ const ToolbarRoot = styled(Box)(({ theme }) => ({ | |
| boxShadow: theme.shadows[2], | ||
|
|
||
| [theme.breakpoints.down('sm')]: { | ||
| height: 'auto', | ||
| flexWrap: 'wrap', | ||
| flexWrap: 'nowrap', | ||
| padding: theme.spacing(1), | ||
| gap: theme.spacing(1) | ||
| } | ||
|
|
@@ -30,13 +29,43 @@ const ToolbarRoot = styled(Box)(({ theme }) => ({ | |
| const Section = styled(Box)(({ theme }) => ({ | ||
| display: 'flex', | ||
| alignItems: 'center', | ||
| gap: theme.spacing(1), | ||
| minWidth: 0 | ||
| })); | ||
|
|
||
| const RightSection = styled(Section)(({ theme }) => ({ | ||
| marginLeft: 'auto', | ||
| flexWrap: 'nowrap', | ||
| flexShrink: 1, | ||
| minWidth: 0, | ||
| justifyContent: 'flex-end', | ||
|
|
||
| [theme.breakpoints.down('sm')]: { | ||
| paddingLeft: theme.spacing(1) | ||
| } | ||
| })); | ||
|
|
||
| const RightControlsGroup = styled(Box)(({ theme }) => ({ | ||
| display: 'flex', | ||
| alignItems: 'center', | ||
| flexShrink: 1, | ||
| minWidth: 0, | ||
| gap: theme.spacing(1) | ||
| })); | ||
|
|
||
| const RightSection = styled(Section)({ | ||
| marginLeft: 'auto' | ||
| const SearchSlot = styled(Box)({ | ||
| flex: '0 1 auto', | ||
| minWidth: 0, | ||
| maxWidth: '15rem' | ||
| }); | ||
|
|
||
| const TrailingControls = styled(Box)(({ theme }) => ({ | ||
| display: 'flex', | ||
| alignItems: 'center', | ||
| flexShrink: 0, | ||
| gap: theme.spacing(1) | ||
| })); | ||
|
|
||
| export function DataTableToolbar({ | ||
| primaryActions, | ||
| secondaryActions, | ||
|
|
@@ -45,6 +74,7 @@ export function DataTableToolbar({ | |
| filter, | ||
| columnVisibility, | ||
| viewSwitch, | ||
| compactTrailing, | ||
| searchHelperText, | ||
| tabs, | ||
| columns, | ||
|
|
@@ -54,6 +84,9 @@ export function DataTableToolbar({ | |
| }: DataTableToolbarProps): JSX.Element { | ||
| const theme = useTheme(); | ||
| const { width: viewportWidth } = useWindowDimensions(); | ||
| const isNarrowViewport = | ||
| viewportWidth > 0 && viewportWidth < theme.breakpoints.values.sm; | ||
| const effectiveCompactTrailing = compactTrailing ?? isNarrowViewport; | ||
|
Comment on lines
+87
to
+89
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win Reset the column menu state when compact mode hides the control.
Clear both states when 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 |
||
|
|
||
| // Compute auto-hide visibility from columns config + viewport width | ||
| const autoHideVisibility = React.useMemo(() => { | ||
|
|
@@ -155,27 +188,43 @@ export function DataTableToolbar({ | |
| columnVisibility | ||
| ); | ||
|
|
||
| const trailingControls = ( | ||
| <> | ||
| {filter} | ||
| {columnControl} | ||
| {viewSwitch} | ||
| </> | ||
| ); | ||
|
|
||
| const hasTrailingControls = | ||
| !effectiveCompactTrailing && | ||
| (Boolean(filter) || Boolean(columnControl) || Boolean(viewSwitch)); | ||
|
|
||
| const hasLeftContent = Boolean(primaryActions); | ||
| const hasRightContent = | ||
| Boolean(bulkOperations) || | ||
| Boolean(secondaryActions) || | ||
| Boolean(filter) || | ||
| Boolean(search) || | ||
| Boolean(columnControl) || | ||
| Boolean(viewSwitch); | ||
| hasTrailingControls; | ||
|
|
||
| return ( | ||
| <> | ||
| <ToolbarRoot sx={sx}> | ||
| {hasLeftContent && <Section>{primaryActions}</Section>} | ||
| <ToolbarRoot data-testid="data-table-toolbar" sx={sx}> | ||
| {hasLeftContent && <Section data-testid="data-table-toolbar-left-section">{primaryActions}</Section>} | ||
| {hasRightContent && ( | ||
| <RightSection> | ||
| <RightSection data-testid="data-table-toolbar-right-section"> | ||
| {bulkOperations} | ||
| {secondaryActions} | ||
| {search} | ||
| {filter} | ||
| {columnControl} | ||
| {viewSwitch} | ||
| {(search || hasTrailingControls) && ( | ||
| <RightControlsGroup data-testid="data-table-toolbar-right-controls"> | ||
| {search && <SearchSlot>{search}</SearchSlot>} | ||
| {hasTrailingControls && ( | ||
| <TrailingControls data-testid="data-table-toolbar-trailing-controls"> | ||
| {trailingControls} | ||
| </TrailingControls> | ||
| )} | ||
| </RightControlsGroup> | ||
| )} | ||
| </RightSection> | ||
| )} | ||
| </ToolbarRoot> | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How did we arrive at 15rem?
Should this be using a theme.spacing or breakpoint size instead?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@pontusringblom That’s the expanded width we already use for SearchBar.