← All Components
<mth-toggle-button>
Two-state pressable toggle button exposing aria-pressed and :state(pressed).
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-toggle-button>, or toggle Theme, Direction (LTR/RTL), or props above.
Live Variants & States Showcase
variant="outline"Outline
variant="soft"Soft
variant="solid"Solid
variant="ghost"Ghost
pressedActive Toggle
disabledDisabled
Multi-Framework Playground & Snippets
<script type="module" src="@methane-ui/ui/toggle-button"></script>
<mth-toggle-button variant="solid" size="sm">Example</mth-toggle-button>import '@methane-ui/ui/toggle-button';
import '@methane-ui/react';
export function Example() {
return <mth-toggle-button variant="solid" size="sm">Example</mth-toggle-button>;
}<script setup lang="ts">
import '@methane-ui/ui/toggle-button';
</script>
<template>
<mth-toggle-button variant="solid" size="sm">Example</mth-toggle-button>
</template>import { Component, CUSTOM_ELEMENTS_SCHEMA } from '@angular/core';
import '@methane-ui/ui/toggle-button';
import { MthToggleButtonDirective } from '@methane-ui/angular';
@Component({
standalone: true,
schemas: [CUSTOM_ELEMENTS_SCHEMA],
imports: [MthToggleButtonDirective],
template: `<mth-toggle-button variant="solid" size="sm">Example</mth-toggle-button>`,
})
export class ExampleComponent {}<script lang="ts">
import '@methane-ui/ui/toggle-button';
import MthToggleButton from '@methane-ui/svelte/MthToggleButton.svelte';
</script>
<MthToggleButton variant="solid" size="sm">Example</MthToggleButton>Properties & Attributes
| Property | Attribute | Type | Default | Description |
|---|---|---|---|---|
pressed | pressed | boolean | false | Whether the toggle button is currently pressed. |
variant | variant | 'solid' | 'soft' | 'outline' | 'outlined' | 'ghost' | "outline" | Visual style (solid, soft, outline / outlined, or ghost). |
size | size | 'sm' | 'md' | 'lg' | "md" | Control size (sm, md, or lg). |
disabled | disabled | boolean | false | Disables interaction and focus. |
value | value | string | "" | Optional associated value included in mth-change. |
label | label | string | "" | Optional accessible aria-label when using icon-only content. |
Events
| Event | Detail Type | Description |
|---|---|---|
mth-press | { originalEvent: Event; pressed: boolean } | Cancelable event fired when pressed before state toggle. |
mth-change | { pressed: boolean; value: string } | Cancelable event fired when pressed toggles. |
APG Keyboard Matrix
| Key | Direction | When | Expected Behavior |
|---|---|---|---|
| Enter | both | Button is focused and enabled | Toggles pressed state and emits mth-change |
both | Button is focused and enabled | Toggles pressed state and emits mth-change |
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-toggle-button.spec.test.ts |
| states | Exposes ElementInternals CustomStateSet flags: :state(pressed), :state(disabled). | Conformance suite |
| i18n | Routes 1 UI/ARIA strings through @methane-ui/core i18n catalog. | Locale context test |