Skip to content
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

[DataGridPro] Improve compact density UI for header filters #14373

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ function CustomHeaderFilter(props) {
{...mouseEventsHandlers}
>
<Button
centerRipple={false}
disableRipple
onClick={() => apiRef.current.showFilterPanel(colDef.field)}
>
{activeFiltersCount > 0 ? `${activeFiltersCount} active` : 'Add'} filters
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ function CustomHeaderFilter(props: GridHeaderFilterCellProps) {
{...mouseEventsHandlers}
>
<Button
centerRipple={false}
disableRipple
onClick={() => apiRef.current.showFilterPanel(colDef.field)}
>
{activeFiltersCount > 0 ? `${activeFiltersCount} active` : 'Add'} filters
Expand Down
6 changes: 6 additions & 0 deletions docs/pages/x/api/data-grid/data-grid-premium.json
Original file line number Diff line number Diff line change
Expand Up @@ -1538,6 +1538,12 @@
"description": "Styles applied to the toggle of the grouping criteria cell",
"isGlobal": false
},
{
"key": "headerFilterInput--compact",
"className": "MuiDataGridPremium-headerFilterInput--compact",
"description": "Styles applied the form control of the header filter cell with density=\"compact\".",
"isGlobal": false
},
{
"key": "headerFilterRow",
"className": "MuiDataGridPremium-headerFilterRow",
Expand Down
6 changes: 6 additions & 0 deletions docs/pages/x/api/data-grid/data-grid-pro.json
Original file line number Diff line number Diff line change
Expand Up @@ -1452,6 +1452,12 @@
"description": "Styles applied to the toggle of the grouping criteria cell",
"isGlobal": false
},
{
"key": "headerFilterInput--compact",
"className": "MuiDataGridPro-headerFilterInput--compact",
"description": "Styles applied the form control of the header filter cell with density=\"compact\".",
"isGlobal": false
},
{
"key": "headerFilterRow",
"className": "MuiDataGridPro-headerFilterRow",
Expand Down
6 changes: 6 additions & 0 deletions docs/pages/x/api/data-grid/data-grid.json
Original file line number Diff line number Diff line change
Expand Up @@ -1338,6 +1338,12 @@
"description": "Styles applied to the toggle of the grouping criteria cell",
"isGlobal": false
},
{
"key": "headerFilterInput--compact",
"className": "MuiDataGrid-headerFilterInput--compact",
"description": "Styles applied the form control of the header filter cell with density=\"compact\".",
"isGlobal": false
},
{
"key": "headerFilterRow",
"className": "MuiDataGrid-headerFilterRow",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -977,6 +977,9 @@
"groupingCriteriaCellToggle": {
"description": "Styles applied to the toggle of the grouping criteria cell"
},
"headerFilterInput--compact": {
"description": "Styles applied the form control of the header filter cell with density=&quot;compact&quot;."
},
"headerFilterRow": {
"description": "Styles applied to {{nodeName}}.",
"nodeName": "the column header filter row"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -915,6 +915,9 @@
"groupingCriteriaCellToggle": {
"description": "Styles applied to the toggle of the grouping criteria cell"
},
"headerFilterInput--compact": {
"description": "Styles applied the form control of the header filter cell with density=&quot;compact&quot;."
},
"headerFilterRow": {
"description": "Styles applied to {{nodeName}}.",
"nodeName": "the column header filter row"
Expand Down
3 changes: 3 additions & 0 deletions docs/translations/api-docs/data-grid/data-grid/data-grid.json
Original file line number Diff line number Diff line change
Expand Up @@ -804,6 +804,9 @@
"groupingCriteriaCellToggle": {
"description": "Styles applied to the toggle of the grouping criteria cell"
},
"headerFilterInput--compact": {
"description": "Styles applied the form control of the header filter cell with density=&quot;compact&quot;."
},
"headerFilterRow": {
"description": "Styles applied to {{nodeName}}.",
"nodeName": "the column header filter row"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ import {
gridFilterModelSelector,
gridFilterableColumnLookupSelector,
GridPinnedColumnPosition,
gridDensitySelector,
GridDensity,
} from '@mui/x-data-grid';
import {
GridStateColDef,
Expand Down Expand Up @@ -66,10 +68,11 @@ type OwnerState = DataGridProProcessedProps & {
pinnedPosition?: GridPinnedColumnPosition;
showRightBorder: boolean;
showLeftBorder: boolean;
density: GridDensity;
};

const useUtilityClasses = (ownerState: OwnerState) => {
const { colDef, classes, showRightBorder, showLeftBorder, pinnedPosition } = ownerState;
const { colDef, classes, showRightBorder, showLeftBorder, pinnedPosition, density } = ownerState;

const slots = {
root: [
Expand All @@ -83,6 +86,7 @@ const useUtilityClasses = (ownerState: OwnerState) => {
pinnedPosition === 'left' && 'columnHeader--pinnedLeft',
pinnedPosition === 'right' && 'columnHeader--pinnedRight',
],
formControl: [density === 'compact' && 'headerFilterInput--compact'],
};

return composeClasses(slots, getDataGridUtilityClass, classes);
Expand Down Expand Up @@ -136,6 +140,8 @@ const GridHeaderFilterCell = React.forwardRef<HTMLDivElement, GridHeaderFilterCe
const menuOpenField = useGridSelector(apiRef, gridHeaderFilteringMenuSelector);
const isMenuOpen = menuOpenField === colDef.field;

const density = useGridSelector(apiRef, gridDensitySelector);

// TODO: Support for `isAnyOf` operator
const filterOperators = React.useMemo(() => {
if (!colDef.filterOperators) {
Expand Down Expand Up @@ -306,6 +312,7 @@ const GridHeaderFilterCell = React.forwardRef<HTMLDivElement, GridHeaderFilterCe
colDef,
showLeftBorder,
showRightBorder,
density,
};

const classes = useUtilityClasses(ownerState as OwnerState);
Expand Down Expand Up @@ -376,6 +383,7 @@ const GridHeaderFilterCell = React.forwardRef<HTMLDivElement, GridHeaderFilterCe
tabIndex={-1}
InputLabelProps={null}
sx={colDef.type === 'date' || colDef.type === 'dateTime' ? dateSx : undefined}
formControlClassName={classes.formControl}
{...(isNoInputOperator ? { value: '' } : {})}
{...currentOperator?.InputComponentProps}
{...InputComponentProps}
Expand Down
17 changes: 17 additions & 0 deletions packages/x-data-grid/src/components/containers/GridRootStyles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -406,6 +406,23 @@ export const GridRootStyles = styled('div', {
zIndex: 4, // Should be above the column separator
background: 'var(--DataGrid-pinnedBackground)',
},
[`& .${c['headerFilterInput--compact']}`]: {
[`& input`]: {
fontSize: 14,
marginTop: '-4px',
paddingTop: 3,
paddingBottom: 3,
height: 20,
},
[`& label[data-shrink="false"]`]: {
fontSize: 14,
marginTop: '-8px',
},
[`& div[role="combobox"]`]: {
fontSize: 14,
padding: 0,
},
},
[`& .${c.columnSeparator}`]: {
position: 'absolute',
overflow: 'hidden',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export type GridFilterInputBooleanProps = GridFilterInputValueProps &
* required is selected (for example `isEmpty`)
*/
isFilterActive?: boolean;
formControlClassName?: string;
};

const BooleanOperatorContainer = styled('div')({
Expand All @@ -37,6 +38,7 @@ function GridFilterInputBoolean(props: GridFilterInputBooleanProps) {
label: labelProp,
variant = 'standard',
InputLabelProps,
formControlClassName,
...others
} = props;
const [filterValueState, setFilterValueState] = React.useState(item.value || '');
Expand Down Expand Up @@ -67,7 +69,7 @@ function GridFilterInputBoolean(props: GridFilterInputBooleanProps) {

return (
<BooleanOperatorContainer>
<rootProps.slots.baseFormControl fullWidth>
<rootProps.slots.baseFormControl fullWidth className={formControlClassName}>
<rootProps.slots.baseInputLabel
{...rootProps.slotProps?.baseInputLabel}
id={labelId}
Expand Down Expand Up @@ -131,6 +133,7 @@ GridFilterInputBoolean.propTypes = {
applyValue: PropTypes.func.isRequired,
clearButton: PropTypes.node,
focusElementRef: refType,
formControlClassName: PropTypes.string,
/**
* It is `true` if the filter either has a value or an operator with no value
* required is selected (for example `isEmpty`)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export type GridFilterInputDateProps = GridFilterInputValueProps &
* required is selected (for example `isEmpty`)
*/
isFilterActive?: boolean;
formControlClassName?: string;
};

function convertFilterItemValueToInputValue(
Expand Down Expand Up @@ -54,6 +55,7 @@ function GridFilterInputDate(props: GridFilterInputDateProps) {
clearButton,
tabIndex,
disabled,
formControlClassName,
...other
} = props;
const filterTimeout = useTimeout();
Expand Down Expand Up @@ -98,6 +100,7 @@ function GridFilterInputDate(props: GridFilterInputDateProps) {
InputLabelProps={{
shrink: true,
}}
className={formControlClassName}
inputRef={focusElementRef}
InputProps={{
...(applying || clearButton
Expand Down Expand Up @@ -137,6 +140,7 @@ GridFilterInputDate.propTypes = {
PropTypes.func,
PropTypes.object,
]),
formControlClassName: PropTypes.string,
/**
* It is `true` if the filter either has a value or an operator with no value
* required is selected (for example `isEmpty`)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ export type GridFilterInputSingleSelectProps = GridFilterInputValueProps &
*/
isFilterActive?: boolean;
type?: 'singleSelect';
formControlClassName?: string;
};

function GridFilterInputSingleSelect(props: GridFilterInputSingleSelectProps) {
Expand All @@ -80,6 +81,7 @@ function GridFilterInputSingleSelect(props: GridFilterInputSingleSelectProps) {
isFilterActive,
clearButton,
InputLabelProps,
formControlClassName,
...others
} = props;
const filterValue = item.value ?? '';
Expand Down Expand Up @@ -123,7 +125,7 @@ function GridFilterInputSingleSelect(props: GridFilterInputSingleSelectProps) {

return (
<SingleSelectOperatorContainer>
<rootProps.slots.baseFormControl fullWidth>
<rootProps.slots.baseFormControl fullWidth className={formControlClassName}>
<rootProps.slots.baseInputLabel
{...rootProps.slotProps?.baseInputLabel}
id={labelId}
Expand Down Expand Up @@ -182,6 +184,7 @@ GridFilterInputSingleSelect.propTypes = {
PropTypes.func,
PropTypes.object,
]),
formControlClassName: PropTypes.string,
/**
* It is `true` if the filter either has a value or an operator with no value
* required is selected (for example `isEmpty`)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export type GridTypeFilterInputValueProps = GridFilterInputValueProps &
* required is selected (for example `isEmpty`)
*/
isFilterActive?: boolean;
formControlClassName?: string;
};

type ItemPlusTag = GridFilterItem & { fromInput?: string };
Expand All @@ -32,6 +33,7 @@ function GridFilterInputValue(props: GridTypeFilterInputValueProps) {
isFilterActive,
clearButton,
InputProps,
formControlClassName,
variant = 'standard',
...others
} = props;
Expand Down Expand Up @@ -72,6 +74,7 @@ function GridFilterInputValue(props: GridTypeFilterInputValueProps) {
onChange={onFilterChange}
variant={variant}
type={type || 'text'}
className={formControlClassName}
InputProps={{
...(applying || clearButton
? {
Expand Down Expand Up @@ -113,6 +116,7 @@ GridFilterInputValue.propTypes = {
PropTypes.func,
PropTypes.object,
]),
formControlClassName: PropTypes.string,
/**
* It is `true` if the filter either has a value or an operator with no value
* required is selected (for example `isEmpty`)
Expand Down
5 changes: 5 additions & 0 deletions packages/x-data-grid/src/constants/gridClasses.ts
Original file line number Diff line number Diff line change
Expand Up @@ -610,6 +610,10 @@ export interface GridClasses {
*/
'columnHeader--withRightBorder': string;
'columnHeader--withLeftBorder': string;
/**
* Styles applied the form control of the header filter cell with density="compact".
*/
'headerFilterInput--compact': string;
/**
* Styles applied to the root of the grouping column of the tree data.
*/
Expand Down Expand Up @@ -696,6 +700,7 @@ export const gridClasses = generateUtilityClasses<GridClassKey>('MuiDataGrid', [
'columnHeader--filtered',
'columnHeader--pinnedLeft',
'columnHeader--pinnedRight',
'headerFilterInput--compact',
'columnHeader--last',
'columnHeader--lastUnpinned',
'columnHeader--siblingFocused',
Expand Down