Navigation Menu Button Example
This example demonstrates the menu button 설계 패턴 for a button that displays a menu of link targets. The menu items are made from HTML links, so they maintain their HTML link behaviors. That is, activating a menuitem loads the link target, and the browser's link context menu and associated actions are available.
In this implementation, an HTML button
element reveals a menu structure made with an HTML ul
element.
The menuitem
role is on the HTML a
element contained by each li
element so link behaviors are available when focus is set on the menu item.
Another reason for applying the menuitem
role to the a
element instead of the li
element is that the semantics of descendants of menuitem
elements are not exposed in the accessibility tree.
That is, an item in a menu can only be a menuitem
because accessibility APIs do not enable assistive technologies to render elements contained inside of an item in a menu.
For a more detailed description of this constraint, see
Roles That Automatically Hide Semantics by Making Their Descendants Presentational.
유사한 예는 다음과 같습니다:
- Action Menu Button Example Using element.focus(): A button that opens a menu of actions or commands where focus in the menu is managed using
element.focus()
. - Action Menu Button Example Using aria-activedescendant: A button that opens a menu of actions or commands where focus in the menu is managed using aria-activedescendant.
Example
접근성 특성
- A down arrow icon is included to help users understand that the button opens a menu.
- To support operating system high contrast settings:
- Because transparent borders are visible on some systems with operating system high contrast settings enabled, transparency cannot be used to create a visual difference between the element that is focused an other elements. Instead of using transparency, the focused element has a thicker border and less padding. When an element receives focus, its border changes from 1 to 3 pixels and padding is reduced by 2 pixels. When an element loses focus, its border changes from 3 pixels to 1 and padding is increased by 2 pixels.
- Because background color and text color styles can be overridden by operating system high contrast settings, a border is used to ensure the button has a visible boundary when high contrast mode is enabled.
-
To ensure the arrow icons used to indicate the expanded or collapsed state have sufficient contrast with the background when high contrast settings invert colors, the CSS
currentcolor
value for thefill
andstroke
properties of the SVGpolygon
element is used to synchronize the color with text content. If specific colors are used to specify thefill
andstroke
properties, these colors will remain the same in high contrast mode, which could lead to insufficient contrast between the icon and the background or even make the icon invisible if its color matches the high contrast mode background.
키보드 지원
Menu Button
키 | 기능 |
---|---|
Down Arrow Space Enter |
Opens menu and moves focus to first menuitem |
Up Arrow | Opens menu and moves focus to last menuitem |
Menu
Key | 기능 |
---|---|
Space Enter |
Activates the menu item, which is equivalent to activating the link element from which the menu item is made. |
Escape |
|
Up Arrow |
|
Down Arrow |
|
Home | Moves focus to the first menu item. |
End | Moves focus to the last menu item. |
A-Z a-z |
|
Role, Property, State, Tabindex 어트리뷰트
Menu Button
역할(role) | 어트리뷰트 | 엘리먼트 | 사용법 |
---|---|---|---|
aria-haspopup="true" |
button
|
|
|
aria-controls="IDREF" |
button
|
|
|
aria-expanded="true" |
button |
|
Note
The label for the button is provided by the text content of the button
element.
Menu
역할(role) | 어트리뷰트 | 엘리먼트 | 사용법 |
---|---|---|---|
menu
|
ul
|
Identifies the ul element as a menu . |
|
|
aria-labelledby="IDREF" |
ul
|
|
none
|
li
|
|
|
menuitem
|
a
|
|
|
tabindex="-1" |
a
|
removes the a element from the page tab sequence but keeps it focusable with JavaScript. |
Javascript와 CSS 소스 코드
- CSS: menu-button-links.css
- Javascript: menu-button-links.js
HTML Source Code