Transition
Install: npm install @mantine/core@9.7.1 @mantine/hooks@9.7.1
Version and compatibility
Pinned Mantine Core 9.7.1 requires React and React DOM ^19.2.0 and matching @mantine/hooks@9.7.1, from the installed npm package's peerDependencies. Do not force it into React 18 or another incompatible version. Explain upgrade impact and agree on a plan with the project owner; do not hide conflicts with --force/--legacy-peer-deps. The native Provider enables theme.respectReducedMotion and uses forceColorScheme for light/dark.
Use case
Apply transition styles to mounted content.
Native props used by this example
These props are extracted from the local typechecked JSX and grouped by their owning native component. This is not an exhaustive prop list; see pinned source signatures and inheritance below.
| Component prop | Explanation |
|---|---|
Button.onClick | Local click handler; replace demo logic with an explicit business action. |
Transition.mounted | Whether transition content should be present. |
Transition.transition | Native transition name/configuration. |
Interaction and state checks
Current scenarios: Default. Check actual behavior after selecting supported disabled/error/read-only scenarios; components without those native states do not receive invented universal props. Verify keyboard focus and exits, then connect changed values through the native callback signature.
Business integration boundary
Apply the render function's style to the animated element. mounted decides presence; the transition does not execute business logic.
Host setup
Install pinned @mantine/core and @mantine/hooks, import @mantine/core/styles.css at the entry and use MantineProvider. The example's theme/variant are JGuang-authored host props, not universal native component APIs; forceColorScheme synchronizes the app theme. Native implementation source is a reading reference: use npm exports rather than copying internal engines. This batch covers Core, not dates/charts/forms extension packages. Detailed upstream prose remains English.
Runnable usage
import { useState } from 'react';
import * as M from '@mantine/core';
import '@mantine/core/styles.css';
function ComponentPreview({ variant = 'Default' }: { variant?: string }) {
const [open, setOpen] = useState(false);
const content = <M.Text>Build something beautiful / 构建美好的界面</M.Text>;
return <div><M.Button onClick={() => setOpen(!open)}>Toggle transition</M.Button><M.Transition mounted={open} transition="fade">{(styles) => <div style={styles}>{content}</div>}</M.Transition></div>;
}
export default function Example({ variant = 'Default', theme = 'light' }: { variant?: string; theme?: 'light' | 'dark' }) {
return <M.MantineProvider forceColorScheme={theme} theme={{ respectReducedMotion: true }}><ComponentPreview variant={variant} /></M.MantineProvider>;
}
Preview states
Default
The example uses the native Mantine API. For supported input demos, change the local variant to Disabled, Invalid or Read only; these are example labels, not new component props. Keep the documented data, controlled values, stores and compound children when adapting the example.
Usage
The Transition component is designed to animate the presence of elements with fixed or absolute positioning, such as dropdowns, modals, or tooltips. Other Mantine components (like Modal and Tooltip) use Transition internally for their animations.
Note that the Transition component is not intended to be a comprehensive solution for all animations. It is a simple utility for animating the presence of elements with fixed or absolute positioning. If you need to implement more complex animations, consider using Motion, React Spring, or other dedicated animation libraries.
Example usage of the Transition component:
import { Transition } from '@mantine/core';
function Demo({ opened }: { opened: boolean }) {
return (
<Transition mounted={opened} transition="fade">
{(styles) => <div style={styles}>Your modal</div>}
</Transition>
);
}
Premade transitions
Mantine includes several premade transitions:
To use one of them, set the transition property to one of these values:
import { Transition } from '@mantine/core';
function Demo({ opened }: { opened: boolean }) {
return (
<Transition
mounted={opened}
transition="fade"
duration={400}
timingFunction="ease"
>
{(styles) => <div style={styles}>Your modal</div>}
</Transition>
);
}
Custom transitions
You can create your own transition. transition is an object with 4 properties:
in– styles for mounted stateout– styles for unmounted statecommon(optional) – styles for both mounted and unmounted statestransitionProperty– properties which participate in the transition
Enter and exit delay
Use the enterDelay and exitDelay props to delay the transition start. Values are in milliseconds:
Reduced motion
Transition respects the prefers-reduced-motion media query and your theme's
respectReducedMotion setting. When reduced motion is preferred, all
transitions complete instantly:
import { createTheme, MantineProvider, Transition } from '@mantine/core';
const theme = createTheme({
respectReducedMotion: true, // default
});
function Demo() {
return (
<MantineProvider theme={theme}>
<Transition mounted transition="fade" duration={400}>
{(styles) => <div style={styles}>Content</div>}
</Transition>
</MantineProvider>
);
}
This improves accessibility for users with vestibular disorders who may experience motion sickness from animations.
Lifecycle callbacks
Use lifecycle callbacks to perform actions at different stages of the transition:
onEnter- Called when enter transition startsonEntered- Called when enter transition completesonExit- Called when exit transition startsonExited- Called when exit transition completes
import { Transition } from '@mantine/core';
function Demo() {
return (
<Transition
mounted
transition="fade"
duration={200}
onEnter={() => console.log('Enter started')}
onEntered={() => console.log('Enter completed')}
onExit={() => console.log('Exit started')}
onExited={() => console.log('Exit completed')}
>
{(styles) => <div style={styles}>Content</div>}
</Transition>
);
}
Keep mounted
By default, the element is unmounted from the DOM when the transition is
complete. Use keepMounted to keep the element mounted with display: none:
import { Transition } from '@mantine/core';
function Demo() {
return (
<Transition mounted={false} keepMounted transition="fade">
{(styles) => <div style={styles}>Content</div>}
</Transition>
);
}
This is useful when you want to:
- Preserve element state during hide/show
- Avoid remounting overhead
- Maintain focus/scroll position
Source-backed parameter reference
Implementation signatures and types are generated from the pinned local source. Optional props, native inherited types, union branches and never exclusions are preserved. A forwardRef implementation's ref is a React reference, not an additional business prop.
Transition({
keepMounted,
keepMountedMode = 'activity',
transition = 'fade',
duration = 250,
exitDuration = duration,
mounted,
children,
timingFunction = 'ease',
onExit,
onEntered,
onEnter,
onExited,
enterDelay,
exitDelay,
}: TransitionProps)
export interface TransitionProps {
/** If set, the element is kept in the DOM when hidden. React 19 `Activity` is used to preserve state while the element is not visible. */
keepMounted?: boolean;
/**
* Controls how the element is hidden when `keepMounted` is set:
* `'activity'` - hidden with React 19 `Activity` component,
* `'display-none'` - hidden with `display: none` styles
* @default 'activity'
*/
keepMountedMode?: 'activity' | 'display-none';
/** Transition name or object */
transition?: MantineTransition;
/** Transition duration in ms @default 250 */
duration?: number;
/** Exit transition duration in ms @default 250 */
exitDuration?: number;
/** Transition timing function @default theme.transitionTimingFunction */
timingFunction?: string;
/** Determines whether component should be mounted to the DOM */
mounted: boolean;
/** Render function with transition styles argument */
children: (styles: React.CSSProperties) => React.JSX.Element;
/** Called when exit transition ends */
onExited?: () => void;
/** Called when exit transition starts */
onExit?: () => void;
/** Called when enter transition starts */
onEnter?: () => void;
/** Called when enter transition ends */
onEntered?: () => void;
/** Delay in ms before enter transition starts */
enterDelay?: number;
/** Delay in ms before exit transition starts */
exitDelay?: number;
}
Destructuring defaults in source
Only defaults written directly in parameter/props destructuring are listed. Conditional expressions, runtime theme and computed values require source inspection; this is not an exhaustive behavior-default list.
// Transition
keepMountedMode = 'activity'
// Transition
transition = 'fade'
// Transition
duration = 250
// Transition
exitDuration = duration
// Transition
timingFunction = 'ease'
Native and external types
External types remain defined by React or native dependencies, not manually expanded into guessed props. The installed version's TypeScript definitions are authoritative.
MantineTransition
React.CSSProperties
React.JSX.Element