skip section navigation

Toggle

Toggle displays a boolean setting as a switch. your app owns checked and updates it in onclick; the component doesn’t flip the value itself.

reminders are off in this demo.

usage

svelte
<script>
	import { Toggle } from '@ciabi/loafkit-ui';
	let reminders = $state(false);
</script>

<Toggle label="Weekly reading reminder" checked={reminders}
	onclick={() => reminders = !reminders} aria-describedby="reminder-detail" />
<p id="reminder-detail">{reminders ? 'reminders are on in this demo.' : 'reminders are off in this demo.'}</p>

give the setting a visible label. if you omit it, provide aria-label and enough surrounding context to explain what changes.

Toggle renders button type="button" with role="switch" and aria-checked. Enter and Space use native button activation. it has no name prop and doesn’t submit a form value by itself. bind your app state into submission or persistence separately.

API reference

Toggle

Component
checked
Default: false

the app-owned on/off state.

label
Default: ''

the visible control name.

disabled
Default: false

makes the control unavailable.

fullWidth
Default: false

fills the available width.

id

unique ID used by the component and its control relationships.

aria-label

an explicit accessible name.

aria-describedby

IDs of supporting descriptions.

aria-invalid

explicit native invalid state.

class
Default: ''

extra classes on the component root.

style

inline styles on the component root.

onclick
Default: async () => {}

receives the button event; update checked in your handler.