Switch

Capture boolean input from user
Import

Usage

Size
xs
sm
md
lg
xl
Radius
xs
sm
md
lg
xl
Color
<Switch
label="I agree to sell my privacy"
/>

Controlled

import { useState } from 'react';
import { Switch } from '@mantine/core';
function Demo() {
const [checked, setChecked] = useState(false);
return <Switch checked={checked} onChange={(event) => setChecked(event.currentTarget.checked)} />;
}

Inner Labels

<Switch onLabel="ON" offLabel="OFF" />

Get input ref

import { useRef } from 'react';
import { Switch } from '@mantine/core';
function Demo() {
const ref = useRef();
return <Switch ref={ref} />;
}

Accessibility

Switch is a regular input with checkbox type. Provide aria-label if Switch is used without label:

<Switch /> // -> not ok, input is not labeled
<Switch label="I agree to everything" /> // -> ok, input and label is connected
<Switch aria-label="I agree to everything" /> // -> ok, label is not visible but will be announced by screen reader
Build fully functional accessible web applications faster than ever
Feedback
Your feedback is most valuable contribution to the project, please share how you use Mantine, what features are missing and what is done good
Leave feedback