LoadingOverlay

Overlay over given container with centered Loader
Import

Usage

Use LoadingOverlay to overlay element to disable interactions and indicate loading state. Note that elements under overlay are still focusable with keyboard. Remember to add additional logic to handle this case.

Overlay had absolute position and will take 100% of width and height of nearest parent container with relative position. Use it when you need to disable user interactions and indicate loading state, for example, while form is submitting.

visible is the only required prop, if it set to false component will not render anything.

import { useState } from 'react';
import { LoadingOverlay, Button, Group } from '@mantine/core';
function Demo() {
const [visible, setVisible] = useState(false);
// Note that position: relative is required
return (
<>
<div style={{ width: 400, position: 'relative' }}>
<LoadingOverlay visible={visible} />
{/* ...other content */}
</div>
<Group position="center">
<Button onClick={() => setVisible((v) => !v)}>Toggle overlay</Button>
</Group>
</>
);
}

Transition duration

You can change appear and disappear animations duration by passing transitionDuration prop:

// 500ms animations
<LoadingOverlay transitionDuration={500} />
// disable animations
<LoadingOverlay transitionDuration={0} />

Loader and Overlay props

LoadingOverlay is built using Overlay and Loader components. You can change all props of Loader component, opacity and color of Overlay:

import { LoadingOverlay } from '@mantine/core';
function Demo() {
return (
<LoadingOverlay
loaderProps={{ size: 'sm', color: 'pink', variant: 'bars' }}
overlayOpacity={0.3}
overlayColor="#c5c5c5"
/>
);
}

Configure default loader

You can configure default loader in MantineProvider, it will be used in Loader and LoadingOverlay components by default:

import { MantineProvider } from '@mantine/core';
function Demo() {
return (
<MantineProvider theme={{ loader: 'bars' }}>
<YourApp />
</MantineProvider>
);
}

Custom loader

You can use any other loader with LoadingOverlay by setting loader prop:

import { DEFAULT_THEME, LoadingOverlay } from '@mantine/core';
const customLoader = (
<svg
width="54"
height="54"
viewBox="0 0 38 38"
xmlns="http://www.w3.org/2000/svg"
stroke={DEFAULT_THEME.colors.blue[6]}
>
<g fill="none" fillRule="evenodd">
<g transform="translate(1 1)" strokeWidth="2">
<circle strokeOpacity=".5" cx="18" cy="18" r="18" />
<path d="M36 18c0-9.94-8.06-18-18-18">
<animateTransform
attributeName="transform"
type="rotate"
from="0 18 18"
to="360 18 18"
dur="1s"
repeatCount="indefinite"
/>
</path>
</g>
</g>
</svg>
);
function Demo() {
return <LoadingOverlay loader={customLoader} visible />;
}