Skip to Content
文档

跳过导航

“跳过导航链接”允许键盘用户跳转到页面的主要内容。

SourceStorybook
Skip to Content

Navigation

This represents a navigation area that users might want to skip over.

Main Content

This is the main content area. When users press Tab and then Enter on the "Skip to Content" link, focus will jump directly here, bypassing the navigation.

用法

¥Usage

屏幕阅读器和键盘用户跳过导航链接和目标容器。

¥Skip Navigation link and destination container for screen readers and keyboard users.

根据 WebAIM.org 基于 WCAG 2.4.1(绕过块 - A 级) 组件,由于主要内容并非总是用户在页面上遇到的第一个部分,因此强烈建议包含一个跳过链接,以便用户能够跳过存在于多个页面上的内容。导航链接是最常被跳过的。

¥Per WebAIM.org on WCAG 2.4.1 (Bypass Blocks - Level A), because the main content is not always the first section that the user encounters on a page, it is strongly recommended to include a skip link for users to be able to bypass content that is present on multiple pages. Navigation links are the most common skipped.

使用屏幕阅读器或专用软件的用户可以通过标题或 main 区域跳过内容,但对于主要使用键盘的视力正常用户来说,这还不够。

import { SkipNavContent, SkipNavLink } from "@chakra-ui/react"
<SkipNavLink>Skip to content</SkipNavLink>
<SkipNavContent />

示例

¥Examples

基本用法

¥Basic Usage

理想情况下,SkipNavLink 组件应该是用户在页面加载后开始导航时遇到的首批项目之一。因此,建议将其放置在应用尽可能高的位置。

¥The SkipNavLink component ideally needs to be one of the first items a user encounters when they begin navigating a page after load. Therefore, it is recommended to place it as high as possible in the app.

它会渲染一个 a 标签,并自动创建一个带有 href 属性的链接,该链接将指向 SkipNavContent

¥It renders an a tag and automatically creates a link with an href attribute that will point to SkipNavContent.

SkipNavContent 组件用作链接的目标,以将键盘焦点置于第一个主要内容上。它会渲染一个 div,既可以作为自闭合组件,也可以封装主要内容。

¥The SkipNavContent component is used as a target for the link to place keyboard focus on the first piece of main content. It renders a div and can either be a self-closing component, or wrap the main content.

Skip to Content

Navigation

This represents a navigation area that users might want to skip over.

Main Content

This is the main content area. When users press Tab and then Enter on the "Skip to Content" link, focus will jump directly here, bypassing the navigation.

自定义 ID

¥Custom ID

你可以使用 id props 提供自定义 id 值,但你必须在两个组件中都使用此 props 和值,否则它们将不匹配。

¥You can supply a custom id value using the id prop but you will have to use this prop and value in both components, or they will not match.

Skip to Main Content

Header & Navigation

This example uses a custom ID "main-content" for both components to ensure they match.

Main Content (Custom ID)

Both the SkipNavLink and SkipNavContent use the same custom ID "main-content" to ensure proper linking and focus management.

包含主要内容

¥With Main Content

SkipNavContent 组件可以封装你的主要内容区域,以确保正确的焦点管理。

¥The SkipNavContent component can wrap your main content area to ensure proper focus management.

Skip to Content

Site Header

• Home

• About

• Services

• Contact

Welcome to Our Site

This is the main content area. The SkipNavContent component wraps this entire section, making it the target for the skip navigation link.

When keyboard users press Tab to focus the "Skip to Content" link and then press Enter, focus will jump directly to this content area, bypassing all the navigation items above.

This is especially helpful for users with screen readers or those who navigate primarily with keyboards.

实际操作中

¥In Action

你可以在此页面上查看这些组件的实际效果!

¥You can see these components in action on this page!

  1. 将光标放在浏览器的地址栏中。
  2. 从 URL 中移除所有 ID 查询。(即 /skip-nav#usage
  3. 点击 Enter 重新加载页面,然后点击 Tab。“跳过导航”链接将显示在左上角。
  4. 点击链接上的 Enter 将带你到文档内容的顶部。

Previous

展示

Next

视觉隐藏