Skip to content

Commit 6f14ac5

Browse files
authored
Merge pull request #2652 from ably/web-4440-native-desktop-nav
[WEB-4443] Semantic links for desktop header tabs
2 parents 6016bc4 + 6c4b265 commit 6f14ac5

File tree

6 files changed

+32
-18
lines changed

6 files changed

+32
-18
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
"validate-llms-txt": "ts-node bin/validate-llms.txt.ts"
4141
},
4242
"dependencies": {
43-
"@ably/ui": "17.0.0",
43+
"@ably/ui": "17.1.0",
4444
"@codesandbox/sandpack-react": "^2.20.0",
4545
"@codesandbox/sandpack-themes": "^2.0.21",
4646
"@gfx/zopfli": "^1.0.15",

src/components/Examples/ExamplesList.tsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,18 @@
11
import React from 'react';
22
import { examples } from '../../data/examples/';
3+
import Link from '../Link';
34

45
const ExamplesList: React.FC = () => {
56
return (
67
<div className="flex flex-col gap-6 py-3">
78
{examples.map((example) => (
8-
<a
9+
<Link
910
key={example.name}
10-
href={'#'}
11+
to={example.id ? `/examples/${example.id}` : '#'}
1112
className="px-4 ui-text-label1 text-neutral-1000 dark:text-neutral-300 font-bold hover:text-neutral-1300 dark:hover:text-neutral-000"
1213
>
1314
{example.name}
14-
</a>
15+
</Link>
1516
))}
1617
</div>
1718
);

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" />,

src/components/Layout/LeftSidebar.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ const LeftSidebar = ({ inHeader = false }: LeftSidebarProps) => {
228228
'overflow-y-auto',
229229
hasScrollbar ? 'md:pr-2' : 'md:pr-4',
230230
)}
231-
style={sidebarAlignmentStyles}
231+
style={!inHeader ? sidebarAlignmentStyles : {}}
232232
id={inHeader ? 'mobile-nav' : 'left-nav'}
233233
data={productNavData}
234234
{...commonAccordionOptions(null, activePage.tree[0]?.index, true, inHeader)}

yarn.lock

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@
77
resolved "https://registry.yarnpkg.com/@aashutoshrathi/word-wrap/-/word-wrap-1.2.6.tgz#bd9154aec9983f77b3a034ecaa015c2e4201f6cf"
88
integrity sha512-1Yjs2SvM8TflER/OD3cOjhWWOZb58A2t7wpE2S9XfBYTiIl+XFhQG2bjy4Pu1I+EAlCNUzRDYDdFwFYUKvXcIA==
99

10-
"@ably/ui@17.0.0":
11-
version "17.0.0"
12-
resolved "https://registry.yarnpkg.com/@ably/ui/-/ui-17.0.0.tgz#c3dce13df783fd06d374a5312702e4b3692dbe21"
13-
integrity sha512-y615+E62OH5EjxElUk6CR5/BRkLkE2Q/mawcxlueNWOxm0TyYVn73KO8OQGIsUumykwy1QpYad/KZqhc1jaw+w==
10+
"@ably/ui@17.1.0":
11+
version "17.1.0"
12+
resolved "https://registry.yarnpkg.com/@ably/ui/-/ui-17.1.0.tgz#5c3612d37cb75668f2ef3058ad96c0bc17761ed9"
13+
integrity sha512-tRztxGCwzJ9+9yy/1TurefoTXDjWTvTluOzsQzeZIGD6uRaF/JrA0WggtiYnFnw0FKudQN57ENvXpHpfOZunIg==
1414
dependencies:
1515
"@radix-ui/react-accordion" "^1.2.1"
1616
"@radix-ui/react-navigation-menu" "^1.2.4"

0 commit comments

Comments
 (0)