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

    OptionGroup

    OptionGroup allows the user to select one item from a restrictedcollection (usually 3 to 5 items).

    View source code
    • Usage
    • Props
    • Accessibility

    Basic Usage

    const Demo = () => {
      const [selectedValue, setSelectedValue] = useState<string | null>(null);
    
      return (
        <OptionGroup
          name="optionGroupField"
          options={[
            { value: "daily", label: "Daily" },
            { value: "weekly", label: "Weekly" },
            { value: "yearly", label: "Yearly" },
          ]}
          value={selectedValue}
          onChange={(event) => {
            setSelectedValue(event.target.value);
          }}
        />
      );
    };
    

    Number as value

    const Demo = () => {
      const [selectedValue, setSelectedValue] = useState<string | null>(null);
      return (
        <OptionGroup
          name="nps"
          options={Array.from({ length: 10 }, (_, i) => {
            return { label: i + 1, value: i + 1 };
          })}
          value={selectedValue}
          onChange={(event) => {
            setSelectedValue(event.target.value);
          }}
        />
      );
    };
    

    Icon as label

    The OptionGroup supports Icon as label. Inside each option, use the attribute iconName to provide the name of the icon.

    Info

    The label prop is still mandatory to label the icon inside each radio button.

    const Demo = () => {
      const [selectedValue, setSelectedValue] = useState<string | null>(null);
    
      return (
        <OptionGroup
          name="transport"
          options={[
            {
              iconName: "plane",
              label: "airplane",
              value: "airplane",
            },
            {
              iconName: "car",
              label: "car",
              value: "car",
            },
            {
              iconName: "bike",
              label: "bike",
              value: "bike",
            },
          ]}
          value={selectedValue}
          onChange={(event) => {
            setSelectedValue(event.target.value);
          }}
        />
      );
    };