Grapes homepage1.57.0
  • Guide
  • Tokens
  • Components
    Grapes on GithubGrapes on Figma
    Interaction
    • Button
    • IconButton
    • FloatingActionBar
    • Link
    Icons
    • Icon
    • HighlightIcon
    Form
    • AmountInput
    • Autocomplete
    • AutocompleteMultiple
    • AutocompletePlace
    • CheckboxBox
    • CheckboxField
    • DatePicker
    • FormField
    • Input
    • OptionGroup
    • PasswordInput
    • PhoneInput
    • RadioBox
    • RadioField
    • RadioGroup
    • Select
    • SwitchField
    • TextArea
    • TextInput
    • Upload
    • UploadButton
    Feedback
    • Badge
    • Banner
    • Callout
    • EmptyState
    • Modal
    • ModalSlideshow
    • DeprecatedModalSlideshow
    • PageModal
    • Skeleton
    • Tag
    • Toast
    • Tooltip
    Data display
    • Accordion
    • Avatar
    • Box
    • Calendar
    • CalendarRange
    • CollapsibleList
    • FileCard
    • InfoTip
    • ListBox
    • ListView
    • Panel
    • SidePanel
    • DeprecatedPreview
    • Table
    • Timeline
    • useDateFormatter
    Navigation
    • DropdownItem
    • DropdownMenu
    • Navigation
    • NavigationItem
    • Popover
    • Tabs

    RadioBox

    View source code
    • Usage
    • Props
    • Accessibility
    The RadioBox only works within a RadioGroup

    The RadioBox component should be wrapped inside a RadioGroup in order to work. Learn more about the RadioGroup here.

    Basic usage

    const Demo = () => {
      const [selectedValue, setSelectedValue] = useState<string | null>(null);
    
      return (
        <RadioGroup
          name="cardType"
          value={selectedValue}
          onChange={(event) => {
            setSelectedValue(event?.target.value);
          }}
          direction="column"
          className="gap-8"
        >
          <RadioBox
            label="Administrator"
            description="An admin can set-up the account"
            value="administrator"
          />
          <RadioBox
            label="Controller"
            description="A controller has access to all accounting features"
            value="controller"
          />
          <RadioBox
            label="Requester"
            description="A requester can request and make purchases"
            value="requester"
          />
        </RadioGroup>
      );
    };
    

    Default value

    RadioGroup only works in a controlled mode. To define a default value, use useState.

    const Demo = () => {
      const [selectedValue, setSelectedValue] = useState<string | null>(
        "administrator"
      );
    
      return (
        <RadioGroup
          name="cardType"
          value={selectedValue}
          onChange={(event) => {
            setSelectedValue(event?.target.value);
          }}
          direction="column"
          className="gap-8"
        >
          <RadioBox
            label="Administrator"
            description="An admin can set-up the account"
            value="administrator"
          />
          <RadioBox
            label="Controller"
            description="A controller has access to all accounting features"
            value="controller"
          />
          <RadioBox
            label="Requester"
            description="A requester can request and make purchases"
            value="requester"
          />
        </RadioGroup>
      );
    };
    

    With icon

    Use the iconName prop to add an icon to the RadioBox.

    <RadioGroup {...otherProps}>
      <RadioBox
        iconName="single-purchase-card"
        label="Single use"
        description="If you need to make a one-time payment"
        value="singleUse"
      />
      <RadioBox
        iconName="recurring-card"
        label="Recurring"
        description="If you want to manage your subscriptions"
        value="recurring"
      />
    </RadioGroup>
    

    Without the description

    The description prop is optional.

    <RadioGroup {...otherProps}>
      <RadioBox label="Yes" value="yes" />
      <RadioBox label="No" value="no" />
    </RadioGroup>