Skip to main content

Modal

A centered overlay dialog for content that needs the user's attention before they continue. It has no corner close button and closes only through actions inside it.

Base
Mantine + override
Mantine
Import
{ Modal } from '@mantine/core'
Source
src/themes/component-overrides/overlays.ts
src/themes/style-overrides/modal.module.css

Usage​

Modal displays content that temporarily blocks interaction with the rest of the application. Modals are interruptive, so use them with care.

size
React
<Modal opened={opened} onClose={() => setOpened(false)} title="Slett rad" size="md">
<FocusTrap.InitialFocus />
<Text size="md" mb="md">Denne handlingen kan ikke angres.</Text>
<TextInput label="Kommentar" mb="md" />
<Checkbox label="Jeg bekrefter at raden skal slettes" mb="md" />
<Group justify="flex-end">
<Button variant="secondary" onClick={() => setOpened(false)}>Avbryt</Button>
<Button variant="primary" onClick={() => setOpened(false)}>Slett</Button>
</Group>
</Modal>

size​

You can change the modal width by setting the size prop to a predefined size or any valid width, for example, 55% or 50rem. The Modal width cannot exceed 100vw.

Fullscreen​

A fullscreen modal will take the entire screen. Use this carefully because it's hard for users to understand that this is a modal when there is little UI feedback.

Props​

Only what this design system changes. Everything else is Mantine's — read the full props table there.

PropertyTypeAllowed valuesDefaultDescription
withCloseButtonboolean—falseRenders the corner close button. Mantine ships it on.
closeOnClickOutsideboolean—falseCloses the modal when the overlay is clicked. Mantine ships it on.
closeOnEscapeboolean—falseCloses the modal on Escape. Mantine ships it on.
centeredboolean—trueCentres the modal vertically in the viewport rather than anchoring it near the top.
radiusMantineRadius | number—mdRounds the modal corners to 8px, overriding the theme's own global default of sm (5px).
titleReactNode——Heading in the modal header, rendered at the h4 size (20px).
transitionPropsTransitionProps—{ transition: 'pop', duration: 300, timingFunction: 'ease' }Sets how the modal enters and leaves. Dropdowns use a separate, faster transition.

Not touched: trapFocus and returnFocus both keep Mantine's own default of true.

Accessibility​

  • Closing. The corner close button, click on the overlay and Escape are off by default. The modal closes through an action you provide inside it, such as the footer buttons in the demo above.
  • Initial focus. Mantine focuses the first focusable element inside the modal on open. With withCloseButton off, that is the first interactive element in the body or footer. Use FocusTrap.InitialFocus, as in the demo, to start focus on the modal itself instead.
  • Focus is trapped inside the modal while it is open and returned to the trigger element on close (trapFocus, returnFocus — both Mantine defaults, untouched here).