Liking cljdoc? Tell your friends :D

x-checkbox

An accessible, themeable checkbox control that supports checked, indeterminate, disabled, read-only, and required states. Fires cancelable request events before state changes, allowing host code to intercept.


Tag

<x-checkbox></x-checkbox>

Attributes

AttributeTypeDefaultDescription
checkedbooleanfalseWhether the checkbox is checked
indeterminatebooleanfalseIndeterminate (mixed) state — overrides checked visually
disabledbooleanfalseDisables interaction
readonlybooleanfalsePrevents user toggling (still focusable)
requiredbooleanfalseMarks the field as required; the element is invalid when unchecked
namestringForm field name
valuestring"on"Value submitted with form data when checked
aria-labelstringAccessible label
aria-describedbystringReferences a describing element
aria-labelledbystringReferences a labelling element

Properties

PropertyTypeReflects attribute
checkedbooleanchecked
indeterminatebooleanindeterminate
disabledbooleandisabled
readOnlybooleanreadonly
requiredbooleanrequired
namestringname
valuestringvalue

Events

EventCancelableDetail
x-checkbox-change-requestyes{ value, previousChecked, nextChecked } — call preventDefault() to block the toggle
x-checkbox-changeno{ value, checked } — fired after state has changed

Both events bubble and are composed.


Toggle logic

  • When indeterminate is set, clicking always transitions to checked=true, indeterminate=false.
  • When checked, clicking transitions to checked=false, indeterminate=false.
  • When unchecked, clicking transitions to checked=true, indeterminate=false.

Accessibility

  • The host element has role="checkbox" and aria-checked set to "true", "false", or "mixed".
  • tabindex="0" when enabled; tabindex="-1" when disabled.
  • aria-disabled="true" when disabled.
  • aria-required="true" when required.
  • aria-readonly="true" when readonly.
  • Keyboard: Space toggles; Enter toggles (unless readonly/disabled).

Examples

Basic states

<x-checkbox></x-checkbox>
<x-checkbox checked></x-checkbox>
<x-checkbox indeterminate></x-checkbox>
<x-checkbox disabled></x-checkbox>
<x-checkbox checked disabled></x-checkbox>

With a label

<label>
  <x-checkbox name="agree" value="yes" required></x-checkbox>
  I agree to the terms
</label>

Listening to changes

document.querySelector('x-checkbox').addEventListener('x-checkbox-change', e => {
  console.log('checked:', e.detail.checked, 'value:', e.detail.value);
});

Intercept and block toggle

checkbox.addEventListener('x-checkbox-change-request', e => {
  if (!canToggle) e.preventDefault();
});

ClojureScript (hiccup renderer)

[:x-checkbox {:checked "" :name "agree" :value "yes"
              :on-x-checkbox-change
              (fn [e]
                (swap! state assoc :agreed (.. e -detail -checked)))}]

Can you improve this documentation?Edit on GitHub

cljdoc builds & hosts documentation for Clojure/Script libraries

Keyboard shortcuts
Ctrl+kJump to recent docs
Move to previous article
Move to next article
Ctrl+/Jump to the search field
× close