ui: Select options are truncated if they don't fit on the page

If you have lots of options, they get truncated:

<Select>
  <SelectTrigger className="w-[180px]">
    <SelectValue placeholder="Theme" />
  </SelectTrigger>
  <SelectContent>
    {[...Array(100)].map((e, i) => (
      <SelectItem key={i} value={`${i}`}>
        Item number {i}
      </SelectItem>
    ))}
  </SelectContent>
</Select>

image

There is no way to scroll the elements, however Radix does scroll them. When there isn’t enough room it adds a vertical scroll thing:

image

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Reactions: 7
  • Comments: 15 (3 by maintainers)

Commits related to this issue

Most upvoted comments

You can add the following Tailwind class if position is set to popper to make it not exceed the viewport height:

<Select.Content className="max-h-[--radix-select-content-available-height]" />

Not sure if helps, but i managed to solve for myself fixing the height and specifying overflow-y: scroll;

<SelectContent
      className="overflow-y-scroll !h-[300px]"
    >
// content
</SelectContent>

You can add the following Tailwind class if position is set to popper to make it not exceed the viewport height:

<Select.Content className="max-h-[--radix-select-content-available-height]" />

Best solution for now! Cheers!

For me, the solution was to add the proper CSS variable as max height for Content, and add the ScrollUp and ScrollDown buttons around the Viewport.

(classes removed for readability)

<SelectPrimitive.Content className="max-h-[--radix-select-content-available-height]">
  <SelectPrimitive.ScrollUpButton>
    <IconChevronUp />
  </SelectPrimitive.ScrollUpButton>

  <SelectPrimitive.Viewport>
    <SelectPrimitive.Group>{children}</SelectPrimitive.Group>
  </SelectPrimitive.Viewport>

  <SelectPrimitive.ScrollDownButton>
    <IconChevronDown />
  </SelectPrimitive.ScrollDownButton>
</SelectPrimitive.Content>

I can add scrolling to <Select />. However I’d recommend checking out https://ui.shadcn.com/docs/components/command#combobox for large sets.

Is there gonna be an official fix for this? I don’t know why It hasn’t been done yet especially considering the fact the default select from radix doesn’t have this issue.

It’s easier to understand this way! I wanted to hide the button, so this is what it looks like! Thank you very much!

<SelectPrimitive.Content  className="max-h-[--radix-select-content-available-height]">
  <SelectPrimitive.ScrollUpButton />

  <SelectPrimitive.Viewport>
    <SelectPrimitive.Group>{children}</SelectPrimitive.Group>
  </SelectPrimitive.Viewport>

  <SelectPrimitive.ScrollDownButton />
</SelectPrimitive.Content>

Just came here to report that. Also, looks like it only happens when SelectContent position prop is equal to popper which is the default. Besides that, to make the arrows appear when position is equal to item-aligned, you need to add SelectPrimitive.ScrollUpButton and SelectPrimitive.ScrollDownButton to the SelectContent component.

Related: https://github.com/radix-ui/primitives/issues/1980#issuecomment-1479692521