materialuiupgraded
Version:
Material-UI's workspace package
63 lines (39 loc) • 2.08 kB
Markdown
<p class="description">To change the direction of Material-UI components you must follow the following steps.</p>
Make sure `dir="rtl"` is set on **body**, otherwise native components and portals will break.
Set `direction: 'rtl'` on your custom theme.
We are relying on a JSS plugin to flip the styles: [jss-rtl](https://github.com/alitaheri/jss-rtl).
```sh
npm install jss-rtl
```
Internally, we are dynamically enabling this plugin when `direction: 'rtl'` is set on the theme.
The [CSS-in-JS documentation](/customization/css-in-js/
Once you have created a new JSS instance with the plugin, you need to make it available to all components in the component tree. JSS has a [`JssProvider`](https://github.com/cssinjs/react-jss) component for this:
```jsx
import { create } from 'jss';
import rtl from 'jss-rtl';
import JssProvider from 'react-jss/lib/JssProvider';
import { createGenerateClassName, jssPreset } from '@material-ui/core/styles';
// Configure JSS
const jss = create({ plugins: [...jssPreset().plugins, rtl()] });
// Custom Material-UI class name generator.
const generateClassName = createGenerateClassName();
function RTL(props) {
return (
<JssProvider jss={jss} generateClassName={generateClassName}>
{props.children}
</JssProvider>
);
}
```
*Use the direction toggle button on the top right corner to flip the whole documentation*
{{"demo": "pages/guides/right-to-left/Direction.js"}}
If you want to prevent a specific rule-set from being affected by the `rtl` transformation you can add `flip: false` at the begining:
*Use the direction toggle button on the top right corner to see the effect*
{{"demo": "pages/guides/right-to-left/RtlOptOut.js", "hideEditButton": true}}