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

    Select

    The Select component allows the user to click and select an item from a list of options.

    View source code
    • Usage
    • Props

    Import

    • Select: The select component
    • DropdownItem: A helper component designed to represent a complex item inside a list.

    Basic usage

    type Option = { key: string; label: string };
    
    const costCenters: (Option & { owner: string })[] = [
      {
        key: "marketing",
        label: "Marketing",
        owner: "Michael Murphy",
      },
      // ...
    ];
    
    const Demo = () => {
      const [selectedOption, setSelectedOption] = useState<Option>();
    
      return (
        <Select
          fit="parent"
          placeholder="Select a cost center"
          options={costCenters}
          value={selectedOption}
          onSelect={setSelectedOption}
        />
      );
    };
    

    Placement

    Use the placement prop to move the list of options above or below the Select.

    <>
      <Select placement="bottom-start" {...otherProps} />
      <Select placement="top-start" {...otherProps} />
    </>
    

    Customization

    Max height

    The dropdownContentMaxHeight prop is used to define a maximum height for the select's dropdown content. It defaults to 152px.

    Visibility behavior

    To indicate that the dropdown is scrollable, please ensure the last visible item is partially hidden. For example, the default value of 152px result in the fourth item being cut off halfway, signaling to the user that there are more items to scroll through.

    <Select dropdownContentMaxHeight="232px" {...otherProps} />
    

    Customized option

    Use the renderOption prop to customize how options are rendered.

    Visibility behavior

    If you customize the rendering of options, which likely involves changing the default height of a dropdown item (40px), you should also use the dropdownContentMaxHeight prop to adjust the default height of the DropdownContent accordingly.

    <Select
      renderOption={(option: CostCenter, optionState) => (
        <DropdownItem
          label={`${option.label} (${option.owner})`}
          {...optionState}
        />
      )}
      {...otherProps}
    />