-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
[data grid] Column Header tooltip should be displayed on keyboard focus (especially when a column has ellipsis) #13131
Comments
Hey @shahidify |
@michelengelen Sorry, I didn't realize it's private. Updated. It should work - https://codesandbox.io/p/sandbox/column-header-tooltip-on-keyboard-focus-s5h7rx |
This is basically a material-ui problem, since the Tooltip component apparently captures the keydown events without propagation. I am not super sure what happens here, but it works as expected when using a renderHeader without Tooltip. @mnajdova what do you think? shouldn't this be in the material-ui repo? |
The Tooltip components itself, by default shows the tooltip when the component receives a focus (the component in this case being the icon, no the cell). In order for this to work, the icon itself should have a tabIndex={0}, or be an IconButton component (or a custom button component). I don't see a missing functionality on the Tooltip component iself, or please let me know if this is the case, I think this is more related to how the focus is being handled in the header cell.
What do you mean, from what I tested it works as expected, see: https://codesandbox.io/p/sandbox/blue-sun-ng53wt?file=%2Fsrc%2FDemo.js%3A28%2C33. |
OK, I did some more investigation into this and the root issue was that there was a I did come up with a different solution though: const CustomColumnHeader: FunctionComponent<GridColumnHeaderParams> = ({ colDef, field }) => {
const [isOpen, setIsOpen] = React.useState(false);
const apiRef = useGridApiContext();
const { headerName, description } = colDef;
React.useEffect(() => {
setIsOpen(apiRef.current?.state.focus.columnHeader?.field === field);
}, [apiRef.current?.state.focus.columnHeader]);
return (
<Tooltip
open={isOpen}
title={
<Box display="flex" flexDirection="column">
<Typography sx={{ whiteSpace: 'pre-line' }}>{description}</Typography>
</Box>
}
>
<Typography variant="body2" sx={{ fontWeight: 'bold' }}>
{headerName}
</Typography>
</Tooltip>
);
}; Now the React.useEffect(() => {
apiRef.current.subscribeEvent('columnHeaderFocus', (params) => {
if (field === params.field) {
setIsOpen(true);
}
});
apiRef.current.subscribeEvent('columnHeaderBlur', (params) => {
if (field === params.field) {
setIsOpen(false);
}
});
}, [apiRef]); I do prefer the top one thoush. @shahidify WDYT? Would that solve your issue? |
Thank you @michelengelen |
@michelengelen While both these solution work for keyboard focus, I observe column headers don't display tooltip on Mouse Hover anymore. Do we need to add some additional events for mouse hover ? |
Yes, you would need to add events for |
Shouldn't the Grid do this by default? Having to work around it with a custom component doesn't seem proper. |
I was out last week. I will try the suggested solution and will update. Thanks. |
Not if you provide a custom renderer ... |
Mouse hover and keyboard focus don't seem to work together. Multiple tooltips may open (one with keyboard, one with mouse hover). @michelengelen any suggestion ? |
The original issue is to display tooltip on keyboard focus like how it works on mouse hover. I used custom renderer to achieve the same. Will be happy if it can be achieved without custom header. |
The problem in depth
I am a MUI Pro license user.
I am working on an accessibility feature that needs to display column header tooltip on keyboard focus. This is essential in case where column header has ellipsis (due to resize or long header text). Datagrid tooltip is displayed only on mouse hover, not on keyboard hover. If I use custom header and update tabIndex, keyboard navigation gets trapped.
A similar issue in data cell got resolved using
hasFocus
prop but this prop is not available for header cell.Example: https://codesandbox.io/p/sandbox/column-header-tooltip-on-keyboard-focus-s5h7rx
Any suggestion to add this behavior?
Your environment
Search keywords: Column Header tooltip, keyboard navigation
Order ID: 8813014139
The text was updated successfully, but these errors were encountered: