<focsd-checkboxname="terms"required>I accept the terms of service</focsd-checkbox>
import { Checkbox } from'@focsd-dev/react';
exportfunctionExample() {
return<CheckboxonChange={(e) => console.log(e.target)}name="terms"required>I accept the terms of service</Checkbox>;
}
<scriptsetup>
import'@focsd-dev/components/focsd-checkbox.js';
</script>
<template>
<focsd-checkbox@change="onChange"name="terms"required>I accept the terms of service</focsd-checkbox>
</template>
// Add CUSTOM_ELEMENTS_SCHEMA to the component's schemas, then:
import'@focsd-dev/components/focsd-checkbox.js';
// template
<focsd-checkbox (change)="onChange($event)" name="terms" required>I accept the terms of service</focsd-checkbox>
<script>
import'@focsd-dev/components/focsd-checkbox.js';
</script>
<focsd-checkboxonchange={(e) => console.log(e.target)}name="terms"required>I accept the terms of service</focsd-checkbox>
API
Attributes
Attribute
Property
Type
Default
name
name
string
—
disabled
disabled
boolean
false
required
required
boolean
false
readonly
readOnly
boolean
false
aria-label
hostAriaLabel
string | null
null
aria-description
hostAriaDescription
string | null
null
aria-labelledby
hostAriaLabelledBy
string | null
null
aria-describedby
hostAriaDescribedBy
string | null
null
label-position
labelPosition
'top' | 'start' | 'end' | undefined
—
hint
hint
string
—
error
error
—
—
warning
warning
string | undefined
—
success
success
string | undefined
—
error-message
errorMessage
string | undefined
—
warning-message
warningMessage
string | undefined
—
warning-pattern
warningPattern
string | undefined
—
checked
checked
boolean
false
indeterminate
indeterminate
boolean
false
value
value
FormValue
on
Methods
Method
Description
describedByIds()
IDs to add to the inner control's aria-describedby: the hint, then the shown message.
checkValidity()
True when the value is valid; otherwise fires invalid and returns false, like native.
reportValidity()
Like checkValidity(), and also shows the browser's validation message when invalid.
setCustomValidity(message)
Set (non-empty) or clear (empty string) a custom validation error, like native controls.
setValidityState(flags, message, anchor)
For subclasses: set the validity flags and message. anchor is the element the browser points its message at.
validate()
Show (or clear) the error from the control's own checks: required, type, pattern, min,
max and the like. Uses error-message, else the browser's localized message. An error the
author set (a server error, say) is left as it is.
clearValidation()
Clear the error and warning that validate() and warning-pattern showed (a form reset does).
emitValue(commit)
For subclasses: fire the value events, as a native control does on a user edit: input
(bubbles, composed), then with commit also change (bubbles, stays in its tree).
idrefText(ids)
For subclasses: the text of the elements an ID reference list names, resolved in the host's
tree (ID references cannot cross a shadow root), joined by spaces.
Events
Event
Description
input
—
change
Fired when the user commits a change to the value or state.
Slots
Slot
Description
(default)
Default content.
CSS parts
Style the inside of the component with ::part(), for example focsd-checkbox::part(control).
Part
Description
control
The control element.
label
The label element.
text
The text element.
layout
The wrapper around the label and the body.
body
The label wrapper and the messages.
hint
The hint text.
message
The shown message (also error, warning or success).
message-icon
The icon in the message.
announcer
The hidden region that announces message changes.
Accessibility
Do not set readonly here: like a native checkbox or select it has no effect, and HTML skips validation for any custom form control with a readonly attribute. Use disabled, or show the value as text.
A native checkbox inside a <label> that wraps the slotted text, so clicking the text toggles it.
indeterminate exposes the mixed state.
required reports valueMissing until checked.
Form-associated: participates in FormData, validation, reset and fieldset disabled like a native control.
Keyboard
Key
Action
Space
Toggles
Ask the docs
Hi, what are you building?
Ask about any component, theming, forms or frameworks. I answer with the right component, a snippet and a link to its docs.