Checkbox
ReadyA checkbox component that lets users select or deselect an option.
Preview
Code
Install
npm install @fbin-web/neighborhood-core
Import
import { NbhdCheckbox } from '@fbin-web/neighborhood-core';
Usage
<nbhd-checkbox
label="Checkbox Label"
id="checkbox-1">
</nbhd-checkbox>
Install
npm install @fbin-web/neighborhood-react
Import
import { NbhdCheckbox } from '@fbin-web/neighborhood-react';
Usage
import { NbhdCheckbox } from '@fbin-web/neighborhood-react';
const App = () => (
<>
<NbhdCheckbox
label="Checkbox Label"
id="checkbox-1"></NbhdCheckbox>
</>
);
Properties
| Property | Attribute | Type | Default | Description |
|---|---|---|---|---|
label | label | string | — | The label text for the checkbox. |
value | value | string | — | The value of the checkbox. |
title | title | string | — | The title of the checkbox. |
name | name | string | — | The name of the checkbox. The form field name it submits under. |
form | form | string | — | ID of a |
id | id | string | — | The id of the checkbox. |
cssClass | css-class | string | — | Additional CSS classes to apply to the checkbox. |
ariaLabel | aria-label | string | — | Descriptive text for additional context. |
errorText | error-text | string | — | Error message text to display when invalid. Defaults to "This field has an error." when empty. |
helpText | help-text | string | — | Help text to provide additional context. |
invalid | invalid | boolean | false | Marks the checkbox as invalid and shows the error text. |
disabled | disabled | boolean | false | Disables the checkbox from being selected. |
checked | checked | boolean | false | Whether the checkbox is checked initially. |
required | required | boolean | false | Whether the checkbox is required. |
No properties match.
Events
| Name | Description | Event Detail |
|---|---|---|
click | Fired when the checkbox is clicked. | MouseEvent |
input | Fired when the checkbox value changes. | InputEvent |
nbhd-change | Emitted when the checkbox is checked or unchecked. The value is the checkbox’s `value` when checked, or an empty string when unchecked. | { value: string } |
change | Emitted alongside nbhd-change. | { value: string } |
Form methods
Form-associated: inside a
Slots
| Name | Description |
|---|---|
label | Custom content for the checkbox label. When omitted, the label property value is rendered. |
help | Help text content displayed below the checkbox when not in an invalid state. |
error | Error message content displayed below the checkbox when in an invalid state. |
CSS Parts
| Name | Description |
|---|---|
base | The wrapper div for the checkbox form control. |
label | The label element for the checkbox. |
label-slot | The named label slot inside the checkbox label. |
label-text | The fallback text element that displays the label property value. |
required | The required marker (*) shown in the label when required. Hidden from assistive technology, which announces the native required state. |
text | The wrapper div for help and error text. |
help | The help slot element. |
error | The error slot element. |
No css parts match.
nbhd-checkbox::part(base) {
/* your styles */
}
CSS Properties
Set these on nbhd-checkbox or an ancestor to override the defaults. Token is the design token a default comes from and Value is what it resolves to in core Neighborhood; brands may override them. Properties that adapt to surface follow the light or inverse surface they sit on until you set them.
Checkbox
| Property | Token | Value | Copy |
|---|---|---|---|
--nbhd-checkbox-box-borderRadius | --nbhd-border-radius-sm | 2px |
|
--nbhd-checkbox-indicator-borderRadius | --nbhd-border-radius-none | 0 |
Form control
| Property | Token | Value | Copy |
|---|---|---|---|
--nbhd-formControl-display | — | inline |
|
--nbhd-formControl-field-appearance | — | none |
|
--nbhd-formControl-field-borderRadius | --nbhd-border-radius-none | 0 |
|
--nbhd-formControl-field-color | --nbhd-context-color-control-foreground | Adapts to surface | |
--nbhd-formControl-field-display | — | inline-block |
|
--nbhd-formControl-field-fontFamily | --nbhd-typography-body-fontFamily | sans-serif |
|
--nbhd-formControl-field-fontSize | --nbhd-typography-body-fontSize | 1rem |
|
--nbhd-formControl-field-inlineSize | — | 100% |
|
--nbhd-formControl-field-position | — | relative |
|
--nbhd-formControl-fontFamily | --nbhd-typography-body-fontFamily | sans-serif |
|
--nbhd-formControl-host-display | — | block |
|
--nbhd-formControl-label-color | --nbhd-context-color-text-primary | Adapts to surface | |
--nbhd-formControl-label-display | — | block |
|
--nbhd-formControl-label-fontFamily | --nbhd-typography-label-fontFamily | sans-serif |
|
--nbhd-formControl-label-fontSize | --nbhd-typography-label-fontSize | 1rem |
|
--nbhd-formControl-label-fontWeight | --nbhd-typography-label-fontWeight | 600 |
|
--nbhd-formControl-label-letterSpacing | — | inherit |
|
--nbhd-formControl-label-marginBlock | --nbhd-space-0 --nbhd-space-05 | 0px 2px |
|
--nbhd-formControl-label-position | — | relative |
|
--nbhd-formControl-label-textTransform | — | inherit |
|
--nbhd-formControl-marginBlock | --nbhd-space-0 | 0px |
|
--nbhd-formControl-maxInlineSize | — | 100% |
|
--nbhd-formControl-paddingBlock | --nbhd-space-0 | 0px |
|
--nbhd-formControl-paddingInline | --nbhd-space-0 | 0px |
|
--nbhd-formControl-position | — | relative |
|
--nbhd-formControl-required-gap | --nbhd-space-05 | 2px |
|
--nbhd-formControl-text-marginBlock | --nbhd-space-1 --nbhd-space-0 | 4px 0px |
No form control match.
Selection control
| Property | Token | Value | Copy |
|---|---|---|---|
--nbhd-selectionControl-box-blockSize | — | 18px |
|
--nbhd-selectionControl-box-borderColor | --nbhd-context-color-control-border | Adapts to surface | |
--nbhd-selectionControl-box-borderRadius | --nbhd-border-radius-sm | 2px |
|
--nbhd-selectionControl-box-borderStyle | — | solid |
|
--nbhd-selectionControl-box-borderWidth | --nbhd-border-width-subtle | 1px |
|
--nbhd-selectionControl-box-inlineSize | — | 18px |
|
--nbhd-selectionControl-checked-label-fontWeight | — | 600 |
|
--nbhd-selectionControl-focus-outlineColor | --nbhd-context-color-focus-outline | Adapts to surface | |
--nbhd-selectionControl-formControl-marginBlock | --nbhd-space-1 | 4px |
|
--nbhd-selectionControl-formControl-paddingBlock | --nbhd-space-1 | 4px |
|
--nbhd-selectionControl-host-display | — | block |
|
--nbhd-selectionControl-indicator-backgroundColor | — | transparent |
|
--nbhd-selectionControl-indicator-blockSize | — | 10px |
|
--nbhd-selectionControl-indicator-inlineSize | — | 10px |
|
--nbhd-selectionControl-indicator-marginInline | --nbhd-space-1 --nbhd-space-0 | 4px 0px |
|
--nbhd-selectionControl-label-alignItems | — | center |
|
--nbhd-selectionControl-label-cursor | — | pointer |
|
--nbhd-selectionControl-label-display | — | flex |
|
--nbhd-selectionControl-label-fontWeight | --nbhd-typography-body-fontWeight | 400 |
|
--nbhd-selectionControl-label-gap | --nbhd-space-1 | 4px |
|
--nbhd-selectionControl-label-justifyContent | — | start |
|
--nbhd-selectionControl-label-paddingInline | --nbhd-space-9 --nbhd-space-0 | 36px 0px |
|
--nbhd-selectionControl-label-textTransform | — | normal |
|
--nbhd-selectionControl-text-paddingInlineStart | --nbhd-space-9 | 36px |
No selection control match.
Dependencies
Child components <nbhd-checkbox> renders internally. Import them too when you tree-shake.