diff --git a/packages/components/src/ui/select.tsx b/packages/components/src/ui/select.tsx index c62399fd..a2512bcb 100644 --- a/packages/components/src/ui/select.tsx +++ b/packages/components/src/ui/select.tsx @@ -1,8 +1,9 @@ import { Popover } from '@radix-ui/react-popover'; +import * as PopoverPrimitive from '@radix-ui/react-popover'; import { Check as DefaultCheckIcon, ChevronDown as DefaultChevronIcon } from 'lucide-react'; import * as React from 'react'; import { useOverlayTriggerState } from 'react-stately'; -import { PopoverContent, PopoverTrigger } from './popover'; +import { PopoverTrigger } from './popover'; import { cn } from './utils'; export interface SelectOption { @@ -52,11 +53,7 @@ export function Select({ const triggerRef = React.useRef(null); const popoverRef = React.useRef(null); const selectedItemRef = React.useRef(null); - const [menuWidth, setMenuWidth] = React.useState(undefined); - - React.useEffect(() => { - if (triggerRef.current) setMenuWidth(triggerRef.current.offsetWidth); - }, []); + // No need for JavaScript width measurement - Radix provides --radix-popover-trigger-width CSS variable // Scroll to selected item when dropdown opens React.useEffect(() => { @@ -130,15 +127,27 @@ export function Select({ - for PopoverContent to ensure keyboard accessibility and focus management - role="listbox" - id={listboxId} - style={{ width: menuWidth ? `${menuWidth}px` : undefined }} - > -
+ + for PopoverContent to ensure keyboard accessibility and focus management + role="listbox" + id={listboxId} + style={{ width: 'var(--radix-popover-trigger-width)' }} + data-slot="popover-content" + > +
-
    +
      {filtered.length === 0 &&
    • No results.
    • } {filtered.map((option) => { const isSelected = option.value === value; @@ -208,7 +217,8 @@ export function Select({ })}
- +
+
); }