Skip to content

Commit

Permalink
[docs] Add recipe showing how to remove cell focus outline (#10843)
Browse files Browse the repository at this point in the history
Signed-off-by: Michel Engelen <[email protected]>
Co-authored-by: Andrew Cherniavskii <[email protected]>
  • Loading branch information
michelengelen and cherniavskii authored Nov 1, 2023
1 parent f1ef162 commit 612fb24
Show file tree
Hide file tree
Showing 6 changed files with 101 additions and 1 deletion.
30 changes: 30 additions & 0 deletions docs/data/data-grid/style-recipes/CellFocusNoOutline.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import * as React from 'react';
import { DataGridPro, gridClasses } from '@mui/x-data-grid-pro';
import { useDemoData } from '@mui/x-data-grid-generator';

const VISIBLE_FIELDS = ['name', 'rating', 'country', 'dateCreated', 'isAdmin'];

export default function CellFocusNoOutline() {
const { data } = useDemoData({
dataSet: 'Employee',
visibleFields: VISIBLE_FIELDS,
rowLength: 100,
});

return (
<div style={{ height: 400, width: '100%' }}>
<DataGridPro
sx={{
[`& .${gridClasses.cell}:focus, & .${gridClasses.cell}:focus-within`]: {
outline: 'none',
},
[`& .${gridClasses.columnHeader}:focus, & .${gridClasses.columnHeader}:focus-within`]:
{
outline: 'none',
},
}}
{...data}
/>
</div>
);
}
30 changes: 30 additions & 0 deletions docs/data/data-grid/style-recipes/CellFocusNoOutline.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import * as React from 'react';
import { DataGridPro, gridClasses } from '@mui/x-data-grid-pro';
import { useDemoData } from '@mui/x-data-grid-generator';

const VISIBLE_FIELDS = ['name', 'rating', 'country', 'dateCreated', 'isAdmin'];

export default function CellFocusNoOutline() {
const { data } = useDemoData({
dataSet: 'Employee',
visibleFields: VISIBLE_FIELDS,
rowLength: 100,
});

return (
<div style={{ height: 400, width: '100%' }}>
<DataGridPro
sx={{
[`& .${gridClasses.cell}:focus, & .${gridClasses.cell}:focus-within`]: {
outline: 'none',
},
[`& .${gridClasses.columnHeader}:focus, & .${gridClasses.columnHeader}:focus-within`]:
{
outline: 'none',
},
}}
{...data}
/>
</div>
);
}
12 changes: 12 additions & 0 deletions docs/data/data-grid/style-recipes/CellFocusNoOutline.tsx.preview
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<DataGridPro
sx={{
[`& .${gridClasses.cell}:focus, & .${gridClasses.cell}:focus-within`]: {
outline: 'none',
},
[`& .${gridClasses.columnHeader}:focus, & .${gridClasses.columnHeader}:focus-within`]:
{
outline: 'none',
},
}}
{...data}
/>
14 changes: 14 additions & 0 deletions docs/data/data-grid/style-recipes/style-recipes.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Data Grid - Styling recipes

<p class="description">Advanced grid styling recipes.</p>

## Remove cell focus outline

The data grid cells are actionable elements and visually indicate the `focus` state by default.
You can remove the focus outline by overriding the `:focus` and `:focus-within` styles for the cells and header cells.

:::warning
Removing the visible `focus` state hurts the accessibility of the grid.
:::

{{"demo": "CellFocusNoOutline.js", "bg": "inline", "defaultCodeOpen": false}}
9 changes: 8 additions & 1 deletion docs/data/pages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,14 @@ const pages: MuiPage[] = [
{ pathname: '/x/react-data-grid/export' },
{ pathname: '/x/react-data-grid/clipboard', title: 'Copy and paste', newFeature: true },
{ pathname: '/x/react-data-grid/components', title: 'Custom subcomponents' },
{ pathname: '/x/react-data-grid/style' },
{
pathname: '/x/react-data-grid/style-group',
title: 'Style',
children: [
{ pathname: '/x/react-data-grid/style', title: 'Overview' },
{ pathname: '/x/react-data-grid/style-recipes', title: 'Recipes' },
],
},
{ pathname: '/x/react-data-grid/localization' },
{ pathname: '/x/react-data-grid/scrolling' },
{ pathname: '/x/react-data-grid/virtualization' },
Expand Down
7 changes: 7 additions & 0 deletions docs/pages/x/react-data-grid/style-recipes.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import * as React from 'react';
import MarkdownDocs from 'docs/src/modules/components/MarkdownDocs';
import * as pageProps from 'docsx/data/data-grid/style-recipes/style-recipes.md?@mui/markdown';

export default function Page() {
return <MarkdownDocs {...pageProps} />;
}

0 comments on commit 612fb24

Please sign in to comment.