apps/mantine.dev/src/pages/styles/rtl.mdx
import { StylesDemos } from '@docs/demos'; import { Layout } from '@/layout'; import { MDX_DATA } from '@/mdx';
export default Layout(MDX_DATA.Rtl);
All Mantine components support right-to-left direction out of the box.
You can preview how components work with RTL direction by clicking the direction control
in the top right corner or pressing Ctrl + Shift + L.
The DirectionProvider component is used to set direction for all components inside it.
It is required to wrap your application with DirectionProvider if you are planning to
either use RTL direction or change direction dynamically.
DirectionProvider supports the following props:
export interface DirectionProviderProps {
/** Your application */
children: React.ReactNode;
/** Direction set as a default value, `ltr` by default */
initialDirection?: 'rtl' | 'ltr';
/** Determines whether direction should be updated on mount based on the `dir` attribute set on the root element (usually the html element), `true` by default */
detectDirection?: boolean;
}
Setup DirectionProvider in your application:
import { DirectionProvider, MantineProvider } from '@mantine/core';
function Demo() {
return (
<DirectionProvider>
<MantineProvider></MantineProvider>
</DirectionProvider>
);
}
It is required to set the dir attribute on the root element of your application, usually the html element.
The DirectionProvider will use its value to set direction on mount if the detectDirection prop is set to true.
Note that this guide does not cover setting the dir attribute for different frameworks – follow your framework's
documentation to learn how to do it.
<!doctype html>
<!-- Set direction attribute on html element -->
<html dir="rtl">
<head></head>
<body></body>
</html>
useDirection returns an object with the following properties:
dir – current directionsetDirection – function to set directiontoggleDirection – function to change direction to the opposite valueYou can use it to create direction control in your application:
<Demo data={StylesDemos.directionControl} />If you have postcss-preset-mantine installed, then you can use the rtl mixin in .css files: