Skip to content

Commit c0bc4dd

Browse files
authored
fix(sidebar): use placeholders in select menu (#7871)
* fix(#7646): add default value if current page is missing in sidebar sometimes current page can be missing from navigation data if the entry is not present in the navigation.json file. In those cases it shows an empty select box on smaller screens. This PR chooses the first item in the navigation tree if the current page is missing from there * refactor(#7646): update the select component to have a default placeholder of the window title in site * refactor(#7646): update the title source to that of frontmatter
1 parent 6272aab commit c0bc4dd

File tree

2 files changed

+6
-0
lines changed

2 files changed

+6
-0
lines changed

apps/site/components/withSidebar.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import type { RichTranslationValues } from 'next-intl';
77
import type { FC } from 'react';
88

99
import Link from '#site/components/Link';
10+
import { useClientContext } from '#site/hooks';
1011
import { useSiteNavigation } from '#site/hooks/server';
1112
import { useRouter } from '#site/navigation.mjs';
1213
import type { NavigationKeys } from '#site/types';
@@ -23,6 +24,7 @@ const WithSidebar: FC<WithSidebarProps> = ({ navKeys, context, ...props }) => {
2324
const locale = useLocale();
2425
const t = useTranslations();
2526
const { push } = useRouter();
27+
const { frontmatter } = useClientContext();
2628
const sideNavigation = getSideNavigation(navKeys, context);
2729

2830
const mappedSidebarItems =
@@ -40,6 +42,7 @@ const WithSidebar: FC<WithSidebarProps> = ({ navKeys, context, ...props }) => {
4042
groups={mappedSidebarItems}
4143
pathname={pathname.replace(`/${locale}`, '')}
4244
title={t('components.common.sidebar.title')}
45+
placeholder={frontmatter?.title}
4346
onSelect={push}
4447
as={Link}
4548
{...props}

packages/ui-components/Containers/Sidebar/index.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ type SidebarProps = {
1515
onSelect: (value: string) => void;
1616
as?: LinkLike;
1717
showProgressionIcons?: boolean;
18+
placeholder?: string;
1819
};
1920

2021
const SideBar: FC<PropsWithChildren<SidebarProps>> = ({
@@ -25,6 +26,7 @@ const SideBar: FC<PropsWithChildren<SidebarProps>> = ({
2526
as,
2627
showProgressionIcons = false,
2728
children,
29+
placeholder,
2830
}) => {
2931
const selectItems = groups.map(({ items, groupName }) => ({
3032
label: groupName,
@@ -44,6 +46,7 @@ const SideBar: FC<PropsWithChildren<SidebarProps>> = ({
4446
label={title}
4547
values={selectItems}
4648
defaultValue={currentItem?.value}
49+
placeholder={placeholder}
4750
onChange={onSelect}
4851
className={styles.mobileSelect}
4952
/>

0 commit comments

Comments
 (0)