Skip to content

Commit a9d3f49

Browse files
committed
Tweak
1 parent 4858329 commit a9d3f49

File tree

4 files changed

+22
-14
lines changed

4 files changed

+22
-14
lines changed

packages/lab/src/__tests__/__e2e__/tabs-next/TabsNext.cy.tsx

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ describe("Given a Tabstrip", () => {
105105
cy.realPress("Tab");
106106
cy.findByRole("tab", { name: "Home" }).should("be.focused");
107107

108+
cy.wait(100);
108109
cy.realPress("ArrowLeft");
109110
cy.findByRole("tab", { name: "13 tabs hidden" }).should("be.focused");
110111

@@ -188,6 +189,7 @@ describe("Given a Tabstrip", () => {
188189
cy.findAllByRole("tab").should("have.length", 5);
189190

190191
cy.findByRole("tab", { name: "13 tabs hidden" }).realClick();
192+
cy.findByRole("tab", { name: "Checks" }).should("be.focused");
191193
cy.realPress("Enter");
192194
cy.findByRole("tab", { name: "Checks" })
193195
.should("have.attr", "aria-selected", "true")
@@ -419,16 +421,19 @@ describe("Given a Tabstrip", () => {
419421
"true",
420422
);
421423

422-
cy.get("[data-overflowbutton]").realClick();
424+
cy.findByRole("tab", { name: "15 tabs hidden" }).realClick();
425+
cy.findByRole("tab", { name: "Loans" }).should("be.focused");
426+
423427
cy.findByRole("tab", { name: "Lots" }).realClick();
428+
cy.findByRole("tab", { name: "Lots" }).should("be.focused");
424429
cy.findByRole("tab", { name: "Lots" }).should(
425430
"have.attr",
426431
"aria-selected",
427432
"true",
428433
);
429434

430435
cy.findByRole("button", { name: "Lots Close tab" }).realClick();
431-
cy.findByRole("tab", { name: "More" })
436+
cy.findByRole("tab", { name: "Transactions" })
432437
.should("have.attr", "aria-selected", "true")
433438
.and("be.focused");
434439
});
@@ -442,12 +447,11 @@ describe("Given a Tabstrip", () => {
442447
cy.mount(<Overflow />);
443448
cy.findAllByRole("tab").should("have.length", 5);
444449

445-
cy.get("[data-overflowbutton]").realClick();
450+
cy.findByRole("tab", { name: "13 tabs hidden" }).realClick();
446451
cy.wait(500);
447452

448453
// no horizontal overflow, menu should flip in horizontally
449454
cy.get("html").then((body) => {
450-
console.log(body[0]);
451455
const { clientWidth, scrollWidth } = body[0];
452456
expect(clientWidth).to.equal(scrollWidth);
453457
});

packages/lab/src/tabs-next/TabListNext.tsx

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -129,8 +129,12 @@ export const TabListNext = forwardRef<HTMLDivElement, TabListNextProps>(
129129
if (!currentTab?.stale) return;
130130
const nextIndex = currentTab.staleIndex ?? -1;
131131

132-
queueMicrotask(() => {
133-
const nextTab = itemAt(nextIndex) ?? getLast();
132+
setTimeout(() => {
133+
let nextTab = itemAt(nextIndex) ?? getLast();
134+
135+
if (nextTab?.element === overflowButtonRef.current) {
136+
nextTab = itemAt(nextIndex - 1);
137+
}
134138

135139
if (nextTab) {
136140
if (currentTabIsSelected) {
@@ -140,11 +144,12 @@ export const TabListNext = forwardRef<HTMLDivElement, TabListNextProps>(
140144
nextTab.element?.focus();
141145
}
142146
}
143-
});
147+
}, 88);
144148
});
145149

146150
useEffect(() => {
147151
const handleFocus = () => {
152+
if (!tabstripRef.current) return;
148153
handleTabRemoval();
149154
};
150155

packages/lab/src/tabs-next/hooks/useCollection.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,7 @@ export function useCollection({ wrap }: UseCollectionProps) {
6565

6666
const newItems = Array.from(itemMap.current.values());
6767
itemsRef.current = sortBasedOnDOMPosition(newItems);
68-
batchTimeout.current = null;
69-
}, 166);
68+
}, 88);
7069

7170
return () => {
7271
itemMap.current.set(item.id, {

packages/lab/src/tabs-next/hooks/useOverflow.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import {
1212
type RefObject,
1313
useEffect,
1414
useMemo,
15+
useState,
1516
} from "react";
1617
import type { TabNextProps } from "../TabNext";
1718

@@ -27,8 +28,6 @@ function getTabWidth(element: HTMLElement) {
2728
return Math.ceil(width);
2829
}
2930

30-
let pinned: string | undefined;
31-
3231
export function useOverflow({
3332
container,
3433
overflowButton,
@@ -42,6 +41,7 @@ export function useOverflow({
4241
visibleCount: Number.POSITIVE_INFINITY,
4342
isMeasuring: false,
4443
});
44+
const [pinned, setPinned] = useState(selected);
4545

4646
const pinnedValue = pinned ?? selected;
4747

@@ -214,13 +214,13 @@ export function useOverflow({
214214
[childArray, visibleCount],
215215
);
216216

217-
const hiddenSelectedIndex = hidden.findIndex(
217+
const hiddenSelected = hidden.find(
218218
(child) =>
219219
isValidElement<TabNextProps>(child) && child?.props?.value === selected,
220220
);
221221

222-
if (hiddenSelectedIndex !== -1) {
223-
pinned = selected;
222+
if (hiddenSelected) {
223+
setPinned(selected);
224224
}
225225

226226
const hiddenPinnedIndex = hidden.findIndex(

0 commit comments

Comments
 (0)