Skip to content

Commit 7fe8f42

Browse files
authored
Merge pull request #2918 from ClickHouse/p_issue_215
highlight top selected menu
2 parents 4ee5db0 + 0afe61d commit 7fe8f42

File tree

4 files changed

+39
-3
lines changed

4 files changed

+39
-3
lines changed

sidebars.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1443,7 +1443,7 @@ const sidebars = {
14431443
},
14441444
],
14451445
},
1446-
],
1446+
],
14471447
russia: [
14481448
{
14491449
type: "autogenerated",

src/components/DocsCategoryDropdown/index.jsx

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import React, { useState, useRef, useEffect } from 'react';
22
import { useHistory } from 'react-router-dom';
3-
import Link from '@docusaurus/Link'
3+
import Link from '@docusaurus/Link';
4+
import {useDocsSidebar} from '@docusaurus/theme-common/internal';
45
import styles from './styles.module.css';
56

67
function DocsCategoryDropdown({ dropdownCategory }) {
@@ -46,6 +47,19 @@ function DocsCategoryDropdown({ dropdownCategory }) {
4647
}
4748
}, [isOpen]); // This runs when the dropdown is opened
4849

50+
let sidebar = null;
51+
52+
// Safely call useDocsSidebar
53+
try {
54+
sidebar = useDocsSidebar();
55+
} catch (e) {
56+
}
57+
58+
// Guard against undefined sidebar
59+
const isSelected = sidebar && sidebar.name && dropdownCategory
60+
? sidebar.name === dropdownCategory.sidebar
61+
: false;
62+
4963
return (
5064
<div
5165
className={styles.docsNavDropdownContainer}
@@ -56,7 +70,9 @@ function DocsCategoryDropdown({ dropdownCategory }) {
5670
className={styles.docsNavDropdownToolbarLink}
5771
ref={triggerRef} // Attach the ref to the individual link that triggers the dropdown
5872
>
59-
<Link className={styles.docsNavDropdownToolbarTopLevelLink} href={dropdownCategory.link}>{dropdownCategory.title}</Link> <DropdownCaret />
73+
<Link className={`${styles.docsNavDropdownToolbarTopLevelLink} ${
74+
isSelected ? styles.docsNavSelected : ''
75+
}`} href={dropdownCategory.link}>{dropdownCategory.title}</Link> <DropdownCaret />
6076
</span>
6177
{isOpen && (
6278
<DropdownContent

src/components/DocsCategoryDropdown/styles.module.css

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,18 @@
3333
color: white;
3434
}
3535

36+
.docsNavSelected {
37+
color: black;
38+
text-decoration: underline;
39+
text-underline-offset: 4px;
40+
}
41+
42+
[data-theme="dark"] .docsNavSelected {
43+
color: white;
44+
text-decoration: underline;
45+
text-underline-offset: 4px;
46+
}
47+
3648
.docsNavDropdownMenu {
3749
position: absolute;
3850
top: 100%;

src/theme/Navbar/Content/index.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ function NavbarItems({ items }) {
4242
const dropdownCategories = [{
4343
title: 'Getting Started',
4444
description: 'Learn how to use ClickHouse',
45+
sidebar: 'docs',
4546
link: '/docs',
4647
menuItems: [
4748
{
@@ -80,6 +81,7 @@ const dropdownCategories = [{
8081
{
8182
title: 'Cloud',
8283
description: 'The fastest way to deploy ClickHouse',
84+
sidebar: 'cloud',
8385
link: '/docs/en/cloud/overview',
8486
menuItems: [
8587
{
@@ -122,6 +124,7 @@ const dropdownCategories = [{
122124
{
123125
title: 'Managing Data',
124126
description: 'How to manage data in ClickHouse',
127+
sidebar: 'managingData',
125128
link: '/docs/en/updating-data',
126129
menuItems: [
127130
{
@@ -149,6 +152,7 @@ const dropdownCategories = [{
149152
{
150153
title: 'Server Admin',
151154
description: 'Manage and deploy ClickHouse',
155+
sidebar: 'serverAdmin',
152156
link: '/docs/en/architecture/introduction',
153157
menuItems: [
154158
{
@@ -181,6 +185,7 @@ const dropdownCategories = [{
181185
{
182186
title: 'SQL Reference',
183187
description: 'Reference documentation for ClickHouse features',
188+
sidebar: 'sqlreference',
184189
link: '/docs/en/sql-reference',
185190
menuItems: [
186191
{
@@ -208,6 +213,7 @@ const dropdownCategories = [{
208213
{
209214
title: 'Integrations',
210215
description: 'Integrations, clients, and drivers to use with ClickHouse',
216+
sidebar: 'integrations',
211217
link: '/docs/en/integrations',
212218
menuItems: [
213219
{
@@ -255,6 +261,7 @@ const dropdownCategories = [{
255261
{
256262
title: 'chDB',
257263
description: 'chDB is an embedded version of ClickHouse',
264+
sidebar: 'chdb',
258265
link: '/docs/en/chdb',
259266
menuItems: [
260267
{
@@ -277,6 +284,7 @@ const dropdownCategories = [{
277284
{
278285
title: 'About',
279286
link: '/docs/en/about-clickhouse',
287+
sidebar: 'aboutClickHouse',
280288
description: 'Learn more about ClickHouse',
281289
menuItems: [
282290
{

0 commit comments

Comments
 (0)