Skip to content

Commit 2195004

Browse files
committed
fix: supply Gatsby link tabs to header TabMenu
1 parent d9a07c7 commit 2195004

File tree

2 files changed

+22
-9
lines changed

2 files changed

+22
-9
lines changed

src/components/Layout/Header.test.tsx

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,14 @@ jest.mock('./LanguageSelector', () => ({
3737
LanguageSelector: jest.fn(() => <div>LanguageSelector</div>),
3838
}));
3939

40+
jest.mock('../Link', () => {
41+
const MockLink: React.FC<{ to: string; children: React.ReactNode; className?: string }> = ({ children }) => (
42+
<a>{children}</a>
43+
);
44+
MockLink.displayName = 'MockLink';
45+
return MockLink;
46+
});
47+
4048
describe('Header', () => {
4149
beforeEach(() => {
4250
document.body.innerHTML = '';

src/components/Layout/Header.tsx

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
import React, { useContext } from 'react';
2-
import { navigate, useLocation } from '@reach/router';
2+
import { useLocation } from '@reach/router';
33
import Icon from '@ably/ui/core/Icon';
44
import AblyHeader from '@ably/ui/core/Header';
55
import { SearchBar } from '../SearchBar';
66
import LeftSidebar from './LeftSidebar';
77
import UserContext from 'src/contexts/user-context';
88
import ExamplesList from '../Examples/ExamplesList';
99
import TabMenu from '@ably/ui/core/TabMenu';
10+
import Link from '../Link';
1011

1112
type HeaderProps = {
1213
searchBar?: boolean;
@@ -23,18 +24,22 @@ const Header: React.FC<HeaderProps> = ({ searchBar = true }) => {
2324
account: userContext.sessionState.account ?? { links: { dashboard: { href: '#' } } },
2425
};
2526

26-
const tabs = ['Docs', 'Examples'];
27-
const tabLinks = ['/docs', '/examples'];
27+
const desktopTabs = [
28+
<Link key="docs" to="/docs" className="p-4">
29+
Docs
30+
</Link>,
31+
<Link key="examples" to="/examples" className="p-4">
32+
Examples
33+
</Link>,
34+
];
35+
const mobileTabs = ['Docs', 'Examples'];
2836

2937
return (
3038
<AblyHeader
3139
nav={
3240
<TabMenu
33-
tabs={tabs}
34-
tabClassName="ui-text-menu3 !px-4"
35-
tabOnClick={(index) => {
36-
navigate(tabLinks[index] ?? '#');
37-
}}
41+
tabs={desktopTabs}
42+
tabClassName="!p-0"
3843
options={{
3944
underline: false,
4045
flexibleTabHeight: true,
@@ -44,7 +49,7 @@ const Header: React.FC<HeaderProps> = ({ searchBar = true }) => {
4449
}
4550
mobileNav={
4651
<TabMenu
47-
tabs={tabs}
52+
tabs={mobileTabs}
4853
contents={[
4954
<LeftSidebar inHeader key="nav-mobile-documentation-tab" />,
5055
<ExamplesList key="nav-mobile-examples-tab" />,

0 commit comments

Comments
 (0)