Skip to content

Commit

Permalink
Investigate tab resize
Browse files Browse the repository at this point in the history
  • Loading branch information
joshwooding committed Feb 19, 2025
1 parent 0c2b29b commit 18e8a1c
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
1 change: 1 addition & 0 deletions packages/lab/src/tabs-next/TabListNext.css
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
min-height: calc(var(--salt-size-base) + var(--salt-spacing-100));
gap: var(--salt-spacing-100);
max-width: 100%;
width: 100%;
}

.saltTabListNext-center {
Expand Down
18 changes: 15 additions & 3 deletions packages/lab/src/tabs-next/hooks/useOverflow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ export function useOverflow({
}
}

return Math.max(1, newVisibleCount);
return Math.max(0, newVisibleCount);
}
return visibleCount;
};
Expand Down Expand Up @@ -137,6 +137,18 @@ export function useOverflow({
updateOverflow();
}, [selected]);

useIsomorphicLayoutEffect(() => {
const handleWindowResize = () => {
updateOverflow();
};

targetWindow?.addEventListener("resize", handleWindowResize);

return () => {
targetWindow?.removeEventListener("resize", handleWindowResize);
};
});

useEffect(() => {
const element = container?.current;
if (!element) return;
Expand All @@ -163,8 +175,8 @@ export function useOverflow({
}, [container, updateOverflow]);

const childArray = useMemo(() => Children.toArray(children), [children]);
const visible = childArray.slice(0, visibleCount || 1);
const hidden = childArray.slice(visibleCount || 1);
const visible = childArray.slice(0, visibleCount);
const hidden = childArray.slice(visibleCount);

const hiddenSelectedIndex = hidden.findIndex(
// @ts-ignore
Expand Down

0 comments on commit 18e8a1c

Please # to comment.