|
| 1 | +# Migrating to v6 |
| 2 | + |
| 3 | +<p class="description">This guide explains how and why to migrate from Material UI v5 to v6.</p> |
| 4 | + |
| 5 | +## Start using the alpha release |
| 6 | + |
| 7 | +In the `package.json` file, change the package version from `latest` to `next`. |
| 8 | + |
| 9 | +```diff title="package.json" |
| 10 | +-"@mui/material": "latest", |
| 11 | ++"@mui/material": "next", |
| 12 | +``` |
| 13 | + |
| 14 | +Using `next` ensures your project always uses the latest v6 alpha release. |
| 15 | +Alternatively, you can also target and fix it to a specific version, for example, `6.0.0-alpha.0`. |
| 16 | + |
| 17 | +## Supported browsers |
| 18 | + |
| 19 | +The targets of the default bundle have changed in v6. |
| 20 | + |
| 21 | +The exact versions will be pinned on release from the browserslist query `"> 0.5%, last 2 versions, Firefox ESR, not dead, safari >= 15.4, iOS >= 15.4"`. |
| 22 | + |
| 23 | +The stable bundle supports the following minimum versions: |
| 24 | + |
| 25 | +<!-- #stable-snapshot --> |
| 26 | + |
| 27 | +- Chrome 109 (up from 90) |
| 28 | +- Edge 121 (up from 91) |
| 29 | +- Firefox 115 (up from 78) |
| 30 | +- Safari 15.4 in both macOS and iOS (up from 14 in macOS and 12.5 in iOS) |
| 31 | +- and more (see [.browserslistrc (`stable` entry)](https://github.com/mui/material-ui/blob/v6.0.0/.browserslistrc#L16)) |
| 32 | + |
| 33 | +### Removed support for IE 11 |
| 34 | + |
| 35 | +Support for IE 11 is completely removed, by dropping the legacy bundle and all IE 11 related code. |
| 36 | +This allows us to decrease bundle size and keep the scope manageable. |
| 37 | +If you need to support IE 11, you can use Material UI v5's [legacy bundle](https://v5.mui.com/material-ui/guides/minimizing-bundle-size/#legacy-bundle), but it won't get updates or bug fixes. |
| 38 | + |
| 39 | +## Breaking changes |
| 40 | + |
| 41 | +Since v6 is a new major release, it contains some changes that affect the public API. |
| 42 | +The steps you need to take to migrate from Material UI v5 to v6 are described below. |
| 43 | + |
| 44 | +:::info |
| 45 | +This list is a work in progress. |
| 46 | +Expect updates as new breaking changes are introduced. |
| 47 | +::: |
| 48 | + |
| 49 | +### UMD bundle was removed |
| 50 | + |
| 51 | +To align with React 19's removal of UMD builds, Material UI has also removed its UMD bundle. |
| 52 | +This results in a reduction of the `@mui/material` package size by 2.5MB or 25% of the total package size. |
| 53 | + |
| 54 | +Instead, using ESM-based CDNs such as [esm.sh](https://esm.sh/) is recommended. |
| 55 | +For alternative installation methods, refer to the [CDN documentation](/material-ui/getting-started/installation/#cdn). |
| 56 | + |
| 57 | +### Autocomplete |
| 58 | + |
| 59 | +#### New reason values added to onInputChange |
| 60 | + |
| 61 | +Three new possible values have been added to the `reason` argument in the `onInputChange` callback of the Autocomplete component: |
| 62 | + |
| 63 | +- `"blur"`: like `"reset"` but triggered when the focus is moved off the input. `clearOnBlur` must be `true`. Before, it was treated as `"reset"`. |
| 64 | +- `"selectOption"`: triggered when the input value changes after an option has been selected. Before, it was treated as `"reset"`. |
| 65 | +- `"removeOption"`: triggered in multiple selection when a chip gets removed due to the corresponding option being selected. Before, it was treated as `"reset"`. |
| 66 | + |
| 67 | +These are added on top of the existing ones: `"input"`, `"reset"`, or `"clear"`. |
| 68 | + |
| 69 | +### Chip |
| 70 | + |
| 71 | +The Chip component's behavior has been updated to match the standard behavior of other components like buttons. |
| 72 | +Previously, the Chip component lost focus when the escape button was pressed, which differed from how other button-like components work. |
| 73 | +This issue has been resolved, and the chip component retains focus as expected. |
| 74 | + |
| 75 | +You can provide a custom `onKeyUp` handler to implement the previous behavior. |
| 76 | + |
| 77 | +```js |
| 78 | +import * as React from 'react'; |
| 79 | +import Chip from '@mui/material/Chip'; |
| 80 | + |
| 81 | +export default function ChipExample() { |
| 82 | + const chipRef = React.useRef(null); |
| 83 | + const keyUpHandler = (event) => { |
| 84 | + if (event.key === 'Escape' && chipRef.current) { |
| 85 | + chipRef.current.blur(); |
| 86 | + } |
| 87 | + }; |
| 88 | + return ( |
| 89 | + <Chip |
| 90 | + label="Chip Outlined" |
| 91 | + variant="outlined" |
| 92 | + ref={chipRef} |
| 93 | + onKeyUp={keyUpHandler} |
| 94 | + /> |
| 95 | + ); |
| 96 | +} |
| 97 | +``` |
| 98 | + |
| 99 | +### Grid v2 (Unstable_Grid) |
| 100 | + |
| 101 | +The spacing mechanism was reworked to use the `gap` CSS property. |
| 102 | +This maps better with current layout practices and removes the need for using React Context. |
| 103 | +It brings some breaking changes described in the following sections. |
| 104 | + |
| 105 | +#### The Grid is contained inside parent's padding |
| 106 | + |
| 107 | +Previously, the Grid overflowed its parent. |
| 108 | +In v6, this is fixed: |
| 109 | + |
| 110 | +<img src="/static/material-ui/migration-v5/grid-overflow-change.png" style="width: 814px;" alt="Before and after of the Grid no longer overflowing its parent in v6." width="1628" height="400" /> |
| 111 | + |
| 112 | +This removes the need for the `disableEqualOverflow` prop, so you can remove it: |
| 113 | + |
| 114 | +```diff |
| 115 | + <Grid |
| 116 | +- disableEqualOverflow |
| 117 | + /> |
| 118 | +``` |
| 119 | + |
| 120 | +#### Spacing is no longer considered inside the Grid item's box |
| 121 | + |
| 122 | +Previously, the Grid items included spacing in it's box. |
| 123 | +In v6, this is fixed: |
| 124 | + |
| 125 | +<img src="/static/material-ui/migration-v5/grid-spacing-change.png" style="width: 814px;" alt="Before and after of the Grid items no longer including spacing in their box." width="1628" height="400" /> |
| 126 | + |
| 127 | +:::warning |
| 128 | +Both of these changes might slightly affect your layout. |
| 129 | +Note that the items' position doesn't change. |
| 130 | +We recommend adopting this new behavior and **not trying to replicate the old one**, as this is a more predictable and modern approach. |
| 131 | +::: |
| 132 | + |
| 133 | +### LoadingButton |
| 134 | + |
| 135 | +#### Contents wrapped in a <span> |
| 136 | + |
| 137 | +The `children` passed to the LoadingButton component is now wrapped in a `<span>` tag to avoid [issues](https://github.com/mui/material-ui/issues/27853) when using tools to translate websites. |
| 138 | + |
| 139 | +### useMediaQuery |
| 140 | + |
| 141 | +#### Removed types |
| 142 | + |
| 143 | +The following deprecated types were removed: |
| 144 | + |
| 145 | +- `MuiMediaQueryList`: use `MediaQueryList` (from lib.dom.d.ts) instead. |
| 146 | +- `MuiMediaQueryListEvent`: use `MediaQueryListEvent` (from lib.dom.d.ts) instead. |
| 147 | +- `MuiMediaQueryListListener`: use `(event: MediaQueryListEvent) => void` instead. |
0 commit comments