Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Doc-site] Improve navigation semantics and page title #3589

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 8 additions & 2 deletions packages/docsite/src/components/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,16 @@ export const Layout: FC<LayoutProps> = memo(function Layout(props) {
const touchBackend = isTouchBackend()
const [dndArea, setDndArea] = useState<HTMLDivElement | null>(null)
const html5Options = useMemo(() => ({ rootElement: dndArea }), [dndArea])

const topicTitle: string = location?.pathname?.split('/').pop()
return (
<>
<Helmet title="React DnD" meta={HEADER_META} link={HEADER_LINK}>
<Helmet
title={`React DnD ${topicTitle ? '·' : ''} ${
topicTitle.charAt(0).toUpperCase() + topicTitle.slice(1)
}`}
meta={HEADER_META}
link={HEADER_LINK}
>
<html lang="en" />
<link
rel="stylesheet"
Expand Down
4 changes: 2 additions & 2 deletions packages/docsite/src/components/navbar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@ export const NavBar: FC = memo(function NavBar() {
</LogoTitle>
<LogoDescription>Drag and Drop for React</LogoDescription>
</LogoContainer>
<div>
<nav aria-label="main">
<StyledGatsbyLink to={'/docs/overview'}>Docs</StyledGatsbyLink>
<StyledGatsbyLink to={'/examples'}>Examples</StyledGatsbyLink>
<StyledWebLink href={'https://github.com/react-dnd/react-dnd/'}>
GitHub
</StyledWebLink>
</div>
</nav>
</ContentContainer>
</Container>
)
Expand Down
59 changes: 46 additions & 13 deletions packages/docsite/src/components/sidebar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,18 @@ export const Sidebar: FC<SideBarProps> = memo(function Sidebar({
groups,
location,
}) {
const navigationName = location.split('/')[1]
function renderGroup({ title, pages, debug }: PageGroup, index: number) {
const id = `${title}-${index}`
const isRendered = !debug || isDebugMode()
return isRendered ? (
<Group key={index}>
<GroupTitle>{title}</GroupTitle>
{Object.keys(pages).map((key) => renderLink(pages[key], key))}
<div role="presentation" aria-hidden="true">
<GroupTitle id={id}>{title}</GroupTitle>
</div>
<List aria-labelledby={id}>
{Object.keys(pages).map((key) => renderLink(pages[key], key))}
</List>
</Group>
) : null
}
Expand All @@ -31,17 +37,23 @@ export const Sidebar: FC<SideBarProps> = memo(function Sidebar({
const Link = isSelected ? SelectedSidebarItem : SidebarItem

return (
<Link key={key} to={pageLocation}>
<span>{title}</span>
{arrow}
</Link>
<ListItem key={key}>
<Link to={pageLocation}>
<span>{title}</span>
{arrow}
</Link>
</ListItem>
)
}

return <Container>{groups.map(renderGroup)}</Container>
return (
<Container aria-label={`${navigationName}`}>
<List>{groups.map(renderGroup)}</List>
</Container>
)
})

const Container = styled.div`
const Container = styled.nav`
flex-shrink: 0;
flex-grow: 1;

Expand All @@ -56,14 +68,35 @@ const Container = styled.div`
}
`

const Group = styled.div`
margin-bottom: ${theme.dimensions.content.padding};
const List = styled.ul`
list-style: none;
margin-block-start: 0;
margin-block-end: 0;
padding: 0;
margin: 0;
`

const GroupTitle = styled.h4`
const ListItem = styled.li`
list-style: none;
margin: 0;
margin-block-start: 0;
margin-block-end: 0;
`

const Group = styled.li`
list-style: none;
margin: 0;
margin-block-start: 0;
margin-block-end: 0;
margin-bottom: 1.5em;
`

const GroupTitle = styled.span`
border-bottom: 2px solid fade(${theme.color.accent}, 10%);
padding-bottom: 0.5em;
margin: 0 0 0.5em 0;
padding-bottom: 1em;
display: block;
font-weight: bold;
font-size: 1rem;
`

const SidebarItem = styled(GatsbyLink)`
Expand Down