Radio
ReadyA radio button component that allows users to select one option from a group of mutually exclusive choices.
Preview
Code
npm install @fbin-web/neighborhood-core
import { NbhdRadio } from '@fbin-web/neighborhood-core';
<nbhd-radio
label="Radio Label"
title="Radio Title"
value="yes"
name="radio-1"
id="radio-1">
</nbhd-radio>
npm install @fbin-web/neighborhood-react
import { NbhdRadio } from '@fbin-web/neighborhood-react';
import { NbhdRadio } from '@fbin-web/neighborhood-react';
const App = () => (
<>
<NbhdRadio
label="Radio Label"
title="Radio Title"
value="yes"
name="radio-1"
id="radio-1"></NbhdRadio>
</>
);
Properties
| Property | Attribute | Type | Default | Description |
|---|---|---|---|---|
form | form | string | — | ID of a |
id | id | string | — | The id of the radio button. |
label | label | string | — | The label text for the radio button. |
value | value | string | — | The value of the radio button. |
title | title | string | — | The title of the radio button. |
name | name | string | — | The name of the radio button. The form field name it submits under. |
ariaLabel | aria-label | string | — | Descriptive text for additional context. |
cssClass | css-class | string | — | Additional CSS classes to apply to the radio button. |
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 radio as invalid and shows the error text. |
disabled | disabled | boolean | false | Disables the radio button from being selected. |
checked | checked | boolean | false | Whether the radio button is checked initially. |
required | required | boolean | false | Whether the radio button is required. |
No properties match.
Events
| Name | Description | Event Detail |
|---|---|---|
click | Fired when the radio button is clicked. | MouseEvent |
input | Fired when the radio button value changes. | InputEvent |
nbhd-change | Emitted when the radio button is checked. The value is its `value`. Inside a Radio Group, listen on the group instead; change events from its radios stop there. | { value: string } |
change | Emitted alongside nbhd-change. | { value: string } |
Form methods
Form-associated: a standalone radio submits its value when checked; radios sharing a `name` uncheck each other, but each is its own Tab stop without arrow-key movement. For a group that behaves like native radios (one Tab stop, arrow keys), use nbhd-radio-group, which also submits instead of its radios.
| Name | Description |
|---|---|
checkValidity() | Returns false (and fires `invalid`) if the control fails validation. |
reportValidity() | Like checkValidity(), and shows the browser’s validation message on the control. |
setCustomValidity(message) | Marks the control invalid with your own message; an empty string clears it. |
validity | The ValidityState (valueMissing, typeMismatch, customError, …). |
validationMessage | The message the browser would show. |
willValidate | Whether the control takes part in form validation (false when disabled). |
associatedForm | The |
No form methods match.
Slots
| Name | Description |
|---|---|
label | Custom content for the radio button label. When omitted, the label property value is rendered. |
help | Help text content displayed below the radio when not in an invalid state. |
error | Error message content displayed below the radio when in an invalid state. |
CSS Parts
| Name | Description |
|---|---|
base | The wrapper div for the radio form control. |
label | The label element for the radio button. |
label-slot | The named label slot inside the radio 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-radio::part(base) {
/* your styles */
}
CSS Properties
Set these on nbhd-radio 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.
Radio
| Property | Token | Value | Copy |
|---|---|---|---|
--nbhd-radio-box-borderRadius | --nbhd-border-radius-full | 9999px |
|
--nbhd-radio-indicator-borderRadius | --nbhd-border-radius-full | 9999px |
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-radio> renders internally. Import them too when you tree-shake.