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

[DataGrid] Align grid cell tooltip with the column header #14484

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

arminmeh
Copy link
Contributor

@arminmeh arminmeh commented Sep 4, 2024

While working on #9954 I have noticed that sometimes the cell values are read twice as well.
This occurs because of the title prop that was added in #7671
Accessibility tools were already showing warnings for this approach.

Since column header component is using tooltip to show the whole content, I have added the same to the cells and removed the title prop.

This introduced a small UX issue, since the cell text content is added directly to the cell container to reduce the number of nodes. Tooltip shows up way below the cell, because it has a default margin relative to the target element.

I have added a default slotProp value for the Tooltip component, to render it just a bit over the bottom border

const tooltipProps = slotProps?.tooltip || {
  slotProps: {
    popper: {
      sx: {
        [`&.${tooltipClasses.popper}[data-popper-placement*="bottom"] .${tooltipClasses.tooltip}`]:
          {
            marginTop: '-5px',
          },
      },
    },
  },
};

With default margins
before
With mt = -5px
after

To allow changes, I repeated this pattern (but with default)

Issue that should bring this topic even further #7323

@arminmeh arminmeh added accessibility a11y component: data grid This is the name of the generic UI component, not the React module! enhancement This is not a bug, nor a new feature labels Sep 4, 2024
@arminmeh arminmeh requested a review from a team September 4, 2024 08:43
@mui-bot
Copy link

mui-bot commented Sep 4, 2024

Deploy preview: https://deploy-preview-14484--material-ui-x.netlify.app/

Generated by 🚫 dangerJS against 236b89b

@arminmeh arminmeh removed the request for review from a team September 5, 2024 09:07
@arminmeh arminmeh marked this pull request as draft September 5, 2024 09:08
@arminmeh arminmeh marked this pull request as ready for review September 5, 2024 09:35
@arminmeh arminmeh requested a review from a team September 5, 2024 09:36
@arminmeh arminmeh force-pushed the grid-cell-tooltip branch 2 times, most recently from ce452ad to 5e90ef0 Compare September 11, 2024 22:36
@@ -30,6 +30,12 @@ const GridColumnHeaderTitleRoot = styled('div', {
whiteSpace: 'nowrap',
fontWeight: 'var(--unstable_DataGrid-headWeight)',
lineHeight: 'normal',
// To prevent Safari adding its own tooltip for truncated text
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This issue is still present on the GridCell, but I couldn't apply the same because it would impact performance

@github-actions github-actions bot added the PR: out-of-date The pull request has merge conflicts and can't be merged label Sep 16, 2024
Copy link

This pull request has conflicts, please resolve those before we can evaluate the pull request.

@github-actions github-actions bot added PR: out-of-date The pull request has merge conflicts and can't be merged and removed PR: out-of-date The pull request has merge conflicts and can't be merged labels Sep 16, 2024
Copy link

This pull request has conflicts, please resolve those before we can evaluate the pull request.

@github-actions github-actions bot added PR: out-of-date The pull request has merge conflicts and can't be merged and removed PR: out-of-date The pull request has merge conflicts and can't be merged labels Sep 30, 2024
Copy link

This pull request has conflicts, please resolve those before we can evaluate the pull request.

@github-actions github-actions bot removed the PR: out-of-date The pull request has merge conflicts and can't be merged label Sep 30, 2024
Comment on lines +189 to +200
const tooltipProps = slotProps?.tooltip || {
slotProps: {
popper: {
sx: {
[`&.${tooltipClasses.popper}[data-popper-placement*="bottom"] .${tooltipClasses.tooltip}`]:
{
marginTop: '-5px',
},
},
},
},
};
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like a static object, can be extracted.

@@ -7,8 +7,10 @@ import {
unstable_ownerDocument as ownerDocument,
unstable_capitalize as capitalize,
} from '@mui/utils';
import { tooltipClasses, TooltipProps } from '@mui/material/Tooltip';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you see any way to do this without adding material imports here? I need to get rid of these for the design-system agnostic OKR.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This PR is not explicitly requested by anyone. I just saw that we are using different approach for the header row cell and content row cell tooltips.
If it creates too much trouble, the PR can be discarded.
What will be the replacement for the current header cell tooltip?

@@ -76,6 +78,7 @@ export type GridCellProps = {
onKeyDown?: React.KeyboardEventHandler<HTMLDivElement>;
onDragEnter?: React.DragEventHandler<HTMLDivElement>;
onDragOver?: React.DragEventHandler<HTMLDivElement>;
slotProps?: { tooltip?: Partial<TooltipProps> };
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Avoiding exposing material types on our public API is particularly important to achieve the design-system agnostic OKR :| If this is unavoidable, any way to create a minimal subset of the type to avoid exposing everything?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
accessibility a11y component: data grid This is the name of the generic UI component, not the React module! enhancement This is not a bug, nor a new feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants