Skip to main content
Neighborhood Design System v5.1.0

Radio

Ready

A radio button component that allows users to select one option from a group of mutually exclusive choices.

Preview

Open in Storybook (opens in new tab)

Code

Install
npm install @fbin-web/neighborhood-core
Import
import { NbhdRadio } from '@fbin-web/neighborhood-core';
Usage
<nbhd-radio
  label="Radio Label"
  title="Radio Title"
  value="yes"
  name="radio-1"
  id="radio-1">
</nbhd-radio>

Properties

PropertyAttributeTypeDefaultDescription
formformstring—ID of a
elsewhere on the page to belong to, like a native control’s `form` attribute.
ididstring—The id of the radio button.
labellabelstring—The label text for the radio button.
valuevaluestring—The value of the radio button.
titletitlestring—The title of the radio button.
namenamestring—The name of the radio button. The form field name it submits under.
ariaLabelaria-labelstring—Descriptive text for additional context.
cssClasscss-classstring—Additional CSS classes to apply to the radio button.
errorTexterror-textstring—Error message text to display when invalid. Defaults to "This field has an error." when empty.
helpTexthelp-textstring—Help text to provide additional context.
invalidinvalidbooleanfalseMarks the radio as invalid and shows the error text.
disableddisabledbooleanfalseDisables the radio button from being selected.
checkedcheckedbooleanfalseWhether the radio button is checked initially.
requiredrequiredbooleanfalseWhether the radio button is required.

Events

NameDescriptionEvent Detail
clickFired when the radio button is clicked.MouseEvent
inputFired when the radio button value changes.InputEvent
nbhd-changeEmitted 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 }
changeEmitted 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.

NameDescription
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.
validityThe ValidityState (valueMissing, typeMismatch, customError, …).
validationMessageThe message the browser would show.
willValidateWhether the control takes part in form validation (false when disabled).
associatedFormThe the control belongs to, or null.

Slots

NameDescription
labelCustom content for the radio button label. When omitted, the label property value is rendered.
helpHelp text content displayed below the radio when not in an invalid state.
errorError message content displayed below the radio when in an invalid state.

CSS Parts

NameDescription
baseThe wrapper div for the radio form control.
labelThe label element for the radio button.
label-slotThe named label slot inside the radio label.
label-textThe fallback text element that displays the label property value.
requiredThe required marker (*) shown in the label when required. Hidden from assistive technology, which announces the native required state.
textThe wrapper div for help and error text.
helpThe help slot element.
errorThe error slot element.
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

PropertyTokenValue Copy
--nbhd-radio-box-borderRadius--nbhd-border-radius-full9999px
--nbhd-radio-indicator-borderRadius--nbhd-border-radius-full9999px

Form control

PropertyTokenValue Copy
--nbhd-formControl-display—inline
--nbhd-formControl-field-appearance—none
--nbhd-formControl-field-borderRadius--nbhd-border-radius-none0
--nbhd-formControl-field-color--nbhd-context-color-control-foregroundAdapts to surface
--nbhd-formControl-field-display—inline-block
--nbhd-formControl-field-fontFamily--nbhd-typography-body-fontFamilysans-serif
--nbhd-formControl-field-fontSize--nbhd-typography-body-fontSize1rem
--nbhd-formControl-field-inlineSize—100%
--nbhd-formControl-field-position—relative
--nbhd-formControl-fontFamily--nbhd-typography-body-fontFamilysans-serif
--nbhd-formControl-host-display—block
--nbhd-formControl-label-color--nbhd-context-color-text-primaryAdapts to surface
--nbhd-formControl-label-display—block
--nbhd-formControl-label-fontFamily--nbhd-typography-label-fontFamilysans-serif
--nbhd-formControl-label-fontSize--nbhd-typography-label-fontSize1rem
--nbhd-formControl-label-fontWeight--nbhd-typography-label-fontWeight600
--nbhd-formControl-label-letterSpacing—inherit
--nbhd-formControl-label-marginBlock--nbhd-space-0 --nbhd-space-050px 2px
--nbhd-formControl-label-position—relative
--nbhd-formControl-label-textTransform—inherit
--nbhd-formControl-marginBlock--nbhd-space-00px
--nbhd-formControl-maxInlineSize—100%
--nbhd-formControl-paddingBlock--nbhd-space-00px
--nbhd-formControl-paddingInline--nbhd-space-00px
--nbhd-formControl-position—relative
--nbhd-formControl-required-gap--nbhd-space-052px
--nbhd-formControl-text-marginBlock--nbhd-space-1 --nbhd-space-04px 0px

Selection control

PropertyTokenValue Copy
--nbhd-selectionControl-box-blockSize—18px
--nbhd-selectionControl-box-borderColor--nbhd-context-color-control-borderAdapts to surface
--nbhd-selectionControl-box-borderRadius--nbhd-border-radius-sm2px
--nbhd-selectionControl-box-borderStyle—solid
--nbhd-selectionControl-box-borderWidth--nbhd-border-width-subtle1px
--nbhd-selectionControl-box-inlineSize—18px
--nbhd-selectionControl-checked-label-fontWeight—600
--nbhd-selectionControl-focus-outlineColor--nbhd-context-color-focus-outlineAdapts to surface
--nbhd-selectionControl-formControl-marginBlock--nbhd-space-14px
--nbhd-selectionControl-formControl-paddingBlock--nbhd-space-14px
--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-04px 0px
--nbhd-selectionControl-label-alignItems—center
--nbhd-selectionControl-label-cursor—pointer
--nbhd-selectionControl-label-display—flex
--nbhd-selectionControl-label-fontWeight--nbhd-typography-body-fontWeight400
--nbhd-selectionControl-label-gap--nbhd-space-14px
--nbhd-selectionControl-label-justifyContent—start
--nbhd-selectionControl-label-paddingInline--nbhd-space-9 --nbhd-space-036px 0px
--nbhd-selectionControl-label-textTransform—normal
--nbhd-selectionControl-text-paddingInlineStart--nbhd-space-936px

Dependencies

Child components <nbhd-radio> renders internally. Import them too when you tree-shake.

Used by

Esc
↑ ↓ to move↵ to open