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

Accessibility issues for text and navbar in light mode #1858

Merged
merged 10 commits into from
May 22, 2023
5 changes: 5 additions & 0 deletions .changeset/little-mirrors-push.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'nextra-theme-blog': patch
---

accessibility issues for text and navbar in light mode
13 changes: 10 additions & 3 deletions packages/nextra-theme-blog/src/nav.tsx
Original file line number Diff line number Diff line change
@@ -1,29 +1,36 @@
import type { ReactElement } from 'react'
import Link from 'next/link'
import ThemeSwitch from './theme-switch'
import { useTheme } from 'next-themes'
import { useBlogContext } from './blog-context'
import { collectPostsAndNavs } from './utils/collect'

export default function Nav(): ReactElement {
const { opts, config } = useBlogContext()
const { navPages } = collectPostsAndNavs({ opts, config })
const { resolvedTheme } = useTheme()
return (
<div className="nx-mb-8 nx-flex nx-items-center nx-gap-3">
<div className="nx-flex nx-grow nx-flex-wrap nx-items-center nx-justify-end nx-gap-3">
{navPages.map(page => {
const name = page.frontMatter?.title || page.name
if (page.active) {
return (
<span
key={page.route}
className="nx-cursor-default nx-text-gray-400"
className={`nx-cursor-default ${
resolvedTheme === 'dark'
? 'nx-text-gray-400'
: 'nx-text-gray-600'
}`}
>
{page.frontMatter?.title || page.name}
{name}
</span>
)
}
return (
<Link key={page.route} href={page.route} passHref legacyBehavior>
<a>{page.frontMatter?.title || page.name}</a>
<a>{name}</a>
</Link>
)
})}
Expand Down
8 changes: 6 additions & 2 deletions packages/nextra-theme-blog/src/posts-layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { MDXTheme } from './mdx-theme'
import Nav from './nav'
import { collectPostsAndNavs } from './utils/collect'
import getTags from './utils/get-tags'
import { useTheme } from 'next-themes'

export const PostsLayout = ({
children
Expand All @@ -18,6 +19,9 @@ export const PostsLayout = ({
const router = useRouter()
const { type } = opts.frontMatter
const tagName = type === 'tag' ? router.query.tag : null
const { resolvedTheme } = useTheme()
const textColor =
resolvedTheme === 'dark' ? 'nx-text-gray-400' : 'nx-text-gray-600'
const postList = posts.map(post => {
if (tagName) {
const tags = getTags(post)
Expand All @@ -42,7 +46,7 @@ export const PostsLayout = ({
</Link>
</h3>
{description && (
<p className="nx-mb-2 nx-text-gray-400">
<p className={'nx-mb-2 ' + textColor}>
{description}
{config.readMore && (
<Link href={post.route} passHref legacyBehavior>
Expand All @@ -53,7 +57,7 @@ export const PostsLayout = ({
)}
{date && (
<time
className="nx-text-sm nx-text-gray-300"
className={'nx-text-sm ' + textColor}
dateTime={date.toISOString()}
>
{date.toDateString()}
Expand Down