Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/cyan-toes-happen.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@ebay/ui-core-react": patch
---

prevent onSelect from firing on initial render
8 changes: 6 additions & 2 deletions packages/ebayui-core-react/src/ebay-tabs/tabs.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { cloneElement, FC, KeyboardEvent, useEffect, useState } from "react";
import React, { cloneElement, FC, KeyboardEvent, useEffect, useRef, useState } from "react";
import classNames from "classnames";

import { handleActionKeydown, handleLeftRightArrowsKeydown } from "../common/event-utils";
Expand Down Expand Up @@ -61,8 +61,12 @@ const Tabs: FC<TabsProps> = ({
});
};

const prevIndex = useRef(index);
useEffect(() => {
handleSelect(index);
if (prevIndex.current !== index) {
prevIndex.current = index;
handleSelect(index);
Copy link

Copilot AI Apr 3, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The effect still calls handleSelect(index), which triggers onSelect. This means onSelect will fire for any prop-driven selectedIndex change after mount (not just user interaction), and it will also double-fire in a controlled pattern where the parent updates selectedIndex in response to onSelect (click triggers onSelect, then the prop change triggers onSelect again). Consider syncing internal state from the selectedIndex prop in the effect without calling onSelect (e.g., update selectedIndex state directly), so onSelect is reserved for user-initiated selection changes.

Suggested change
handleSelect(index);
setSelectedIndex(index);
setFocusedIndex(index);

Copilot uses AI. Check for mistakes.
}
}, [index]);
Comment on lines 65 to 70
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should remove the useEffect instead. We already call handleSelect on click

Comment on lines +64 to 70
Copy link

Copilot AI Apr 3, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add/adjust unit coverage for this behavior (Vitest tests exist for EbayTabs): at minimum, assert onSelect is not called on initial mount, and (if selectedIndex is used in a controlled pattern) that a single user click results in a single onSelect call (no extra call from prop-sync). This will prevent regressions of the mount/double-fire issues.

Copilot generated this review using guidance from repository custom instructions.

const isLarge = size === "large";
Expand Down