实现网站无障碍导航与大型菜单
检查并改造网站导航代码,完善键盘操作、焦点管理和移动端交互,交付代码改动与验证步骤。
完整提示词
<context>
Site navigation is a list of links, so the ARIA `menu` and `menubar` roles are almost always wrong for it: they promise application-menu behaviour (arrow keys only, Tab leaves the menu, items are commands), switch screen readers into a mode that hides normal link navigation, and are rarely implemented completely. The robust pattern is the disclosure navigation: a `nav` with a name, a list of links, and for each submenu a real `button` with `aria-expanded` that shows and hides a nested list. Common failures: submenus that open only on hover, so keyboard and touch users cannot reach them; a top-level item that is both a link and a submenu trigger; hover menus that close when the pointer crosses a small gap; dropdowns that cannot be dismissed with Escape (WCAG 1.4.13 applies to content shown on hover or focus); mobile "hamburger" buttons with no name, no expanded state and a menu that sits behind the page in tab order; and no indication of the current page (`aria-current="page"`). If the top item must stay a link, put a separate disclosure button next to it, named "More about Products".
</context>
<task>
Make this navigation accessible using the disclosure pattern.
<navigation>
{{navigation}}
</navigation>
Framework: {{framework}}
1. Read the header, navigation and menu code, including any library. List problems against the context; mark inferences.
2. State the pattern: disclosure navigation with links. If the codebase uses `role="menu"` for site links, explain why you are removing it.
3. Implement: a `nav` with an accessible name (and distinct names if there are several), a list of links, a `button` with `aria-expanded` and `aria-controls` for each submenu, the current page link with `aria-current="page"`, and a visible focus style.
4. Behaviour: click, tap, Enter and Space toggle submenus; Escape closes the open submenu and returns focus to its button; opening one submenu closes the others; moving focus out of the navigation closes it; hover can still open submenus for mouse users, with a small delay and a pointer path that does not close the panel when crossing gaps. Optional arrow-key support between top-level buttons is fine, but Tab must keep working.
5. Mega menus: give each panel headings for its groups, keep the DOM order equal to the visual order, and make the panel reachable at 400% zoom without hiding content off screen.
6. Mobile menu: a named toggle button with `aria-expanded`; when open as an overlay, treat it as a modal (focus inside, background inert, Escape closes, focus returns to the toggle); when it pushes content down, it can stay a simple disclosure.
7. Write tests for names, expanded states, Escape and focus return; run them. Give a manual keyboard, touch and screen-reader check.
</task>
<constraints>
- Do not use `role="menu"`, `menubar` or `menuitem` for site navigation links.
- Do not make submenus reachable only on hover.
- Do not change the information architecture or link labels unless a label is unclear out of context; flag it instead.
{{> guardrails/scope-discipline}}
{{> guardrails/verify-before-done}}
</constraints>
<output_format>
## Problems found
Numbered, with who is blocked and the WCAG criterion.
## Pattern
Short paragraph.
## Changes
Diffs with file paths.
## Keyboard and pointer behaviour
Table: input | result.
## Tests and manual check
Test code, command result, manual steps.
</output_format>可替换内容
- {{navigation}}
- {{framework}}
- {{> guardrails/scope-discipline}}
- {{> guardrails/verify-before-done}}
分类与标签
编程开发、网站导航、无障碍开发、键盘交互、移动端菜单