Checkbox

Select multiple independent items or confirm consent.

Live preview
Interact with the component to see results here.
View code
HTML
<sy-checkbox
  checked
  name="notifications"
  value="email"
  id="sample"
>Receive notification emails</sy-checkbox>

Usage guide

#

Use to toggle multiple independent items. Use Radio for one mutually exclusive value.

  1. Write the error message in the error slot.

    Inside the component, add <span slot="error">Error message</span>. You can include links and other guidance as well as text. For inputs supporting noNativeValidity, enable it to show this guidance instead of a browser popup. Switch always displays errors below the component.

  2. Report business rule failures with setCustomError().

    For example, if the server rejects a duplicate value, update the error slot and call setCustomError(). This method does not take a message argument. A custom error also blocks form submission.

  3. Clear the error after resolving it and check whether submission is allowed.

    Use clearCustomError() to clear a business rule error. Required-field and format validation remain active. await checkValidity() returns true or false; reportValidity() validates and displays errors. Read valid named values through FormData on submission.

Select and deselect

Manage selection with checked. Changing one item preserves other selections.

Indeterminate

indeterminate indicates that some child items are selected. Manage the actual checked value in your app.

Feature examples

#

Choose a feature from 10 topics. Explore property settings, method calls, event results, and slot layouts through live examples and code.

Usage examples · Overview

Try the selected example. Topics with multiple configurations let you switch between detailed examples.

View code
HTML
Loading the example.

Property · Checked

See how settings change appearance and behavior.

View code
HTML
Loading the example.

Property · Disabled

See how settings change appearance and behavior.

View code
HTML
Loading the example.

Property · Indeterminate

See how settings change appearance and behavior.

View code
HTML
Loading the example.

Property · Readonly

See how settings change appearance and behavior.

View code
HTML
Loading the example.

Property · Required

See how settings change appearance and behavior.

View code
HTML
Loading the example.

Methods · Set Focus & Blur

Use the example's buttons to call methods and inspect their results.

View code
HTML
Loading the example.

Methods · setCustomError

Use the example's buttons to call methods and inspect their results.

View code
HTML
Loading the example.

Events · Changed

Interact with the component to see event names and payloads in the live preview below.

View code
HTML
Loading the example.

Usage examples · Checkbox helper text

checkboxTitle is passed to the internal checkbox's title. Put visible text in the default slot and additional information in title.

View code
HTML
<sy-checkbox
  checked
  title="Receive project updates by email."
  name="notifications"
  value="email"
  id="sample"
>Receive notification emails</sy-checkbox>

<script type="module">
  const component1 = document.querySelector("#sample");
  Object.assign(component1, {
    "checkboxTitle": "Receive project updates by email."
  });
</script>

API reference

#

Hover over a name or focus it with the keyboard to see the code. On touch screens, tap the name.

<sy-checkbox>

Properties

Attribute / PropertyTypeDefaultDescription
string''title attribute applied to the checkbox.
string''Field name used in FormData.
string'on'Current value or item identifier.
booleanfalseSelected or on state.
booleanfalseBlock user interaction and keyboard focus.
booleanfalseIndeterminate state when only some items are selected.
booleanfalseDisplay the current value while preventing edits.
booleanfalseFail form validation when no value is provided.
booleanfalseUse the app's error UI instead of the browser's built-in error display. checkValidity still performs validation.

Events

EventDetailDescription
CustomEvent<{ value: boolean; isValid: boolean; checked: boolean; indeterminate: boolean }>Emitted when the value or selection state changes.
CustomEvent<boolean>Emitted when focus is received.
CustomEvent<boolean>Emitted when focus is lost.

Methods

MethodReturnsDescription
Promise<void>Move keyboard focus to the input or action element.
Promise<void>Remove focus from the input element.
Promise<boolean>Return true if the current constraints are satisfied, otherwise false.
Promise<boolean>Validate the current value and display errors to the user.
Promise<string>Return the current validation state.
Promise<void>Set a custom error state.
Promise<void>Clear the custom error state.

Slots

SlotDescription
Component body or child items.
Validation error message.