Skip to content

Commit 838e7fd

Browse files
Add width debugging and ensure inner content takes full width
- Add console logging to track menuWidth changes and ResizeObserver updates - Add w-full class to inner div and ul to ensure content takes full width - This should help debug why dropdown isn't matching full container width - Inner content should now properly expand to match the applied width style
1 parent e1409b7 commit 838e7fd

1 file changed

Lines changed: 18 additions & 4 deletions

File tree

packages/components/src/ui/select.tsx

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,16 @@ export function Select({
5858
React.useEffect(() => {
5959
if (!triggerRef.current) return;
6060

61-
// Set initial width immediately (original behavior)
62-
setMenuWidth(triggerRef.current.offsetWidth);
61+
const updateWidth = () => {
62+
if (triggerRef.current) {
63+
const width = triggerRef.current.offsetWidth;
64+
console.log('Setting menu width to:', width); // Debug log
65+
setMenuWidth(width);
66+
}
67+
};
68+
69+
// Set initial width immediately
70+
updateWidth();
6371

6472
// Add ResizeObserver for dynamic width tracking if available
6573
if (typeof ResizeObserver !== 'undefined') {
@@ -69,6 +77,7 @@ export function Select({
6977
const width = entry.borderBoxSize?.[0]?.inlineSize ??
7078
entry.contentBoxSize?.[0]?.inlineSize ??
7179
(entry.target as HTMLElement).offsetWidth;
80+
console.log('ResizeObserver detected width change:', width); // Debug log
7281
setMenuWidth(width);
7382
}
7483
});
@@ -78,6 +87,11 @@ export function Select({
7887
}
7988
}, []); // Only run once - observer handles all future changes
8089

90+
// Debug effect to log menuWidth changes
91+
React.useEffect(() => {
92+
console.log('menuWidth changed to:', menuWidth);
93+
}, [menuWidth]);
94+
8195
// Scroll to selected item when dropdown opens
8296
React.useEffect(() => {
8397
if (popoverState.isOpen && selectedItemRef.current) {
@@ -170,7 +184,7 @@ export function Select({
170184
style={{ width: menuWidth ? `${menuWidth}px` : undefined }}
171185
data-slot="popover-content"
172186
>
173-
<div className="bg-white p-1.5 rounded-md focus:outline-none sm:text-sm">
187+
<div className="bg-white p-1.5 rounded-md focus:outline-none sm:text-sm w-full">
174188
<div className="px-1.5 pb-1.5">
175189
<SearchInput
176190
type="text"
@@ -200,7 +214,7 @@ export function Select({
200214
className="w-full h-9 rounded-md bg-white px-2 text-sm leading-none focus:ring-0 focus:outline-none border-0"
201215
/>
202216
</div>
203-
<ul className="max-h-[200px] overflow-y-auto rounded-md">
217+
<ul className="max-h-[200px] overflow-y-auto rounded-md w-full">
204218
{filtered.length === 0 && <li className="px-3 py-2 text-sm text-gray-500">No results.</li>}
205219
{filtered.map((option) => {
206220
const isSelected = option.value === value;

0 commit comments

Comments
 (0)