Gauge charts let the user evaluate metrics.
-:::warning -The Gauge Chart component isn't available yet, but you can upvote [**this GitHub issue**](https://github.com/mui/mui-x/issues/2903) to see it arrive sooner. +{{"component": "modules/components/ComponentLinkHeader.js", "design": false}} -Don't hesitate to leave a comment there to influence what gets built. -Especially if you already have a use case for this component, or if you're facing a pain point with your current solution. +## Basics + +The Gauge displays a numeric value that varies within a defined range. + +{{"demo": "BasicGauges.js"}} + +## Value range + +The Gauge's value is provided through the `value` props, which accept a value range between 0 and 100. +To modify it, use the `valueMin` and `valueMax` props. + +{{"demo": "GaugeValueRangeNoSnap.js"}} + +## Arcs configuration + +Modify the arc shape with the following props: + +- `startAngle` and `endAngle`: The angle range provided in degrees +- `innerRadius` and `outerRadius`: The arc's radii. It can be a fixed number of pixels or a percentage string, which will be a percent of the maximal available radius +- `cornerRadius`: It can be a fixed number of pixels or a percentage string, which will be a percent of the maximal available radius + +{{"demo": "ArcPlaygroundNoSnap.js", "bg": "playground", "hideToolbar": true }} + +:::success +Notice that the arc position is computed to let the Gauge take as much space as possible in the drawing area. + +Use the `cx` and/or `cy` props to fix the coordinate of the arc center. ::: + +## Text configuration + +By default, the Gauge displays the value in the center of the arc. +To modify it, use the `text` prop. + +This prop can be a string, or a formatter. +In the second case, the formatter argument contains the `value`, `valueMin` and `valueMax`. + +To modify the text's layout, use the `gaugeClasses.valueText` class name. + +{{"demo": "TextPlaygroundNoSnap.js", "bg": "playground", "hideToolbar": true}} + +## Arc design + +To customize the Gauge styles, use the `chartsGaugeClasses` export to pull class names from different parts of the component, such as `valueText`, `valueArc`, and `referenceArc`. + +For a full reference list, visit the [API page](/x/api/charts/gauge/#classes). + +{{"demo": "ArcDesign.js"}} + +## Adding elements + +### Using the default Gauge + +To insert more elements into the Gauge, the first option would be to add them as children, which means they will be stacked on top of the default rendering. + +```tsx +import { Gauge } from '@mui/x-charts/Gauge'; + +Heat map charts allow to highlight correlation between categories.
+Heatmap charts allow to highlight correlation between categories.
:::warning -The Heat map Chart component isn't available yet, but you can upvote [**this GitHub issue**](https://github.com/mui/mui-x/issues/7926) to see it arrive sooner. +The Heatmap Chart component isn't available yet, but you can upvote [**this GitHub issue**](https://github.com/mui/mui-x/issues/7926) to see it arrive sooner. Don't hesitate to leave a comment there to influence what gets built. Especially if you already have a use case for this component, or if you're facing a pain point with your current solution. diff --git a/docs/data/charts/legend/legend.md b/docs/data/charts/legend/legend.md index edecb80ab591..5c560a3f8592 100644 --- a/docs/data/charts/legend/legend.md +++ b/docs/data/charts/legend/legend.md @@ -1,7 +1,7 @@ --- title: Charts - Legend productId: x-charts -components: ChartsLegend, ChartsText +components: ChartsLegend, DefaultChartsLegend, ChartsText --- # Charts - Legend diff --git a/docs/data/charts/lines/GridDemo.js b/docs/data/charts/lines/GridDemo.js new file mode 100644 index 000000000000..0f5641f5b2a9 --- /dev/null +++ b/docs/data/charts/lines/GridDemo.js @@ -0,0 +1,18 @@ +import * as React from 'react'; +import { LineChart } from '@mui/x-charts/LineChart'; + +export default function GridDemo() { + return ( +Tooltip provides extra data on charts item.
In all charts components, you can pass props to the tooltip by using `tooltip={{...}}`. -If you are using composition, you can add the `Treemap allows to display data with a hierarchical structure.
:::warning -The Treemap Chart component isn't available yet, but you can upvote [**this GitHub issue**](https://github.com/mui/mui-x/issues/7924) to see it arrive sooner. +The Treemap component isn't available yet, but you can upvote [**this GitHub issue**](https://github.com/mui/mui-x/issues/7924) to see it arrive sooner. Don't hesitate to leave a comment there to influence what gets built. Especially if you already have a use case for this component, or if you're facing a pain point with your current solution. diff --git a/docs/data/data-grid/accessibility/DensitySelectorSmallGrid.js b/docs/data/data-grid/accessibility/DensitySelectorSmallGrid.js index d9d61b7c7433..9fe1c320f95b 100644 --- a/docs/data/data-grid/accessibility/DensitySelectorSmallGrid.js +++ b/docs/data/data-grid/accessibility/DensitySelectorSmallGrid.js @@ -15,6 +15,8 @@ function CustomToolbar() { } export default function DensitySelectorSmallGrid() { + const [density, setDensity] = React.useState('compact'); + const { data } = useDemoData({ dataSet: 'Commodity', rowLength: 4, @@ -25,7 +27,11 @@ export default function DensitySelectorSmallGrid() {Using the data grid with Joy UI components
+Using the data grid with Joy UI components
{{"demo": "GridJoyUISlots.js", "bg": "inline"}} diff --git a/docs/data/data-grid/localization/DataGridRTL.js b/docs/data/data-grid/localization/DataGridRTL.js index abd88d606147..e5b06bc23c83 100644 --- a/docs/data/data-grid/localization/DataGridRTL.js +++ b/docs/data/data-grid/localization/DataGridRTL.js @@ -27,7 +27,7 @@ const columns = [ { field: 'age', headerName: 'عمر', - valueGetter: (params) => `${params.value} سنوات`, + valueGetter: (value) => `${value} سنوات`, width: 150, }, { diff --git a/docs/data/data-grid/localization/DataGridRTL.tsx b/docs/data/data-grid/localization/DataGridRTL.tsx index df697849b2d0..bd14585f5255 100644 --- a/docs/data/data-grid/localization/DataGridRTL.tsx +++ b/docs/data/data-grid/localization/DataGridRTL.tsx @@ -27,7 +27,7 @@ const columns: GridColDef[] = [ { field: 'age', headerName: 'عمر', - valueGetter: (params) => `${params.value} سنوات`, + valueGetter: (value) => `${value} سنوات`, width: 150, }, { diff --git a/docs/data/data-grid/localization/data.json b/docs/data/data-grid/localization/data.json index 343c85085279..3ee05aff82c5 100644 --- a/docs/data/data-grid/localization/data.json +++ b/docs/data/data-grid/localization/data.json @@ -5,7 +5,7 @@ "localeName": "Arabic (Sudan)", "missingKeysCount": 3, "totalKeysCount": 117, - "githubLink": "https://github.com/mui/mui-x/blob/next/packages/grid/x-data-grid/src/locales/arSD.ts" + "githubLink": "https://github.com/mui/mui-x/blob/master/packages/x-data-grid/src/locales/arSD.ts" }, { "languageTag": "be-BY", @@ -13,7 +13,7 @@ "localeName": "Belarusian", "missingKeysCount": 29, "totalKeysCount": 117, - "githubLink": "https://github.com/mui/mui-x/blob/next/packages/grid/x-data-grid/src/locales/beBY.ts" + "githubLink": "https://github.com/mui/mui-x/blob/master/packages/x-data-grid/src/locales/beBY.ts" }, { "languageTag": "bg-BG", @@ -21,7 +21,7 @@ "localeName": "Bulgarian", "missingKeysCount": 3, "totalKeysCount": 117, - "githubLink": "https://github.com/mui/mui-x/blob/next/packages/grid/x-data-grid/src/locales/bgBG.ts" + "githubLink": "https://github.com/mui/mui-x/blob/master/packages/x-data-grid/src/locales/bgBG.ts" }, { "languageTag": "zh-HK", @@ -29,7 +29,7 @@ "localeName": "Chinese (Hong Kong)", "missingKeysCount": 3, "totalKeysCount": 117, - "githubLink": "https://github.com/mui/mui-x/blob/next/packages/grid/x-data-grid/src/locales/zhHK.ts" + "githubLink": "https://github.com/mui/mui-x/blob/master/packages/x-data-grid/src/locales/zhHK.ts" }, { "languageTag": "zh-CN", @@ -37,7 +37,7 @@ "localeName": "Chinese (Simplified)", "missingKeysCount": 3, "totalKeysCount": 117, - "githubLink": "https://github.com/mui/mui-x/blob/next/packages/grid/x-data-grid/src/locales/zhCN.ts" + "githubLink": "https://github.com/mui/mui-x/blob/master/packages/x-data-grid/src/locales/zhCN.ts" }, { "languageTag": "zh-TW", @@ -45,7 +45,7 @@ "localeName": "Chinese (Taiwan)", "missingKeysCount": 3, "totalKeysCount": 117, - "githubLink": "https://github.com/mui/mui-x/blob/next/packages/grid/x-data-grid/src/locales/zhTW.ts" + "githubLink": "https://github.com/mui/mui-x/blob/master/packages/x-data-grid/src/locales/zhTW.ts" }, { "languageTag": "hr-HR", @@ -53,7 +53,7 @@ "localeName": "Croatian", "missingKeysCount": 3, "totalKeysCount": 117, - "githubLink": "https://github.com/mui/mui-x/blob/next/packages/grid/x-data-grid/src/locales/hrHR.ts" + "githubLink": "https://github.com/mui/mui-x/blob/master/packages/x-data-grid/src/locales/hrHR.ts" }, { "languageTag": "cs-CZ", @@ -61,7 +61,7 @@ "localeName": "Czech", "missingKeysCount": 3, "totalKeysCount": 117, - "githubLink": "https://github.com/mui/mui-x/blob/next/packages/grid/x-data-grid/src/locales/csCZ.ts" + "githubLink": "https://github.com/mui/mui-x/blob/master/packages/x-data-grid/src/locales/csCZ.ts" }, { "languageTag": "da-DK", @@ -69,7 +69,7 @@ "localeName": "Danish", "missingKeysCount": 3, "totalKeysCount": 117, - "githubLink": "https://github.com/mui/mui-x/blob/next/packages/grid/x-data-grid/src/locales/daDK.ts" + "githubLink": "https://github.com/mui/mui-x/blob/master/packages/x-data-grid/src/locales/daDK.ts" }, { "languageTag": "nl-NL", @@ -77,7 +77,7 @@ "localeName": "Dutch", "missingKeysCount": 3, "totalKeysCount": 117, - "githubLink": "https://github.com/mui/mui-x/blob/next/packages/grid/x-data-grid/src/locales/nlNL.ts" + "githubLink": "https://github.com/mui/mui-x/blob/master/packages/x-data-grid/src/locales/nlNL.ts" }, { "languageTag": "fi-FI", @@ -85,7 +85,7 @@ "localeName": "Finnish", "missingKeysCount": 3, "totalKeysCount": 117, - "githubLink": "https://github.com/mui/mui-x/blob/next/packages/grid/x-data-grid/src/locales/fiFI.ts" + "githubLink": "https://github.com/mui/mui-x/blob/master/packages/x-data-grid/src/locales/fiFI.ts" }, { "languageTag": "fr-FR", @@ -93,7 +93,7 @@ "localeName": "French", "missingKeysCount": 3, "totalKeysCount": 117, - "githubLink": "https://github.com/mui/mui-x/blob/next/packages/grid/x-data-grid/src/locales/frFR.ts" + "githubLink": "https://github.com/mui/mui-x/blob/master/packages/x-data-grid/src/locales/frFR.ts" }, { "languageTag": "de-DE", @@ -101,7 +101,7 @@ "localeName": "German", "missingKeysCount": 3, "totalKeysCount": 117, - "githubLink": "https://github.com/mui/mui-x/blob/next/packages/grid/x-data-grid/src/locales/deDE.ts" + "githubLink": "https://github.com/mui/mui-x/blob/master/packages/x-data-grid/src/locales/deDE.ts" }, { "languageTag": "el-GR", @@ -109,7 +109,7 @@ "localeName": "Greek", "missingKeysCount": 3, "totalKeysCount": 117, - "githubLink": "https://github.com/mui/mui-x/blob/next/packages/grid/x-data-grid/src/locales/elGR.ts" + "githubLink": "https://github.com/mui/mui-x/blob/master/packages/x-data-grid/src/locales/elGR.ts" }, { "languageTag": "he-IL", @@ -117,7 +117,7 @@ "localeName": "Hebrew", "missingKeysCount": 3, "totalKeysCount": 117, - "githubLink": "https://github.com/mui/mui-x/blob/next/packages/grid/x-data-grid/src/locales/heIL.ts" + "githubLink": "https://github.com/mui/mui-x/blob/master/packages/x-data-grid/src/locales/heIL.ts" }, { "languageTag": "hu-HU", @@ -125,7 +125,7 @@ "localeName": "Hungarian", "missingKeysCount": 5, "totalKeysCount": 117, - "githubLink": "https://github.com/mui/mui-x/blob/next/packages/grid/x-data-grid/src/locales/huHU.ts" + "githubLink": "https://github.com/mui/mui-x/blob/master/packages/x-data-grid/src/locales/huHU.ts" }, { "languageTag": "it-IT", @@ -133,15 +133,15 @@ "localeName": "Italian", "missingKeysCount": 3, "totalKeysCount": 117, - "githubLink": "https://github.com/mui/mui-x/blob/next/packages/grid/x-data-grid/src/locales/itIT.ts" + "githubLink": "https://github.com/mui/mui-x/blob/master/packages/x-data-grid/src/locales/itIT.ts" }, { "languageTag": "ja-JP", "importName": "jaJP", "localeName": "Japanese", - "missingKeysCount": 3, + "missingKeysCount": 0, "totalKeysCount": 117, - "githubLink": "https://github.com/mui/mui-x/blob/next/packages/grid/x-data-grid/src/locales/jaJP.ts" + "githubLink": "https://github.com/mui/mui-x/blob/master/packages/x-data-grid/src/locales/jaJP.ts" }, { "languageTag": "ko-KR", @@ -149,7 +149,7 @@ "localeName": "Korean", "missingKeysCount": 30, "totalKeysCount": 117, - "githubLink": "https://github.com/mui/mui-x/blob/next/packages/grid/x-data-grid/src/locales/koKR.ts" + "githubLink": "https://github.com/mui/mui-x/blob/master/packages/x-data-grid/src/locales/koKR.ts" }, { "languageTag": "nb-NO", @@ -157,7 +157,7 @@ "localeName": "Norwegian (Bokmål)", "missingKeysCount": 28, "totalKeysCount": 117, - "githubLink": "https://github.com/mui/mui-x/blob/next/packages/grid/x-data-grid/src/locales/nbNO.ts" + "githubLink": "https://github.com/mui/mui-x/blob/master/packages/x-data-grid/src/locales/nbNO.ts" }, { "languageTag": "fa-IR", @@ -165,7 +165,7 @@ "localeName": "Persian", "missingKeysCount": 3, "totalKeysCount": 117, - "githubLink": "https://github.com/mui/mui-x/blob/next/packages/grid/x-data-grid/src/locales/faIR.ts" + "githubLink": "https://github.com/mui/mui-x/blob/master/packages/x-data-grid/src/locales/faIR.ts" }, { "languageTag": "pl-PL", @@ -173,7 +173,7 @@ "localeName": "Polish", "missingKeysCount": 30, "totalKeysCount": 117, - "githubLink": "https://github.com/mui/mui-x/blob/next/packages/grid/x-data-grid/src/locales/plPL.ts" + "githubLink": "https://github.com/mui/mui-x/blob/master/packages/x-data-grid/src/locales/plPL.ts" }, { "languageTag": "pt-PT", @@ -181,7 +181,7 @@ "localeName": "Portuguese", "missingKeysCount": 3, "totalKeysCount": 117, - "githubLink": "https://github.com/mui/mui-x/blob/next/packages/grid/x-data-grid/src/locales/ptPT.ts" + "githubLink": "https://github.com/mui/mui-x/blob/master/packages/x-data-grid/src/locales/ptPT.ts" }, { "languageTag": "pt-BR", @@ -189,7 +189,7 @@ "localeName": "Portuguese (Brazil)", "missingKeysCount": 3, "totalKeysCount": 117, - "githubLink": "https://github.com/mui/mui-x/blob/next/packages/grid/x-data-grid/src/locales/ptBR.ts" + "githubLink": "https://github.com/mui/mui-x/blob/master/packages/x-data-grid/src/locales/ptBR.ts" }, { "languageTag": "ro-RO", @@ -197,7 +197,7 @@ "localeName": "Romanian", "missingKeysCount": 3, "totalKeysCount": 117, - "githubLink": "https://github.com/mui/mui-x/blob/next/packages/grid/x-data-grid/src/locales/roRO.ts" + "githubLink": "https://github.com/mui/mui-x/blob/master/packages/x-data-grid/src/locales/roRO.ts" }, { "languageTag": "ru-RU", @@ -205,7 +205,7 @@ "localeName": "Russian", "missingKeysCount": 3, "totalKeysCount": 117, - "githubLink": "https://github.com/mui/mui-x/blob/next/packages/grid/x-data-grid/src/locales/ruRU.ts" + "githubLink": "https://github.com/mui/mui-x/blob/master/packages/x-data-grid/src/locales/ruRU.ts" }, { "languageTag": "sk-SK", @@ -213,7 +213,7 @@ "localeName": "Slovak", "missingKeysCount": 3, "totalKeysCount": 117, - "githubLink": "https://github.com/mui/mui-x/blob/next/packages/grid/x-data-grid/src/locales/skSK.ts" + "githubLink": "https://github.com/mui/mui-x/blob/master/packages/x-data-grid/src/locales/skSK.ts" }, { "languageTag": "es-ES", @@ -221,7 +221,7 @@ "localeName": "Spanish", "missingKeysCount": 3, "totalKeysCount": 117, - "githubLink": "https://github.com/mui/mui-x/blob/next/packages/grid/x-data-grid/src/locales/esES.ts" + "githubLink": "https://github.com/mui/mui-x/blob/master/packages/x-data-grid/src/locales/esES.ts" }, { "languageTag": "sv-SE", @@ -229,7 +229,7 @@ "localeName": "Swedish", "missingKeysCount": 3, "totalKeysCount": 117, - "githubLink": "https://github.com/mui/mui-x/blob/next/packages/grid/x-data-grid/src/locales/svSE.ts" + "githubLink": "https://github.com/mui/mui-x/blob/master/packages/x-data-grid/src/locales/svSE.ts" }, { "languageTag": "tr-TR", @@ -237,7 +237,7 @@ "localeName": "Turkish", "missingKeysCount": 18, "totalKeysCount": 117, - "githubLink": "https://github.com/mui/mui-x/blob/next/packages/grid/x-data-grid/src/locales/trTR.ts" + "githubLink": "https://github.com/mui/mui-x/blob/master/packages/x-data-grid/src/locales/trTR.ts" }, { "languageTag": "uk-UA", @@ -245,7 +245,7 @@ "localeName": "Ukrainian", "missingKeysCount": 3, "totalKeysCount": 117, - "githubLink": "https://github.com/mui/mui-x/blob/next/packages/grid/x-data-grid/src/locales/ukUA.ts" + "githubLink": "https://github.com/mui/mui-x/blob/master/packages/x-data-grid/src/locales/ukUA.ts" }, { "languageTag": "ur-PK", @@ -253,7 +253,7 @@ "localeName": "Urdu (Pakistan)", "missingKeysCount": 3, "totalKeysCount": 117, - "githubLink": "https://github.com/mui/mui-x/blob/next/packages/grid/x-data-grid/src/locales/urPK.ts" + "githubLink": "https://github.com/mui/mui-x/blob/master/packages/x-data-grid/src/locales/urPK.ts" }, { "languageTag": "vi-VN", @@ -261,6 +261,6 @@ "localeName": "Vietnamese", "missingKeysCount": 3, "totalKeysCount": 117, - "githubLink": "https://github.com/mui/mui-x/blob/next/packages/grid/x-data-grid/src/locales/viVN.ts" + "githubLink": "https://github.com/mui/mui-x/blob/master/packages/x-data-grid/src/locales/viVN.ts" } ] diff --git a/docs/data/data-grid/localization/localization.md b/docs/data/data-grid/localization/localization.md index 0a2aa44e6753..117d8792a96d 100644 --- a/docs/data/data-grid/localization/localization.md +++ b/docs/data/data-grid/localization/localization.md @@ -7,7 +7,7 @@ The default locale of MUI X is English (United States). If you want to use othe ## Translation keys You can use the `localeText` prop to pass in your own text and translations. -You can find all the translation keys supported in [the source](https://github.com/mui/mui-x/blob/-/packages/grid/x-data-grid/src/constants/localeTextConstants.ts) +You can find all the translation keys supported in [the source](https://github.com/mui/mui-x/blob/-/packages/x-data-grid/src/constants/localeTextConstants.ts) in the GitHub repository. In the following example, the labels of the density selector are customized. @@ -99,7 +99,7 @@ import { nlNL } from '@mui/x-data-grid/locales'; {{"demo": "DataGridLocalisationTableNoSnap.js", "hideToolbar": true, "bg": "inline"}} -You can [find the source](https://github.com/mui/mui-x/tree/HEAD/packages/grid/x-data-grid/src/locales) in the GitHub repository. +You can [find the source](https://github.com/mui/mui-x/tree/HEAD/packages/x-data-grid/src/locales) in the GitHub repository. To create your own translation or to customize the English text, copy this file to your project, make any changes needed and import the locale from there. Note that these translations of the Data Grid component depend on the [Localization strategy](/material-ui/guides/localization/) of the whole library. @@ -107,7 +107,7 @@ Note that these translations of the Data Grid component depend on the [Localizat ## RTL Support Right-to-left languages such as Arabic, Persian, or Hebrew are supported. -Follow [this guide](/material-ui/guides/right-to-left/) to use them. +Follow [this guide](/material-ui/customization/right-to-left/) to use them. The example below demonstrates how to use an RTL language (Arabic) with the data grid. diff --git a/docs/data/data-grid/master-detail/BasicDetailPanels.js b/docs/data/data-grid/master-detail/BasicDetailPanels.js index 27441b5dc395..172e2c73444a 100644 --- a/docs/data/data-grid/master-detail/BasicDetailPanels.js +++ b/docs/data/data-grid/master-detail/BasicDetailPanels.js @@ -61,7 +61,7 @@ function DetailPanelContent({ row: rowProp }) { field: 'total', headerName: 'Total', type: 'number', - valueGetter: ({ row }) => row.quantity * row.unitPrice, + valueGetter: (value, row) => row.quantity * row.unitPrice, }, ]} rows={rowProp.products} @@ -83,7 +83,7 @@ const columns = [ field: 'total', type: 'number', headerName: 'Total', - valueGetter: ({ row }) => { + valueGetter: (value, row) => { const subtotal = row.products.reduce( (acc, product) => product.unitPrice * product.quantity, 0, @@ -175,7 +175,6 @@ export default function BasicDetailPanels() {Aggregation with server side data source.
+Aggregation with server-side data source.
:::warning This feature isn't implemented yet. It's coming. diff --git a/docs/data/data-grid/server-side-data/index.md b/docs/data/data-grid/server-side-data/index.md index 13ee31d9b005..a626f60d7c3c 100644 --- a/docs/data/data-grid/server-side-data/index.md +++ b/docs/data/data-grid/server-side-data/index.md @@ -63,7 +63,7 @@ This example only scratches the surface with a lot of problems still unsolved li - Performance optimization - Caching data/deduping requests - More complex use-cases on the server like grouping, tree data, etc. -- Server side row editing +- Server-side row editing - Lazy loading of data - Handling updates to the data like row editing, row deletion, etc. - Refetching data on-demand @@ -182,7 +182,7 @@ interface GetRowsResponse { rows: GridRowModel[]; /** * To reflect updates in total `rowCount` (optional) - * Useful when the `rowCount` is inaccurate (e.g. when filtering) or not available upfront + * Useful when the `rowCount` is inaccurate (for example when filtering) or not available upfront */ rowCount?: number; /** diff --git a/docs/data/data-grid/server-side-data/infinite-loading.md b/docs/data/data-grid/server-side-data/infinite-loading.md index c317a2bb4fd2..d2bcc0e58d03 100644 --- a/docs/data/data-grid/server-side-data/infinite-loading.md +++ b/docs/data/data-grid/server-side-data/infinite-loading.md @@ -4,7 +4,7 @@ title: React Server-side infinite loading # Data Grid - Server-side infinite loading [](/x/introduction/licensing/#pro-plan 'Pro plan')🚧 -Row infinite loading with server side data source.
+Row infinite loading with server-side data source.
:::warning This feature isn't implemented yet. It's coming. diff --git a/docs/data/data-grid/server-side-data/lazy-loading.md b/docs/data/data-grid/server-side-data/lazy-loading.md index 849d0c9ba721..6c66183ab0e6 100644 --- a/docs/data/data-grid/server-side-data/lazy-loading.md +++ b/docs/data/data-grid/server-side-data/lazy-loading.md @@ -4,7 +4,7 @@ title: React Server-side lazy loading # Data Grid - Server-side lazy loading [](/x/introduction/licensing/#pro-plan 'Pro plan')🚧 -Row lazy-loading with server side data source.
+Row lazy-loading with server-side data source.
:::warning This feature isn't implemented yet. It's coming. diff --git a/docs/data/data-grid/server-side-data/row-grouping.md b/docs/data/data-grid/server-side-data/row-grouping.md index 3dd487f34f27..537ef8ad0d54 100644 --- a/docs/data/data-grid/server-side-data/row-grouping.md +++ b/docs/data/data-grid/server-side-data/row-grouping.md @@ -4,7 +4,7 @@ title: React Server-side row grouping # Data Grid - Server-side row grouping [](/x/introduction/licensing/#pro-plan 'Pro plan')🚧 -Lazy-loaded row grouping with server side data source.
+Lazy-loaded row grouping with server-side data source.
:::warning This feature isn't implemented yet. It's coming. diff --git a/docs/data/data-grid/server-side-data/tree-data.md b/docs/data/data-grid/server-side-data/tree-data.md index 7ce5524f9c16..ba9d93e36719 100644 --- a/docs/data/data-grid/server-side-data/tree-data.md +++ b/docs/data/data-grid/server-side-data/tree-data.md @@ -4,7 +4,7 @@ title: React Server-side tree data # Data Grid - Server-side tree data [](/x/introduction/licensing/#pro-plan 'Pro plan')🚧 -Tree data lazy-loading with server side data source.
+Tree data lazy-loading with server-side data source.
:::warning This feature isn't implemented yet. It's coming. diff --git a/docs/data/data-grid/sorting/ExtendedSortComparator.js b/docs/data/data-grid/sorting/ExtendedSortComparator.js index 86acdc0d08ee..705eb59585e8 100644 --- a/docs/data/data-grid/sorting/ExtendedSortComparator.js +++ b/docs/data/data-grid/sorting/ExtendedSortComparator.js @@ -37,12 +37,11 @@ export default function ExtendedSortComparator() { { field: 'nameAdmin', headerName: 'Name', - valueGetter: (params) => ({ - name: params.row.name, - isAdmin: params.row.isAdmin, + valueGetter: (value, row) => ({ + name: row.name, + isAdmin: row.isAdmin, }), - valueFormatter: (params) => { - const value = params.value; + valueFormatter: (value) => { if (value.isAdmin) { return `${value.name} (admin)`; } diff --git a/docs/data/data-grid/sorting/ExtendedSortComparator.tsx b/docs/data/data-grid/sorting/ExtendedSortComparator.tsx index ddeef60aeb35..5419a57b3eea 100644 --- a/docs/data/data-grid/sorting/ExtendedSortComparator.tsx +++ b/docs/data/data-grid/sorting/ExtendedSortComparator.tsx @@ -2,7 +2,6 @@ import * as React from 'react'; import { GridColDef, DataGrid, - GridValueGetterParams, gridNumberComparator, gridStringOrNumberComparator, GridComparatorFn, @@ -50,12 +49,11 @@ export default function ExtendedSortComparator() { { field: 'nameAdmin', headerName: 'Name', - valueGetter: (params: GridValueGetterParams) => ({ - name: params.row.name, - isAdmin: params.row.isAdmin, + valueGetter: (value, row) => ({ + name: row.name, + isAdmin: row.isAdmin, }), - valueFormatter: (params) => { - const value = params.value as NameAdminCellValue; + valueFormatter: (value: NameAdminCellValue) => { if (value.isAdmin) { return `${value.name} (admin)`; } diff --git a/docs/data/data-grid/sorting/FullyCustomSortComparator.js b/docs/data/data-grid/sorting/FullyCustomSortComparator.js index ecd8c8a0112a..be364bee8b75 100644 --- a/docs/data/data-grid/sorting/FullyCustomSortComparator.js +++ b/docs/data/data-grid/sorting/FullyCustomSortComparator.js @@ -17,7 +17,7 @@ export default function FullyCustomSortComparator() { () => [ { field: 'dateCreatedCustom', - valueGetter: (params) => params.row.dateCreated, + valueGetter: (value, row) => row.dateCreated, headerName: 'Created on', width: 180, type: 'date', diff --git a/docs/data/data-grid/sorting/FullyCustomSortComparator.tsx b/docs/data/data-grid/sorting/FullyCustomSortComparator.tsx index 22a7ee744160..1ffd85dad444 100644 --- a/docs/data/data-grid/sorting/FullyCustomSortComparator.tsx +++ b/docs/data/data-grid/sorting/FullyCustomSortComparator.tsx @@ -18,7 +18,7 @@ export default function FullyCustomSortComparator() { () => [ { field: 'dateCreatedCustom', - valueGetter: (params) => params.row.dateCreated, + valueGetter: (value, row) => row.dateCreated, headerName: 'Created on', width: 180, type: 'date', diff --git a/docs/data/data-grid/sorting/GetSortComparator.js b/docs/data/data-grid/sorting/GetSortComparator.js new file mode 100644 index 000000000000..53ff478e3289 --- /dev/null +++ b/docs/data/data-grid/sorting/GetSortComparator.js @@ -0,0 +1,47 @@ +import * as React from 'react'; +import { DataGrid, gridStringOrNumberComparator } from '@mui/x-data-grid'; +import { + randomQuantity, + randomId, + randomCommodity, +} from '@mui/x-data-grid-generator'; + +const columns = [ + { field: 'commodity', headerName: 'Commodity', width: 200 }, + { + type: 'number', + field: 'quantity', + headerName: 'Quantity', + getSortComparator: (sortDirection) => { + const modifier = sortDirection === 'desc' ? -1 : 1; + return (value1, value2, cellParams1, cellParams2) => { + if (value1 === null) { + return 1; + } + if (value2 === null) { + return -1; + } + return ( + modifier * + gridStringOrNumberComparator(value1, value2, cellParams1, cellParams2) + ); + }; + }, + }, +]; + +const rows = [ + { id: randomId(), commodity: randomCommodity(), quantity: randomQuantity() }, + { id: randomId(), commodity: randomCommodity(), quantity: null }, + { id: randomId(), commodity: randomCommodity(), quantity: randomQuantity() }, + { id: randomId(), commodity: randomCommodity(), quantity: null }, + { id: randomId(), commodity: randomCommodity(), quantity: randomQuantity() }, +]; + +export default function GetSortComparator() { + return ( +{v}
+ This guide describes the changes needed to migrate the Data Grid from v6 to v7.
- +This is a reference guide for upgrading `@mui/x-data-grid` from v6 to v7. +To read more about the changes from the new major, check out [the blog post about the release of MUI X v7](https://mui.com/blog/mui-x-v7-beta/). ## Start using the new release -In `package.json`, change the version of the data grid package to `next`. +In `package.json`, change the version of the data grid package to `^7.0.0`. ```diff -"@mui/x-data-grid": "6.x.x", -+"@mui/x-data-grid": "next", ++"@mui/x-data-grid": "^7.0.0", +-"@mui/x-data-grid-pro": "6.x.x", ++"@mui/x-data-grid-pro": "^7.0.0", +-"@mui/x-data-grid-premium": "6.x.x", ++"@mui/x-data-grid-premium": "^7.0.0", ``` Since v7 is a major release, it contains changes that affect the public API. @@ -27,10 +30,26 @@ Described below are the steps needed to migrate from v6 to v7. ## Update `@mui/material` package -To have the option of using the latest API from `@mui/material`, the package peer dependency version has been updated to `^5.15.0`. +To have the option of using the latest API from `@mui/material`, the package peer dependency version has been updated to `^5.15.14`. It is a change in minor version only, so it should not cause any breaking changes. Please update your `@mui/material` package to this or a newer version. +## Update the license package + +If you're using the commercial version of the Data Grid ([Pro](/x/introduction/licensing/#pro-plan) and [Premium](/x/introduction/licensing/#premium-plan) plans), you need to update the import path: + +```diff +-import { LicenseInfo } from '@mui/x-license-pro'; ++import { LicenseInfo } from '@mui/x-license'; +``` + +If you have `@mui/x-license-pro` in the `dependencies` section of your `package.json`, rename and update the license package to the latest version: + +```diff +-"@mui/x-license-pro": "6.x.x", ++"@mui/x-license": "^7.0.0", +``` + ## Run codemods The `preset-safe` codemod will automatically adjust the bulk of your code to account for breaking changes in v7. @@ -40,13 +59,14 @@ You can either run it on a specific file, folder, or your entire codebase when c ```bash // Data Grid specific -npx @mui/x-codemod@next v7.0.0/data-grid/preset-safeThis guide describes the changes needed to migrate the Date and Time Pickers from v6 to v7.
## Introduction -TBD +This is a reference guide for upgrading `@mui/x-date-pickers` from v6 to v7. +To read more about the changes from the new major, check out [the blog post about the release of MUI X v7](https://mui.com/blog/mui-x-v7-beta/). ## Start using the new release -In `package.json`, change the version of the date pickers package to `next`. +In `package.json`, change the version of the date pickers package to `^7.0.0`. ```diff -"@mui/x-date-pickers": "6.x.x", -+"@mui/x-date-pickers": "next", ++"@mui/x-date-pickers": "^7.0.0", ``` Since `v7` is a major release, it contains changes that affect the public API. @@ -27,10 +26,26 @@ Described below are the steps needed to migrate from v6 to v7. ## Update `@mui/material` package -To have the option of using the latest API from `@mui/material`, the package peer dependency version has been updated to `^5.15.0`. +To have the option of using the latest API from `@mui/material`, the package peer dependency version has been updated to `^5.15.14`. It is a change in minor version only, so it should not cause any breaking changes. Please update your `@mui/material` package to this or a newer version. +## Update the license package + +If you're using the commercial version of the Pickers ([Pro](/x/introduction/licensing/#pro-plan) plan), you need to update the import path: + +```diff +-import { LicenseInfo } from '@mui/x-license-pro'; ++import { LicenseInfo } from '@mui/x-license'; +``` + +If you have `@mui/x-license-pro` in the `dependencies` section of your `package.json`, rename and update the license package to the latest version: + +```diff +-"@mui/x-license-pro": "6.x.x", ++"@mui/x-license": "^7.0.0", +``` + ## Run codemods The `preset-safe` codemod will automatically adjust the bulk of your code to account for breaking changes in v7. You can run `v7.0.0/pickers/preset-safe` targeting only Date and Time Pickers or `v7.0.0/preset-safe` to target Data Grid as well. @@ -39,10 +54,10 @@ You can either run it on a specific file, folder, or your entire codebase when c ```bash // Date and Time Pickers specific -npx @mui/x-codemod@next v7.0.0/pickers/preset-safeThis guide describes the changes needed to migrate the Tree View from v6 to v7.
## Introduction -TBD +This is a reference guide for upgrading `@mui/x-tree-view` from v6 to v7. +To read more about the changes from the new major, check out [the blog post about the release of MUI X v7](https://mui.com/blog/mui-x-v7-beta/). -## Start using the alpha release +## Start using the new release -In `package.json`, change the version of the tree view package to `next`. +In `package.json`, change the version of the tree view package to `^7.0.0`. ```diff -"@mui/x-tree-view": "6.x.x", -+"@mui/x-tree-view": "next", ++"@mui/x-tree-view": "^7.0.0", ``` ## Update `@mui/material` package -To have the option of using the latest API from `@mui/material`, the package peer dependency version has been updated to `^5.15.0`. +To have the option of using the latest API from `@mui/material`, the package peer dependency version has been updated to `^5.15.14`. It is a change in minor version only, so it should not cause any breaking changes. Please update your `@mui/material` package to this or a newer version. @@ -32,6 +31,45 @@ Please update your `@mui/material` package to this or a newer version. Since `v7` is a major release, it contains changes that affect the public API. These changes were done for consistency, improved stability and to make room for new features. +### Drop the legacy bundle + +The support for IE11 has been removed from all MUI X packages. +The `legacy` bundle that used to support old browsers like IE11 is no longer included. + +:::info +If you need support for IE11, you will need to keep using the latest version of the `v6` release. +::: + +### ✅ Rename `nodeId` to `itemId` + +The required `nodeId` prop used by the `TreeItem` has been renamed to `itemId` for consistency: + +```diff +A Tree View widget presents a hierarchical list.
- -Tree views can be used to represent a file system navigator displaying folders and files, an item representing a folder can be expanded to reveal the contents of the folder, which may be files, folders, or both. +The Tree View component lets users navigate hierarchical lists of data with nested levels that can be expanded and collapsed.
{{"component": "modules/components/ComponentLinkHeader.js"}} ## Available components -There are two versions of the Tree View available. +The MUI X Tree View package exposes two different versions of the component: + +### Simple Tree View -### SimpleTreeView +```jsx +import { SimpleTreeView } from '@mui/x-tree-view/SimpleTreeView'; +``` -The `SimpleTreeView` component receives its items as JSX children. -It is designed for simple use-cases where the items are hardcoded. +The simple version of the Tree View component receives its items as JSX children. +This is the recommended version for hardcoded items. {{"demo": "BasicSimpleTreeView.js"}} -:::warning -Most new advanced features won't be available on this component. -If you are waiting for features like editing or virtualization, you should use `RichTreeView` instead. -::: +### Rich Tree View -### RichTreeView +```jsx +import { RichTreeView } from '@mui/x-tree-view/RichTreeView'; +``` -The `RichTreeView` component receives its items through the `items` prop. -It is designed for more advanced use-cases where the items are dynamically loaded from a data source. +The rich version of the Tree View component receives its items dynamically from an external data source. +This is the recommended version for larger trees, as well as those that require more advanced features like editing and virtualization. {{"demo": "BasicRichTreeView.js"}} + +:::info +At the moment, the Simple and Rich Tree Views are similar in terms of feature support. But as the component grows, you can expect to see the more advanced ones appear primarily on the Rich Tree View. +::: + +### Tree Item components + +The `@mui/x-tree-view` package exposes two different components to define your tree items: + +- `TreeItem` +- `TreeItem2` + +#### `TreeItem` + +This is the long-standing component that is very similar to the one used in previous versions (`@mui/x-tree-view@6` and `@mui/lab`). + +When using `SimpleTreeView`, +you can import it from `@mui/x-tree-view/TreeItem` and use it as a child of the `SimpleTreeView` component: + +```tsx +import { SimpleTreeView } from '@mui/x-tree-view/SimpleTreeView'; +import { TreeItem } from '@mui/x-tree-view/TreeItem'; + +export default function App() { + return ( +Learn how to customize the Rich Tree View component.
+ +## Basics + +### Custom icons + +Use the `collapseIcon` slot, the `expandIcon` slot and the `defaultEndIcon` prop to customize the Tree View icons. +The demo below shows how to add icons using both an existing icon library, such as [Material Icons](/material-ui/material-icons/), and creating an icon from scratch using Material UI's [SVG Icon component](/material-ui/icons/#svgicon). + +{{"demo": "CustomIcons.js", "defaultCodeOpen": false}} + +### Custom toggle animations + +Use the `groupTransition` slot on the `TreeItem` to pass a component that handles your animation. + +The demo below is animated using Material UI's [Collapse](/material-ui/transitions/#collapse) component together with the [react-spring](https://www.react-spring.dev/) library. + +{{"demo": "CustomAnimation.js", "defaultCodeOpen": false}} + +### Custom styling + +Use `treeItemClasses` to target internal elements of the Tree Item component and change their styles. + +{{"demo": "CustomStyling.js"}} + +### Custom label + +:::warning +This example is built using the new `TreeItem2` component +which adds several slots to modify the content of the Tree Item or change its behavior. + +You can learn more about this new component in the [Overview page](/x/react-tree-view/#tree-item-components). +::: + +Use the `label` slot to customize the Tree Item label or to replace it with a custom component. + +The `slotProps` prop allows you to pass props to the label component. +The demo below shows how to pass an `id` attribute to the Tree Item label: + +{{"demo": "LabelSlotProps.js", "defaultCodeOpen": false }} + +The `slots` prop allows you to replace the default label with your own component: +The demo below shows how to add a tooltip on the Tree Item label: + +{{"demo": "LabelSlots.js", "defaultCodeOpen": false}} + +### Headless API + +Use the `useTreeItem2` hook to create your own component. +The demo below shows how to add an avatar and custom typography elements. + +{{"demo": "CustomContentTreeView.js", "defaultCodeOpen": false}} + +## Common examples + +### Limit expansion to icon container + +The demo below shows how to trigger the expansion interaction just by clicking on the icon container instead of the whole Tree Item surface. + +{{"demo": "IconExpansionTreeView.js", "defaultCodeOpen": false}} diff --git a/docs/data/tree-view/rich-tree-view/expansion/ControlledExpansion.js b/docs/data/tree-view/rich-tree-view/expansion/ControlledExpansion.js index 063312287ef5..bcc49a4c33c4 100644 --- a/docs/data/tree-view/rich-tree-view/expansion/ControlledExpansion.js +++ b/docs/data/tree-view/rich-tree-view/expansion/ControlledExpansion.js @@ -33,30 +33,30 @@ const MUI_X_PRODUCTS = [ }, ]; -const getAllItemWithChildrenNodeIds = () => { - const nodeIds = []; - const registerNodeId = (item) => { +const getAllItemsWithChildrenItemIds = () => { + const itemIds = []; + const registerItemId = (item) => { if (item.children?.length) { - nodeIds.push(item.id); - item.children.forEach(registerNodeId); + itemIds.push(item.id); + item.children.forEach(registerItemId); } }; - MUI_X_PRODUCTS.forEach(registerNodeId); + MUI_X_PRODUCTS.forEach(registerItemId); - return nodeIds; + return itemIds; }; export default function ControlledExpansion() { - const [expandedNodes, setExpandedNodes] = React.useState([]); + const [expandedItems, setExpandedItems] = React.useState([]); - const handleExpandedNodesChange = (event, nodeIds) => { - setExpandedNodes(nodeIds); + const handleExpandedItemsChange = (event, itemIds) => { + setExpandedItems(itemIds); }; const handleExpandClick = () => { - setExpandedNodes((oldExpanded) => - oldExpanded.length === 0 ? getAllItemWithChildrenNodeIds() : [], + setExpandedItems((oldExpanded) => + oldExpanded.length === 0 ? getAllItemsWithChildrenItemIds() : [], ); }; @@ -64,14 +64,14 @@ export default function ControlledExpansion() {Learn how to focus Tree View items.
+ +## Focus a specific item + +You can use the the `apiRef.focusItem` method to focus a specific item. +This methods receives two parameters: `event` and `itemId`. + +:::success +To use the `apiRef` object, you need to initialize it using the `useTreeViewApiRef` hook as follows: + +```tsx +const apiRef = useTreeViewApiRef(); + +returnLearn how to customize the simple version of the Tree View component.
+Learn how to customize the Simple Tree View component.
## Basics @@ -22,7 +22,7 @@ The demo below shows how to add icons using both an existing icon library, such ### Custom toggle animations -Use the `TransitionComponent` prop on the `TreeItem` to pass a component that handles your animation. +Use the `groupTransition` slot on the `TreeItem` to pass a component that handles your animation. The demo below is animated using Material UI's [Collapse](/material-ui/transitions/#collapse) component together with the [react-spring](https://www.react-spring.dev/) library. @@ -34,23 +34,51 @@ Use `treeItemClasses` to target internal elements of the Tree Item component and {{"demo": "CustomStyling.js"}} -### Adding custom content +### Custom label -Use the `ContentComponent` prop and the `useTreeItemState` hook to replace the Tree Item content with an entirely custom component. +:::warning +This example is built using the new `TreeItem2` component +which adds several slots to modify the content of the Tree Item or change its behavior. + +You can learn more about this new component in the [Overview page](/x/react-tree-view/#tree-item-components). +::: + +Use the `label` slot to customize the Tree Item label or to replace it with a custom component. + +The `slotProps` prop allows you to pass props to the label component. +The demo below shows how to pass an `id` attribute to the Tree Item label: + +{{"demo": "LabelSlotProps.js", "defaultCodeOpen": false }} + +The `slots` prop allows you to replace the default label with your own component: +The demo below shows how to add a tooltip on the Tree Item label: + +{{"demo": "LabelSlots.js", "defaultCodeOpen": false}} + +### Headless API + +Use the `useTreeItem2` hook to create your own component. The demo below shows how to add an avatar and custom typography elements. -{{"demo": "CustomContentTreeView.js"}} +{{"demo": "CustomContentTreeView.js", "defaultCodeOpen": false}} ## Common examples ### Connection border -Target the `treeItemClasses.group` class to add connection borders between the Tree View items. +Target the `treeItemClasses.groupTransition` class to add connection borders between the Tree View items. {{"demo": "BorderedTreeView.js", "defaultCodeOpen": false}} ### Limit expansion to icon container +:::warning +This example is built using the new `TreeItem2` component +which adds several slots to modify the content of the Tree Item or change its behavior. + +You can learn more about this new component in the [Overview page](/x/react-tree-view/#tree-item-components). +::: + The demo below shows how to trigger the expansion interaction just by clicking on the icon container instead of the whole Tree Item surface. {{"demo": "IconExpansionTreeView.js", "defaultCodeOpen": false}} @@ -63,7 +91,17 @@ The demo below shows many of the previous customization examples brought togethe ### Gmail clone +:::warning +This example is built using the new `TreeItem2` component +which adds several slots to modify the content of the Tree Item or change its behavior. + +You can learn more about this new component in the [Overview page](/x/react-tree-view/#tree-item-components). +::: + Google's Gmail side nav is potentially one of the web's most famous tree view components. The demo below shows how to replicate it. +The Gmail sidebar is one of the most well known examples of a tree view. +The demo below shows how to recreate it with the Tree View component: + {{"demo": "GmailTreeView.js"}} diff --git a/docs/data/tree-view/simple-tree-view/expansion/ControlledExpansion.js b/docs/data/tree-view/simple-tree-view/expansion/ControlledExpansion.js index b9a5851e126d..a11d874a4659 100644 --- a/docs/data/tree-view/simple-tree-view/expansion/ControlledExpansion.js +++ b/docs/data/tree-view/simple-tree-view/expansion/ControlledExpansion.js @@ -5,14 +5,14 @@ import { SimpleTreeView } from '@mui/x-tree-view/SimpleTreeView'; import { TreeItem } from '@mui/x-tree-view/TreeItem'; export default function ControlledExpansion() { - const [expandedNodes, setExpandedNodes] = React.useState([]); + const [expandedItems, setExpandedItems] = React.useState([]); - const handleExpandedNodesChange = (event, nodeIds) => { - setExpandedNodes(nodeIds); + const handleExpandedItemsChange = (event, itemIds) => { + setExpandedItems(itemIds); }; const handleExpandClick = () => { - setExpandedNodes((oldExpanded) => + setExpandedItems((oldExpanded) => oldExpanded.length === 0 ? [ 'grid', @@ -35,28 +35,28 @@ export default function ControlledExpansion() {Handle how users can expand items.
+Learn how to handle expanding and collapsing Tree View items.
## Controlled expansion -Use the `expandedNodes` prop to control the expanded items. - -You can use the `onExpandedNodesChange` prop to listen to changes in the expanded items and update the prop accordingly. +Use the `expandedItems` prop to control the expanded items. +You can also use the `onExpandedItemsChange` prop to listen to changes in the expanded items and update the prop accordingly. {{"demo": "ControlledExpansion.js"}} :::info -- The expansion is **controlled** when its parent manages it by providing a `expandedNodes` prop. -- The expansion is **uncontrolled** when it is managed by the component's own internal state. This state can be initialized using the `defaultExpandedNodes` prop. +- The expansion is **controlled** when its parent manages it by providing a `expandedItems` prop. +- The expansion is **uncontrolled** when it is managed by the component's own internal state. This state can be initialized using the `defaultExpandedItems` prop. Learn more about the _Controlled and uncontrolled_ pattern in the [React documentation](https://react.dev/learn/sharing-state-between-components#controlled-and-uncontrolled-components). ::: -## Track node expansion change +## Track item expansion change -Use the `onNodeExpansionToggle` prop if you want to react to a node expansion change: +Use the `onItemExpansionToggle` prop to trigger an action upon an item being expanded. -{{"demo": "TrackNodeExpansionToggle.js"}} +{{"demo": "TrackItemExpansionToggle.js"}} diff --git a/docs/data/tree-view/simple-tree-view/focus/FocusedSimpleTreeView.js b/docs/data/tree-view/simple-tree-view/focus/FocusedSimpleTreeView.js new file mode 100644 index 000000000000..9e12cc3ce060 --- /dev/null +++ b/docs/data/tree-view/simple-tree-view/focus/FocusedSimpleTreeView.js @@ -0,0 +1,40 @@ +import * as React from 'react'; +import Box from '@mui/material/Box'; +import Button from '@mui/material/Button'; +import { SimpleTreeView } from '@mui/x-tree-view/SimpleTreeView'; +import { TreeItem } from '@mui/x-tree-view/TreeItem'; +import { useTreeViewApiRef } from '@mui/x-tree-view/hooks/useTreeViewApiRef'; + +export default function FocusedSimpleTreeView() { + const apiRef = useTreeViewApiRef(); + const handleButtonClick = (event) => { + apiRef.current?.focusItem(event, 'pickers'); + }; + + return ( +Learn how to focus Tree View items.
+ +## Focus a specific item + +You can use the the `apiRef.focusItem` method to focus a specific item. +This methods receives two parameters: `event` and `itemId`. + +:::success +To use the `apiRef` object, you need to initialize it using the `useTreeViewApiRef` hook as follows: + +```tsx +const apiRef = useTreeViewApiRef(); + +return