Switch
Binary setting with visible label; changing setting is not implicit business submission.
Use the web element directly without the semantic runtime.
A registered presentation adapter can bind this component to host-owned meaning and state.
The standard recipe resolver does not select this component automatically.
Import and live example#
One enabled live-updates switch in the on state.
Interactive preview requires JavaScript.
View the complete example source
import {registerAeliqoElements} from "@varendo/web";
import {
AeliqoCheckboxElement,
AeliqoComboboxElement,
AeliqoDateFieldElement,
AeliqoDateRangeElement,
AeliqoFieldGroupElement,
AeliqoFileInputElement,
AeliqoFormElement,
AeliqoNumberFieldElement,
AeliqoRadioGroupElement,
AeliqoSearchFieldElement,
AeliqoSelectElement,
AeliqoSliderElement,
AeliqoSwitchElement,
AeliqoTextAreaElement,
AeliqoTextFieldElement,
type AeliqoOption,
} from "@varendo/web/inputs";
const options: readonly AeliqoOption[] = [
{value: "ada", label: "Ada Lovelace", description: "Research"},
{value: "grace", label: "Grace Hopper", description: "Product"},
{value: "lin", label: "Lin Chen", disabled: true},
];
registerAeliqoElements();
const host = document.querySelector<HTMLElement>("#aeliqo-example") ?? (() => {
const created = document.createElement("div");
created.id = "aeliqo-example";
(document.body ?? document.documentElement).append(created);
return created;
})();
function createCatalogRoot(container: HTMLElement): HTMLElement {
const root = document.createElement("div");
root.dataset.catalogSourceRoot = "true";
root.style.display = "grid";
root.style.gap = "12px";
container.append(root);
return root;
}
function createCatalogElement<T extends HTMLElement>(tagName: string, container: HTMLElement): T {
const element = document.createElement(tagName) as T;
element.setAttribute("data-aeliqo-theme", "light");
container.append(element);
return element;
}
function appendSlottedText(root: HTMLElement, slot: string, textContent: string): void {
const content = document.createElement("span");
content.slot = slot;
content.textContent = textContent;
root.append(content);
}
const root = createCatalogRoot(host);
(((root) => {
const element = createCatalogElement<AeliqoSwitchElement>("aeliqo-switch", root);
element.label = "Live updates";
element.name = "live";
element.checked = true;
}))(root);
Purpose#
A labelled on/off setting built on a native checkbox with switch semantics. The host can set
checked; toggling updates that local property and emits a typed change. It is not an implicit
submission, and the host decides whether to persist the setting.
When to use it#
- A preference turns on or off with immediate visible effect.
- The setting is binary; there is no mixed state.
- The label should stay short and always visible.
When to use a different component#
- Use Checkbox for a form choice or a state that can be mixed.
- Use Form when the change submits alongside other fields.
Properties and defaults#
The switch communicates a boolean preference; the host decides whether to start live work.
| Property | Use and ownership | Declared type | Initial value |
|---|---|---|---|
label | Provides the visible label and accessible name for the component. | string | '' |
description | Provides supporting text associated with the control or value. | string | '' |
error | Provides the current validation or operation error associated with the control. | string | '' |
required | Marks the control as required for validation and native accessibility semantics. | boolean | false |
disabled | Prevents user interaction while keeping the control and its current value visible. | boolean | false |
readOnly | Keeps the current value focusable and readable while preventing edits. | boolean | false |
name | Provides the stable form or action name used by the host to identify this control. | string | '' |
autocomplete | Passes an autocomplete purpose to the native input so browsers can offer an appropriate saved value. | string | 'off' |
locale | Selects locale-sensitive formatting and parsing behavior. | string | 'en-US' |
validationState | Controls the current idle, pending, valid, or invalid validation state. | AeliqoValidationState | 'idle' |
validator | Runs host-provided synchronous validation for a proposed input value. | AeliqoValidator<T> | undefined | undefined |
checked | Controls the current boolean state. Update it from accepted change proposals. | boolean | false |
defaultChecked | Provides the initial uncontrolled checked. Later updates come from component interaction. | boolean | false |
indeterminate | Enables or disables indeterminate as explicit host-controlled state. | boolean | false |
value | Controls the current value. Apply accepted user proposals back to this property. | string | 'on' |
Events#
| Event | Payload | Emitted | Application responsibility |
|---|---|---|---|
aeliqo-input-change | {source, value, composing?} | Whenever the user proposes a draft value change. | Validate or store the draft and reassign controlled value or checked state. |
aeliqo-validation | {source, state, message} | When validation enters pending, valid, or invalid state. | Merge the result with application validation and display authoritative errors. |
Events cross the component boundary as user proposals. Validate their detail and current authority before applying a business effect.
Listen for aeliqo-input-change
const element = document.querySelector('aeliqo-switch');<p>element?.addEventListener('aeliqo-input-change', (event) => {
const proposal = (event as CustomEvent<unknown>).detail;
// Validate the proposal, update host state, then assign controlled properties.
applyProposal(proposal);
});Listen for aeliqo-validation
const element = document.querySelector('aeliqo-switch');</p>
<p>element?.addEventListener('aeliqo-validation', (event) => {
const proposal = (event as CustomEvent<unknown>).detail;
// Validate the proposal, update host state, then assign controlled properties.
applyProposal(proposal);
});States and failure handling#
Relevant states:
- ready
- disabled
- invalid
- pending
Expected result: The boolean preference is keyboard operable and emitted as a typed change proposal.
Changing checked or replacing validator cancels validation for the
previous value and clears its validator-owned error. An independently supplied
host error survives the change. Late results after a reset or disconnect are
ignored.
Keyboard, focus, and accessibility#
Keyboard behavior:
- Tab
- Space
Exposed semantics:
- aria-checked
- aria-describedby
- aria-hidden
- aria-invalid
- aria-readonly
- input
- role
Responsive behavior#
Keep explanatory copy outside the short switch label. Preserve the control target when its parent narrows.
Style hooks#
- Shadow parts:
description,error,field,input,label,pending - Varendo design tokens referenced:
--aeliqo-color-accent,--aeliqo-color-canvas,--aeliqo-color-muted,--aeliqo-control-min-target,--aeliqo-motion-duration-fast,--aeliqo-space-8
Related components#
Generated TypeScript declaration#
View generated declaration
export declare class AeliqoSwitchElement extends AeliqoCheckboxElement {
protected render(): import("lit").TemplateResult<1>;
static readonly styles: import("lit").CSSResult[];
}Version#
This page documents the Varendo 0.6 component contract.
