Checkbox

Checkbox component is a form element that allows the user to select one or more options from a list of options.

Design system docs Examples Default Checkbox
<dap-ds-stack direction="column">
  <dap-ds-checkbox
    value="option-1"
    label="Option 1"
  ></dap-ds-checkbox>

  <dap-ds-checkbox
    label="Option 2"
  ></dap-ds-checkbox>
  <dap-ds-stack>
    Pure css Checkbox:
    <label className="dds-choice-wrap">
      <input type="checkbox" className="dds-checkbox" />
      <div className="dds-choice-label-container">
        Pure css Option 1
      </div>
    </label>
    <label className="dds-choice-wrap">
      <input type="checkbox" className="dds-checkbox" />
      <div className="dds-choice-label-container">
        Pure css Option 2
      </div>
    </label>
  </dap-ds-stack>
</dap-ds-stack>
Sizes

The checkbox component comes in three sizes: small, and large. The default size is small.

<dap-ds-stack direction="row" spacing="1200">
<dap-ds-stack>
  <dap-ds-checkbox
    value="option-0"
    label="Xs Option"
    description="Description"
    size="xs"
  ></dap-ds-checkbox>

  <dap-ds-checkbox
    value="option-1"
    label="Small Option"
    description="Description"
    size="sm"
  ></dap-ds-checkbox>

  <dap-ds-checkbox
    label="Large Option"
    value="option-2"
    description="Description"
    size="lg"
  ></dap-ds-checkbox>
</dap-ds-stack>
<dap-ds-stack>
  <label className="dds-choice-wrap dds-choice-wrap--xs">
    <input type="checkbox" className="dds-checkbox" />
    <div className="dds-choice-label-container">
      <span className="dds-label dds-label--subtle">Pure xs Option 1</span>
      <span className="dds-typography dds-typography-description">
        Description
      </span>
    </div>
  </label>

  <label className="dds-choice-wrap dds-choice-wrap--sm">
    <input type="checkbox" className="dds-checkbox" />
    <div className="dds-choice-label-container">
      <span className="dds-label dds-label--subtle">Pure sm Option 2</span>
      <span className="dds-typography dds-typography-description">
        Description
      </span>
    </div>
  </label>

  <label className="dds-choice-wrap dds-choice-wrap--lg">
    <input type="checkbox" className="dds-checkbox" />
    <div className="dds-choice-label-container">
      <span className="dds-label dds-label--subtle">Pure lg Option 2</span>
      <span className="dds-typography dds-typography-description">
        Description
      </span>
    </div>
  </label>
</dap-ds-stack>
</dap-ds-stack>
Secondary text

The checkbox component comes with a secondary text. The secondary text is used to give more information about the checkbox.

<dap-ds-stack direction="column">
  <dap-ds-checkbox
    label="Option 1"
    value="option-1"
    description="Description bottom, aligned to the right"
  ></dap-ds-checkbox>

  <dap-ds-checkbox
    label="Option 2"
    value="option-2"
    description="Description top, aligned to the right"
    descriptionPlacement="top"
  ></dap-ds-checkbox>

  <dap-ds-checkbox
    label="Option 3"
    value="option-3"
    description="Description bottom, aligned to the left"
    labelPlacement="left"
  ></dap-ds-checkbox>

  <dap-ds-checkbox
    label="Option 4"
    value="option-4"
    description="Description top, aligned to the left"
    descriptionPlacement="top"
    labelPlacement="left"
  ></dap-ds-checkbox>
</dap-ds-stack>
Statuses

The checkbox component can have different statuses.

<dap-ds-stack direction="row" spacing="1200">
<dap-ds-stack direction="column">
  <dap-ds-checkbox
    label="Disabled"
    value="option-1"
    disabled
  ></dap-ds-checkbox>

  <dap-ds-checkbox
    label="Checked"
    value="option-2"
    checked
  ></dap-ds-checkbox>

  <dap-ds-checkbox
    label="Indeterminate"
    value="option-3"
    indeterminate
  ></dap-ds-checkbox>

  <dap-ds-checkbox
    label="Invalid"
    value="option-4"
    invalid
    feedback="You have to accept the terms and conditions"
    feedbackType="negative"
  ></dap-ds-checkbox>
</dap-ds-stack>
<dap-ds-stack direction="column">
  <label className="dds-choice-wrap dds-choice-wrap--sm">
    <input type="checkbox" className="dds-checkbox" disabled/>
    <div className="dds-choice-label-container">
      <span className="dds-label dds-label--subtle">Pure disabled</span>
    </div>
  </label>

  <label className="dds-choice-wrap dds-choice-wrap--sm">
    <input type="checkbox" className="dds-checkbox" defaultChecked/>
    <div className="dds-choice-label-container">
      <span className="dds-label dds-label--subtle">Pure checked</span>
    </div>
  </label>

  <label className="dds-choice-wrap dds-choice-wrap--sm">
    <input type="checkbox" className="dds-checkbox" indeterminate="true" defaultChecked/>
    <div className="dds-choice-label-container">
      <span className="dds-label dds-label--subtle">Pure indeterminate</span>
    </div>
  </label>

  <label className="dds-choice-wrap dds-choice-wrap--sm">
    <input type="checkbox" className="dds-checkbox dds-checkbox--invalid"/>
    <div className="dds-choice-label-container">
      <span className="dds-label dds-label--subtle">Pure invalid</span>
    </div>
  </label>
</dap-ds-stack>
</dap-ds-stack>
Checkbox group

The checkbox component can be used in a group. The checkbox group is used to group multiple checkboxes together. You can use the tooltipAriaLabel property to set the aria label for the tooltip.

<dap-ds-input-group
  required
  label="Checkbox Group"
  description="Checkbox group description"
  tooltip="Tooltip"
  tooltipAriaLabel="Information about the checkbox group"
  feedbackType="negative"
  feedback="feedback text">
  
  <dap-ds-checkbox
    label="Option 1"
    description="Option 1 description"
    value="option-1"
  ></dap-ds-checkbox>

  <dap-ds-checkbox
    label="Option 2"
    value="option-2"
  ></dap-ds-checkbox>

  <dap-ds-checkbox
    label="Option 3"
    value="option-3"
  ></dap-ds-checkbox>
</dap-ds-input-group>
Type

The checkbox component can have background. It is useful when used on a colored background.

It can be set with type="background" property. Default border can be set also with border property.

<div style={{ backgroundColor: "#e9edf2", padding: "16px" }}>
  <dap-ds-input-group
    required
    label="Checkbox Group"
    description="Checkbox group description"
    tooltip="Tooltip"
    feedbackType="negative"
    feedback="feedback text">
    
    <dap-ds-checkbox
      label="Option 1"
      description="Option 1 description"
      value="option-1"
      type="background"
    ></dap-ds-checkbox>

    <dap-ds-checkbox
      label="Option 2"
      value="option-2"
      type="background"
    ></dap-ds-checkbox>

    <dap-ds-checkbox
      label="Option 3 border"
      value="option-3"
      type="background"
      border
    ></dap-ds-checkbox>
  </dap-ds-input-group>
</div>
Border

The checkbox component can have border with border property.

<div style={{ backgroundColor: "#e9edf2", padding: "16px" }}>
  <dap-ds-input-group
    required
    label="Checkbox Group"
    description="Checkbox group description"
    tooltip="Tooltip"
    feedbackType="negative"
    feedback="feedback text">
    
    <dap-ds-checkbox
      label="Option 1"
      description="Option 1 description"
      value="option-1"
      type="background"
      border
    ></dap-ds-checkbox>

    <dap-ds-checkbox
      label="Option 2"
      value="option-2"
      border
    ></dap-ds-checkbox>

    <dap-ds-checkbox
      label="Option 3"
      value="option-3"
      border
    ></dap-ds-checkbox>
  </dap-ds-input-group>
</div>
Importing
import { DapDSCheckbox } from 'dap-design-system/dist/dds'
Importing React
import { DapDSCheckboxReact } from 'dap-design-system/dist/react'
Attributes
PropertyTypeDefaultDescription
indeterminatebooleanfalseWhether the checkbox is indeterminate
preventDefaultbooleanfalseWhether the checkbox should prevent the default action
borderbooleanfalseThis sets up border around the checkbox, when true.
type'normal', 'background''normal'The type of the checkbox
namestringThe name of the checkbox.
valuestringThe value of the checkbox.
checkedbooleanWhether the checkbox is checked.
labelstringThe label of the checkbox.
descriptionstringThe description of the checkbox.
disabledbooleanWhether the checkbox is disabled.
requiredbooleanWhether the checkbox is required.
size'xs', sm' , 'md' , 'lg'The size of the checkbox.
labelPlacement'left', 'right'The placement of the label.
descriptionPlacement'top', 'bottom'The placement of the description.
subtlebooleanThe weight of the label.
feedbackstringThe feedback of the checkbox.
feedbackType'negative', 'positive' , 'warning'The feedback type of the checkbox.
invalidbooleanThe invalid state of the checkbox.
optionalbooleanThe optional state of the checkbox.
optionalLabelstringThe optional label of the checkbox.
Slots

No slots available.

Events
Event NameDescription
dds-changeFired when the checkbox is checked or unchecked.
dds-blurEmitted when the checkbox loses focus.
dds-focusEmitted when the checkbox gains focus.
dds-inputEmitted when the checkbox receives input.
CSS Parts
Part NameDescription
baseThe main checkbox container.
labelThe label of the checkbox.
inputThe input of the checkbox.
controlThe control of the checkbox.
iconThe icon of the checkbox.
label-containerThe label container of the checkbox.
descriptionThe description of the checkbox.
CSS Custom Properties
Property NameDescription
--dds-checkbox-sizeThe size of the checkbox. Default is `var(--dds-spacing-500)`.
--dds-checkbox-border-widthThe border width of the checkbox. Default is `var(--dds-border-width-large)`.
--dds-checkbox-border-radiusThe border radius of the checkbox. Default is `var(--dds-radius-small)`.
--dds-checkbox-border-colorThe border color of the checkbox. Default is `var(--dds-border-neutral-base)`.
--dds-checkbox-background-colorThe background color of the checkbox. Default is `transparent`.
--dds-checkbox-icon-colorThe color of the checkbox icon. Default is `var(--dds-button-primary-icon-enabled)`.
--dds-checkbox-hover-border-colorThe border color when hovering over the checkbox. Default is `var(--dds-border-neutral-medium)`.
--dds-checkbox-hover-background-colorThe background color when hovering over the checkbox. Default is `var(--dds-background-neutral-medium)`.
--dds-checkbox-active-border-colorThe border color when the checkbox is active. Default is `var(--dds-border-neutral-strong)`.
--dds-checkbox-active-background-colorThe background color when the checkbox is active. Default is `var(--dds-background-neutral-strong)`.
--dds-checkbox-checked-border-colorThe border color when the checkbox is checked. Default is `var(--dds-background-brand-base-inverted)`.
--dds-checkbox-checked-background-colorThe background color when the checkbox is checked. Default is `var(--dds-background-brand-base-inverted)`.
--dds-checkbox-checked-hover-border-colorThe border color when hovering over a checked checkbox. Default is `var(--dds-background-brand-medium-inverted)`.
--dds-checkbox-checked-hover-background-colorThe background color when hovering over a checked checkbox. Default is `var(--dds-background-brand-medium-inverted)`.
--dds-checkbox-checked-active-border-colorThe border color when a checked checkbox is active. Default is `var(--dds-background-brand-strong-inverted)`.
--dds-checkbox-checked-active-background-colorThe background color when a checked checkbox is active. Default is `var(--dds-background-brand-strong-inverted)`.
--dds-checkbox-invalid-border-colorThe border color when the checkbox is invalid. Default is `var(--dds-border-negative-base)`.
--dds-checkbox-invalid-background-colorThe background color when the checkbox is invalid. Default is `var(--dds-background-negative-base)`.
--dds-checkbox-invalid-hover-border-colorThe border color when hovering over an invalid checkbox. Default is `var(--dds-border-negative-medium)`.
--dds-checkbox-invalid-hover-background-colorThe background color when hovering over an invalid checkbox. Default is `var(--dds-background-negative-medium)`.
--dds-checkbox-invalid-active-border-colorThe border color when an invalid checkbox is active. Default is `var(--dds-border-negative-strong)`.
--dds-checkbox-invalid-active-background-colorThe background color when an invalid checkbox is active. Default is `var(--dds-background-negative-strong)`.
--dds-checkbox-disabled-border-colorThe border color when the checkbox is disabled. Default is `var(--dds-button-primary-background-disabled)`.
--dds-checkbox-disabled-background-colorThe background color when the checkbox is disabled. Default is `var(--dds-button-primary-background-disabled)`.
--dds-checkbox-disabled-icon-colorThe color of the checkbox icon when disabled. Default is `var(--dds-button-primary-icon-disabled)`.