-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[docs] Add recipe showing how to remove cell focus outline (#10843)
Signed-off-by: Michel Engelen <[email protected]> Co-authored-by: Andrew Cherniavskii <[email protected]>
- Loading branch information
1 parent
f1ef162
commit 612fb24
Showing
6 changed files
with
101 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
12
docs/data/data-grid/style-recipes/CellFocusNoOutline.tsx.preview
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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} | ||
/> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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} />; | ||
} |