sdxc

Type to search, or start from one of these:

[ @sdxc/ui/mixins ]

pressToggle

Why JS.

import { pressToggle } from "@sdxc/ui/mixins";

Usage

Flips a ToggleButton's aria-pressed attribute on every click and dispatches PressToggleChangeEvent, keeping the attribute already rendered onto the host as the single source of truth for pressed state.

Signature

pressToggle(): MixinDescriptor<HTMLButtonElement>

Returns a mixin descriptor for a ToggleButton's mix prop.

Examples

<button aria-pressed="false" mix={pressToggle()}>Mute</button>

The events, constants and types its module publishes, each imported from @sdxc/ui/mixins too.

Event

PressToggleChangeEvent

Dispatched on a ToggleButton by pressToggle right after a click flips its aria-pressed attribute, carrying the value so a consumer can persist it or mirror it onto another element without reading it back.

new PressToggleChangeEvent(pressed: boolean)
PropertyTypeDescription
pressedreadonly booleanThe host's aria-pressed value immediately after this click.

Written by Sergio Xalambrí. Follow @sergiodxa for new packages, or sponsor the work.