← All Components
<mth-switch>
Form-associated binary toggle switch with role="switch", Space/Enter activation, FACE validation, same-root ARIA, and FieldContext.
When NOT to use: Use a lightweight @methane-ui/css layout class instead of a custom element when static CSS suffices.
Live Interactive Preview
Ready · interact with <mth-switch>, or toggle Theme, Direction (LTR/RTL), or props above.
Live Variants & States Showcase
uncheckedEmail notifications
checkedHigh-contrast mode
disabled (off / on)Disabled off Disabled on
Multi-Framework Playground & Snippets
<script type="module" src="@methane-ui/ui/switch"></script>
<mth-switch value="on">Example</mth-switch>import '@methane-ui/ui/switch';
import '@methane-ui/react';
export function Example() {
return <mth-switch value="on">Example</mth-switch>;
}<script setup lang="ts">
import '@methane-ui/ui/switch';
</script>
<template>
<mth-switch value="on">Example</mth-switch>
</template>import { Component, CUSTOM_ELEMENTS_SCHEMA } from '@angular/core';
import '@methane-ui/ui/switch';
import { MthSwitchDirective } from '@methane-ui/angular';
@Component({
standalone: true,
schemas: [CUSTOM_ELEMENTS_SCHEMA],
imports: [MthSwitchDirective],
template: `<mth-switch value="on">Example</mth-switch>`,
})
export class ExampleComponent {}<script lang="ts">
import '@methane-ui/ui/switch';
import MthSwitch from '@methane-ui/svelte/MthSwitch.svelte';
</script>
<MthSwitch value="on">Example</MthSwitch>Properties & Attributes
| Property | Attribute | Type | Default | Description |
|---|---|---|---|---|
checked | checked | boolean | false | Whether the switch is turned on. |
value | value | string | "on" | Form value submitted when checked (defaults to "on"). |
name | name | string | "" | Form submission field name. |
label | label | string | "" | Accessible label when default slot is omitted. |
hint | hint | string | "" | Helper text linked via aria-describedby inside shadow root. |
error | error | string | "" | Explicit custom error message displayed inside shadow root. |
disabled | disabled | boolean | false | Disables switch interaction. |
required | required | boolean | false | Marks switch required for constraint validation. |
readonly | readonly | boolean | false | Prevents toggling while remaining focusable and submittable. |
Events
| Event | Detail Type | Description |
|---|---|---|
mth-change | { checked: boolean; value: string } | Emitted when the switch toggles. |
APG Keyboard Matrix
| Key | Direction | When | Expected Behavior |
|---|---|---|---|
both | focused and not disabled or readonly | toggles switch state | |
| Enter | both | focused and not disabled or readonly | toggles switch state |
Accessibility Checklist
| Category | Requirement | Verified By |
|---|---|---|
| aria | All aria-* IDREFs resolve within the same DOM root (ADR-003). | scanSameRootAria |
| focus | delegatesFocus: true with zero host internals.role (ADR-014). | lint-plugin & spec-compiler |
| contrast | Renders legible borders, focus outlines, and selection indicators under forced-colors: active. | Playwright forced-colors matrix |
| keyboard | Implements all 2 APG keyboard transitions across LTR/RTL. | mth-switch.spec.test.ts |
| states | Exposes ElementInternals CustomStateSet flags: :state(checked), :state(dirty), :state(touched), :state(user-invalid), :state(disabled), :state(required), :state(readonly). | Conformance suite |
| i18n | Routes 3 UI/ARIA strings through @methane-ui/core i18n catalog. | Locale context test |