Skip to content

Commit

Permalink
fix: Select should not crash if getItems returns empty array (#2623)
Browse files Browse the repository at this point in the history
Co-authored-by: Chance Strickland <[email protected]>
  • Loading branch information
benj-dobs and chaance committed Aug 10, 2024
1 parent 7aea268 commit 5105a22
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .yarn/versions/cccc0adb.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
releases:
"@radix-ui/react-select": patch

declined:
- primitives
4 changes: 2 additions & 2 deletions packages/react/select/src/Select.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -859,7 +859,7 @@ const SelectItemAlignedPosition = React.forwardRef<
const willAlignWithoutTopOverflow = contentTopToItemMiddle <= topEdgeToTriggerMiddle;

if (willAlignWithoutTopOverflow) {
const isLastItem = selectedItem === items[items.length - 1].ref.current;
const isLastItem = items.length > 0 && selectedItem === items[items.length - 1].ref.current;
contentWrapper.style.bottom = 0 + 'px';
const viewportOffsetBottom =
content.clientHeight - viewport.offsetTop - viewport.offsetHeight;
Expand All @@ -874,7 +874,7 @@ const SelectItemAlignedPosition = React.forwardRef<
const height = contentTopToItemMiddle + clampedTriggerMiddleToBottomEdge;
contentWrapper.style.height = height + 'px';
} else {
const isFirstItem = selectedItem === items[0].ref.current;
const isFirstItem = items.length > 0 && selectedItem === items[0].ref.current;
contentWrapper.style.top = 0 + 'px';
const clampedTopEdgeToTriggerMiddle = Math.max(
topEdgeToTriggerMiddle,
Expand Down

0 comments on commit 5105a22

Please sign in to comment.