diff --git a/packages/react-core/src/components/Tabs/Tab.tsx b/packages/react-core/src/components/Tabs/Tab.tsx index a626b1e4a77..0e53035e43e 100644 --- a/packages/react-core/src/components/Tabs/Tab.tsx +++ b/packages/react-core/src/components/Tabs/Tab.tsx @@ -129,7 +129,7 @@ const TabBase: React.FunctionComponent = ({ ); useEffect(() => { - setAccentStyles(true); + setAccentStyles(); }, [title, actions]); return ( diff --git a/packages/react-core/src/components/Tabs/__tests__/Tabs.test.tsx b/packages/react-core/src/components/Tabs/__tests__/Tabs.test.tsx index 3aa1d847bd4..f643e69cdcc 100644 --- a/packages/react-core/src/components/Tabs/__tests__/Tabs.test.tsx +++ b/packages/react-core/src/components/Tabs/__tests__/Tabs.test.tsx @@ -1,4 +1,4 @@ -import { render, screen, act } from '@testing-library/react'; +import { render, screen, act, waitFor } from '@testing-library/react'; import userEvent from '@testing-library/user-event'; import { Tabs, TabsProps } from '../Tabs'; import styles from '@patternfly/react-styles/css/components/Tabs/tabs'; @@ -1006,3 +1006,34 @@ test('should not render tablist aria-label or aria-labelledby when neither is pr expect(asFragment()).toMatchSnapshot(); }); + +test(`Does not render with class ${styles.modifiers.initializingAccent} when a controlled tab is selected`, async () => { + const user = userEvent.setup(); + const ControlledTabs = () => { + const [activeKey, setActiveKey] = useState(0); + + return ( + setActiveKey(eventKey)}> + Tab item 1} /> + Tab item 2} /> + + ); + }; + + render(); + + // Wait for the initial mount accent measurement to settle. + await waitFor(() => expect(screen.getByRole('region')).not.toHaveClass(styles.modifiers.initializingAccent)); + + // The initializing class is removed by a 0ms timeout, so track whether it + // ever transiently appears while selecting a tab with inline title elements. + const classLog: string[] = []; + const tabsRoot = screen.getByRole('region'); + const observer = new MutationObserver(() => classLog.push(tabsRoot.className)); + observer.observe(tabsRoot, { attributes: true, attributeFilter: ['class'] }); + + await user.click(screen.getByRole('tab', { name: 'Tab item 2' })); + + observer.disconnect(); + expect(classLog.some((className) => className.includes(styles.modifiers.initializingAccent))).toBe(false); +});