Skip to main content

Checkbox

Use cases:

  • Multi-selection forms
  • Filtering
  • Sorting
  • To-Do lists
  • Privacy and consent

Any use where the user is to give a boolean type input choice.

Example

Default checkbox
Checkbox with slotted label
Check me!
Disabled checkbox

Declaration

<rapid-checkbox></rapid-checkbox>

Usage

@customElement({
name: 'my-element',
template: html`
<rapid-checkbox
?disabled="${(x) => x.disabled}"
?checked="${sync((x) => x.isSelected, 'boolean')}"
@change="${(x, ctx) => x.checkChanged(ctx.event)}"
>Checkbox
</rapid-checkbox>
`,
})
export class MyElement extends GenesisElement {
@observable disabled = false;
@observable isSelected = false;
checkChanged(e: Event) {
this.isSelected = e.event.checked;
console.log(this.isSelected); // sync value updated
console.log(e.event.checked); // equivalent to sync value
}
}

DOM API

Property and attribute binding examples for Genesis Component syntax. Closing tag omitted.

Attributes

AttributeTypeUseExample
checkedbooleanThe boolean value of whether the checkbox is checked. Use the sync utility to allow for data from from the template back to the model.
<rapid-checkbox ?checked="${sync((x) => x.isSelected, 'boolean')}">
readonlybooleanConfigures the component so the user cannot alter the state via the web browser.
<rapid-checkbox readonly>
disabledbooleanSame functionality as readonly, and additionally greys out the component.
<rapid-checkbox disabled>
formstringAssociates this component to a form. Form id needs to be passed. If no Id informed, then it will be associated with the ancestor form.
<rapid-checkbox form="myForm">

Properties

This component doesn't have any properties which are not also controlled via attributes.

Slots

SlotUse
DefaultThe default slot for the label.
checked-indicatorThe checked-state indicator.
indicator-indicatorThe indeterminate (non-checked) indicator.

Parts

PartUse
controlThe element representing the visual checkbox control.
labelThe label text.

Fired Events

EventTypeUseExample
changebooleanEmits a custom change event when the checked state changes. Access the value on the event via .target.checked.
<rapid-checkbox @change="${(x) => x.myChangeHandler(event)}">

Listened events

This component doesn't listen to any events.

Info

Further details

This component is an implementation of an HTML checkbox element.