Toggle
An on/off switch for a setting that takes effect at once.
<arc-toggle>Overview
Toggle is an on/off switch for a setting that takes effect at once, such as turning on notifications. Use a checkbox when the choice waits for the reader to submit a form.
It renders with role="switch" and keeps aria-checked in step with checked. The thumb slides across in 300ms, and when the toggle is on, the track and thumb glow in the --interactive color.
Set checked once and let the toggle keep its own state, or drive checked from your framework's state. With a name, it takes part in native form submission like a checkbox: it submits "on" when checked and nothing when off.
Guidelines
Do
- Give it a short `label` that says what it controls
- Stack related toggles in a vertical list
- Set `checked` on the options that should start on
- Add helper text when the label alone could be read two ways
Don't
- Don't put a toggle inside a clickable card or button. One click would trigger both
- Don't disable a toggle without saying why the option is unavailable
- Don't put more than 8 to 10 toggles in one group. Split them into sections
- Don't use toggles for mutually exclusive options. Use RadioGroup
Features
- Space or Enter toggles it from the keyboard. Enter inside a form toggles it and does not submit the form
- Clicking the `label` text toggles it too
- A disabled toggle is dimmed and ignores pointer and keyboard input
- Fires `arc-change` with `detail.checked`
Preview
Usage
Its events and state need JavaScript, so use the Web Component or a framework wrapper for those.
<arc-toggle label="Email notifications" checked></arc-toggle>
<arc-toggle label="Push notifications"></arc-toggle>
<arc-toggle label="Marketing emails"></arc-toggle>import { Toggle } from '@arclux/arc-ui-react';
export default function Example() {
return (
<>
<Toggle label="Email notifications" checked />
<Toggle label="Push notifications" />
<Toggle label="Marketing emails" />
</>
);
}<script setup>
import { Toggle } from '@arclux/arc-ui-vue';
</script>
<template>
<Toggle label="Email notifications" checked />
<Toggle label="Push notifications" />
<Toggle label="Marketing emails" />
</template><script>
import { Toggle } from '@arclux/arc-ui-svelte';
</script>
<Toggle label="Email notifications" checked />
<Toggle label="Push notifications" />
<Toggle label="Marketing emails" />import { Component } from '@angular/core';
import { Toggle } from '@arclux/arc-ui-angular';
@Component({
imports: [Toggle],
template: `
<arc-toggle label="Email notifications" checked></arc-toggle>
<arc-toggle label="Push notifications"></arc-toggle>
<arc-toggle label="Marketing emails"></arc-toggle>
`,
})
export class SettingsPanel {}import { Toggle } from '@arclux/arc-ui-solid';
export default function Example() {
return (
<>
<Toggle label="Email notifications" checked />
<Toggle label="Push notifications" />
<Toggle label="Marketing emails" />
</>
);
}import { Toggle } from '@arclux/arc-ui-preact';
export default function Example() {
return (
<>
<Toggle label="Email notifications" checked />
<Toggle label="Push notifications" />
<Toggle label="Marketing emails" />
</>
);
}<arc-toggle label="Email notifications" checked></arc-toggle>
<arc-toggle label="Push notifications"></arc-toggle>
<arc-toggle label="Marketing emails"></arc-toggle><!-- Auto-generated by @arclux/prism — do not edit manually -->
<!-- arc-toggle — self-contained, no external CSS needed -->
<div class="arc-toggle">
</div>API
disabledbooleanfalse- Prevents user interaction. The toggle appears at reduced opacity and ignores pointer and keyboard events.
labelstring''- Visible text rendered beside the toggle. Clicking the label also toggles the switch, matching native
<label>behavior. namestring''- Form field name submitted with the toggle value. When set, the component participates in native
<form>submission. checkedbooleanfalse- Whether the toggle is in the on position. When set, the thumb slides to the active side and the track displays the accent glow.
size'sm' | 'md' | 'lg''md'- Controls the toggle size.
formAssociatedbooleantruepropertiesobject{ // flag(), unlike `disabled`. The exclusion in props.js is specifically // about form-associated *platform* semantics: a `disabled` content // attribute that is merely present makes the element actually disabled // per the HTML spec, and formDisabledCallback assigns the property back, // so no converter can win. Neither of these is platform-mapped: // `required` is enforced by _computeValidity() below and `readonly` by // each component's own interaction handlers, so the stock converter buys // nothing here and costs the usual bug: `required="false"` read as true, // blocking submission of a form the author meant to leave optional. // Finding #48's shape, across all 26 form controls at once. required: flag(false), readonly: flag(false), }- Lit merges static properties up the prototype chain, so every consumer
gets these without declaring them.
requiredparticipates in constraint validation below;readonlyreflects for styling and is enforced by each component's interaction handlers (the mixin can't know which gestures mutate state). autoValidatesbooleantrue- Components that run their own constraint-validation logic (pattern checks, range checks) opt out of the automatic required sync by overriding this to false, and own the whole validity flag set instead.
formvalidityvalidationMessagerequiredbooleanfalsereadonlybooleanfalse
Methods
checkValidity()boolean- Whether the control currently satisfies its constraints, per the native
constraint-validation API. Fires
invalidon the element when it does not, and reports nothing to the user. reportValidity()boolean- As checkValidity(), but also shows the browser's validation message against the control when it fails.
Events
arc-changedetail:{ checked: boolean }- Fired when the toggle state changes