diff --git a/files/zh-tw/learn/accessibility/index.html b/files/zh-tw/learn/accessibility/index.html deleted file mode 100644 index 81502b94b6a484..00000000000000 --- a/files/zh-tw/learn/accessibility/index.html +++ /dev/null @@ -1,75 +0,0 @@ ---- -title: 無障礙網頁 -slug: Learn/Accessibility -tags: - - ARIA - - Accessibility - - Articles - - Beginner - - CSS - - CodingScripting - - HTML - - JavaScript - - Landing - - Learn - - Module - - NeedsTranslation - - TopicStub -translation_of: Learn/Accessibility ---- -
{{LearnSidebar}}
- -

如果要當 web 開發者,學會 HTML、CSS、JavaScript 是很重要的。不過除此之外,你還要學得更多:你需要負責任地運用這些技術,才能讓所有讀者都能使用你的網頁。要達成這點,本模塊將展示一般最佳實做(在 HTMLCSSJavaScript 有示範)、跨瀏覽器測試、還有其他啟動的要點。

- -

概觀

- -

When someone describes a site as "accessible," they mean that any user can use all its features and content, regardless of how the user accesses the web — even and especially users with physical or mental impairments.

- - - -

By default, HTML is accessible, if used correctly. Web accessibility involves ensuring that content remains accessible, regardless of who and how the web is accessed.

- -

先決條件

- -

要理解本模塊的概念,最少理解 HTMLCSSJavaScript 是個好主意。如果在學習相關技術時學習會更好。

- -
-

:如果使用的設備無法讓你建立自己的文件,可以試著在 JSBinThimble 這種程式撰寫網站,執行大多數範例。

-
- -

教學

- -
-
何謂無障礙網頁?
-
這篇文章針對何謂無障礙網頁,起了一個好開頭。這模塊包含了要考慮哪些族群以及理由、不同族群會用什麼工具和 Web 互動、還有怎麼把無障礙網頁導入 Web 開發工作流程。
-
HTML:無障礙網頁的好開始
-
只要確保在任何時候,正確的 HTML 元素都用於正確的目的,就能消除各種網頁的障礙。這篇文章詳述 HTML 如何確保網頁無障礙。
-
充分實踐 CSS 與 JavaScript 的無障礙
-
如果 CSS 與 JavaScript 使用得當,將可以為無障礙網頁提供助力……反過來的話,就會嚴重影響無障礙體驗。這篇文章詳述如何在內容複雜的情況下,確保能充分實踐 CSS 與 JavaScript 的無障礙。
-
WAI-ARIA 基礎
-
從之前的文章來看,有時製作要涉及到非語意的 HTML 還有動態 JavaScript 更新技術……等,會令複雜的 UI 控制變得很困難。WAI-ARIA 正是為了解決此一問題而生。它對瀏覽器和輔助技術添加進一步的語意,讓用戶能知道發生了什麼事。我們將介紹如何在基本層面使用此技術,以提昇無障礙。
-
無障礙多媒體
-
會導致無障礙網頁出問題的另一個根源是多媒體:影片、聲音、圖片等內容,需要有合適的文字替代,以便輔助技術和它的用戶能夠理解。我們將在這篇文章中闡明作法。
-
行動無障礙網頁
-
隨著行動設備訪問漸受歡迎、還有像是 iOS 與 Android 這般熱門平台,已經具備完善的輔助工具,考慮到如何在這些平台上實踐無障礙網頁,就變得十分重要。這篇文章將討論行動裝置特有的無障礙網頁相關議題。
-
- -

評估

- -
-
無障礙網頁偵錯
-
要評估本模塊,我們會提出一些簡單的網站,你需要偵測有哪些無障礙的問題並修復之。
-
- -

參見

- - diff --git a/files/zh-tw/learn/accessibility/index.md b/files/zh-tw/learn/accessibility/index.md new file mode 100644 index 00000000000000..7b7568b5ee3f2b --- /dev/null +++ b/files/zh-tw/learn/accessibility/index.md @@ -0,0 +1,65 @@ +--- +title: 無障礙網頁 +slug: Learn/Accessibility +tags: + - ARIA + - Accessibility + - Articles + - Beginner + - CSS + - CodingScripting + - HTML + - JavaScript + - Landing + - Learn + - Module + - NeedsTranslation + - TopicStub +translation_of: Learn/Accessibility +--- +{{LearnSidebar}} + +如果要當 web 開發者,學會 HTML、CSS、JavaScript 是很重要的。不過除此之外,你還要學得更多:你需要**負責任地**運用這些技術,才能讓所有讀者都能使用你的網頁。要達成這點,本模塊將展示一般最佳實做(在 [HTML](/zh-TW/docs/Learn/HTML)、[CSS](/zh-TW/docs/Learn/CSS)、[JavaScript](/en-US/docs/Learn/JavaScript) 有示範)、[跨瀏覽器測試](/zh-TW/docs/Learn/Tools_and_testing/Cross_browser_testing)、還有其他啟動的要點。 + +## 概觀 + +When someone describes a site as "accessible," they mean that any user can use all its features and content, regardless of how the user accesses the web — even and especially users with physical or mental impairments. + +- Sites should be accessible to keyboard, mouse, and touch screen users, and any other way users access the web, including screen readers and voice assistants like Alexa and Google Home. +- Applications should be understandable and usable by people regardless of auditory, visual, physical, or cognitive abilities. +- Sites should also not cause harm: web features like motion can cause migraines or epileptic seizures. + +**By default, HTML is accessible, if used correctly.** Web accessibility involves ensuring that content remains accessible, regardless of who and how the web is accessed. + +## 先決條件 + +要理解本模塊的概念,最少理解 [HTML](/zh-TW/docs/Learn/HTML)、[CSS](/zh-TW/docs/Learn/CSS)、[JavaScript](/zh-TW/docs/Learn/JavaScript) 是個好主意。如果在學習相關技術時學習會更好。 + +> **備註:** 如果使用的設備無法讓你建立自己的文件,可以試著在 [JSBin](http://jsbin.com/) 或 [Thimble](https://thimble.mozilla.org/) 這種程式撰寫網站,執行大多數範例。 + +## 教學 + +- [何謂無障礙網頁?](/zh-TW/docs/Learn/Accessibility/What_is_accessibility) + - : 這篇文章針對何謂無障礙網頁,起了一個好開頭。這模塊包含了要考慮哪些族群以及理由、不同族群會用什麼工具和 Web 互動、還有怎麼把無障礙網頁導入 Web 開發工作流程。 +- [HTML:無障礙網頁的好開始](/zh-TW/docs/Learn/Accessibility/HTML) + - : 只要確保在任何時候,正確的 HTML 元素都用於正確的目的,就能消除各種網頁的障礙。這篇文章詳述 HTML 如何確保網頁無障礙。 +- [充分實踐 CSS 與 JavaScript 的無障礙](/zh-TW/docs/Learn/Accessibility/CSS_and_JavaScript) + - : 如果 CSS 與 JavaScript 使用得當,將可以為無障礙網頁提供助力……反過來的話,就會嚴重影響無障礙體驗。這篇文章詳述如何在內容複雜的情況下,確保能充分實踐 CSS 與 JavaScript 的無障礙。 +- [WAI-ARIA 基礎](/zh-TW/docs/Learn/Accessibility/WAI-ARIA_basics) + - : 從之前的文章來看,有時製作要涉及到非語意的 HTML 還有動態 JavaScript 更新技術……等,會令複雜的 UI 控制變得很困難。WAI-ARIA 正是為了解決此一問題而生。它對瀏覽器和輔助技術添加進一步的語意,讓用戶能知道發生了什麼事。我們將介紹如何在基本層面使用此技術,以提昇無障礙。 +- [無障礙多媒體](/zh-TW/docs/Learn/Accessibility/Multimedia) + - : 會導致無障礙網頁出問題的另一個根源是多媒體:影片、聲音、圖片等內容,需要有合適的文字替代,以便輔助技術和它的用戶能夠理解。我們將在這篇文章中闡明作法。 +- [行動無障礙網頁](/zh-TW/docs/Learn/Accessibility/Mobile) + - : 隨著行動設備訪問漸受歡迎、還有像是 iOS 與 Android 這般熱門平台,已經具備完善的輔助工具,考慮到如何在這些平台上實踐無障礙網頁,就變得十分重要。這篇文章將討論行動裝置特有的無障礙網頁相關議題。 + +## 評估 + +- [無障礙網頁偵錯](/zh-TW/docs/Learn/Accessibility/Accessibility_troubleshooting) + - : 要評估本模塊,我們會提出一些簡單的網站,你需要偵測有哪些無障礙的問題並修復之。 + +## 參見 + +- [Start Building Accessible Web Applications Today](https://egghead.io/courses/start-building-accessible-web-applications-today):Marcy Sutton 所作的一套優秀教學影片。 +- [Deque University resources](https://dequeuniversity.com/resources/):包含程式碼範例、螢幕閱讀器參考、或是其他有用的資源。 +- [WebAIM resources](http://webaim.org/resources/):有教學、便覽、工具……等。 +- [Web Accessibility Evaluation Tools List](https://www.w3.org/WAI/ER/tools/) - includes a list of web accessibility evaluation tools. diff --git a/files/zh-tw/learn/accessibility/mobile/index.html b/files/zh-tw/learn/accessibility/mobile/index.html deleted file mode 100644 index f0e6bc9676237d..00000000000000 --- a/files/zh-tw/learn/accessibility/mobile/index.html +++ /dev/null @@ -1,302 +0,0 @@ ---- -title: Mobile accessibility -slug: Learn/Accessibility/Mobile -translation_of: Learn/Accessibility/Mobile ---- -
-
{{LearnSidebar}}
- -
{{PreviousMenuNext("Learn/Accessibility/Multimedia","Learn/Accessibility/Accessibility_troubleshooting", "Learn/Accessibility")}}
- -

With web access on mobile devices being so popular, and popular platforms such as iOS and Android having fully fledged accessibility tools, it is important to consider the accessibility of your web content on these platforms. This article looks at mobile-specific accessibility considerations.

- - - - - - - - - - - - -
Prerequisites:Basic computer literacy, a basic understanding of HTML, CSS, and JavaScript, and an understanding of the previous articles in the course.
Objective:To understand what problems exist with accessibility on mobile devices, and how to overcome them.
- -

行動裝置上的無障礙

- -

The state of accessibility — and support for web standards in general — is good in modern mobile devices. Long gone are the days when mobile devices ran completely different web technologies to desktop browsers, forcing developers to use browser sniffing and serve them completely separate sites (although quite a few companies still detect usage of mobile devices and serve them a separate mobile domain).

- -

目前,行動裝置通常可以處理“全脂(full fat)”網站,主要平台甚至還內置了屏幕閱讀器,使視障人士能夠成功使用它們。 現代手機行動瀏覽器也傾向於對WAI-ARIA有很好的支持。

- -

To make a website accessible and usable on mobile, you just need to follow general good web design and accessibility best practices.

- -

There are some exceptions that need special consideration for mobile; the main ones are:

- - - -

Summary of screenreader testing on Android and iOS

- -

The most common mobile platforms have fully functional screenreaders. These function in much the same way as desktop screenreaders, except they are largely operated using touch gestures rather than key combinations.

- -

Let's look at the main two: TalkBack on Android and VoiceOver on iOS.

- -

Android TalkBack

- -

The TalkBack screenreader is built into the Android operating system.

- -

To turn it on, select Settings > Accessibility > TalkBack, and then press the slider switch to turn it on. Follow any additional on-screen prompts that you are presented with.

- -

Note: Older versions of TalkBack are turned on in slightly different ways.

- -

When TalkBack is turned on, your Android device's basic controls will be a bit different. For example:

- -
    -
  1. Single-tapping an app will select it, and the device will read out what the app is.
  2. -
  3. Swiping left and right will move between apps, or buttons/controls if you are in a control bar. The device will read out each option.
  4. -
  5. Double-tapping anywhere will open the app/select the option.
  6. -
  7. You can also "explore by touch" — hold your finger down on the screen and drag it around, and your device will read out the different apps/items you move across.
  8. -
- -

If you want to turn TalkBack off:

- -
    -
  1. Navigate to your Settings app using the above gestures.
  2. -
  3. Navigate to Accessibility > TalkBack.
  4. -
  5. Navigate to the slider switch and activate it to turn it off.
  6. -
- -

Note: You can get to your homescreen at any time by swiping up and left in a smooth motion. If you have more than one homescreen, you can move between them by swiping two fingers left and right.

- -

For a more complete list of TalkBack gestures, see Use TalkBack gestures.

- -

Unlocking the phone

- -

When TalkBack is turned on, unlocking the phone is a bit different.

- -

You can do a two-finger swipe up from the bottom of the lock screen. If you've set a passcode or pattern for unlocking your device, you will then be taken to the relevant entry screen to enter it.

- -

You can also explore by touch to find the Unlock button at the bottom middle of the screen, and then double-tap.

- -

Global and local menus

- -

TalkBack allows you to access global and local context menus, wherever you have navigated to on the device. The former provides global options relating to the device as a whole, and the latter provides options relating just to the current app/screen you are in.

- -

To get to these menus:

- -
    -
  1. Access the global menu by quickly swiping down, and then right.
  2. -
  3. Access the local menu by quickly swiping up, and then right.
  4. -
  5. Swipe left and right to cycle between the different options.
  6. -
  7. Once you've selected the option you want, double-click to choose that option.
  8. -
- -

For details on all the options available under the global and local context menus, see Use global and local context menus.

- -

Browsing web pages

- -

You can use the local context menu while in a web browser to find options to navigate web pages using just the headings, form controls, or links, or navigate line by line, etc.

- -

For example, with TalkBack turned on:

- -
    -
  1. Open your web browser.
  2. -
  3. Activate the URL bar.
  4. -
  5. Enter a web page that has a bunch of headings on it, such as the front page of bbc.co.uk. To enter the text of the URL: -
      -
    • Select the URL bar by swiping left/right till you get to it, and then double-tapping.
    • -
    • Hold your finger down on the virtual keyboard until you get the character you want, and then release your finger to type it. Repeat for each character.
    • -
    • Once you've finished, find the Enter key and press it.
    • -
    -
  6. -
  7. Swipe left and right to move between different items on the page.
  8. -
  9. Swipe up and right with a smooth motion to enter the local content menu.
  10. -
  11. Swipe right until you find the "Headings and Landmarks" option.
  12. -
  13. Double-tap to select it. Now you'll be able to swipe left and right to move between headings and ARIA landmarks.
  14. -
  15. To go back to the default mode, enter the local context menu again by swiping up and right, select "Default", and then double-tap to activate.
  16. -
- -

Note: See Get started on Android with TalkBack for more complete documentation.

- -

iOS VoiceOver

- -

A mobile version of VoiceOver is built into the iOS operating system.

- -

To turn it on, go to Your Settings app and select General > Accessibility > VoiceOver. Press the VoiceOver slider to enable it (you'll also see a number of other options related to VoiceOver on this page).

- -

Once VoiceOver is enabled, the iOS's basic control gestures will be a bit different:

- -
    -
  1. A single tap will cause the item you tap on to be selected; your device will speak the item you've tapped on.
  2. -
  3. You can also navigate the items on the screen by swiping left and right to move between them, or by sliding your finger around on the screen to move between different items (when you find the item you want, you can remove your finger to select it).
  4. -
  5. To activate the selected item (e.g., open a selected app), double-tap anywhere on the screen.
  6. -
  7. Swipe with three fingers to scroll through a page.
  8. -
  9. Tap with two fingers to perform a context-relevant action — for example, taking a photo while in the camera app.
  10. -
- -

To turn it off again, navigate back to Settings > General > Accessibility > VoiceOver using the above gestures, and toggle the VoiceOver slider back to off.

- -

Unlock phone

- -

To unlock the phone, you need to press the home button (or swipe) as normal. If you have a passcode set, you can select each number by swiping/sliding (as explained above) and then double-tapping to enter each number when you've found the right one.

- -

Using the Rotor

- -

When VoiceOver is turned on, you have a navigation feature called the Rotor available to you, which allows you to quickly choose from a number of common useful options. To use it:

- -
    -
  1. Twist two fingers around on the screen like you are turning a dial. Each option will be read aloud as you twist further around. You can go back and forth to cycle through the options.
  2. -
  3. Once you've found the option you want: -
      -
    • Release your fingers to select it.
    • -
    • If it is an option you can iterate the value of (such as Volume or Speaking Rate), you can do a swipe up or down to increase or decrease the value of the selected item.
    • -
    -
  4. -
- -

The options available under the Rotor are context-sensitive — they will differ depending on what app or view you are in (see below for an example).

- -

Browsing web pages

- -

Let's have a go at web browsing with VoiceOver:

- -
    -
  1. Open your web browser.
  2. -
  3. Activate the URL bar.
  4. -
  5. Enter a web page that has a bunch of headings on it, such as the front page of bbc.co.uk. To enter the text of the URL: -
      -
    • Select the URL bar by swiping left/right until you get to it, and then double-tapping.
    • -
    • For each character, hold your finger down on the virtual keyboard until you get the character you want, and then release your finger to select it. Double-tap to type it.
    • -
    • Once you've finished, find the Enter key and press it.
    • -
    -
  6. -
  7. Swipe left and right to move between items on the page. You can double-tap an item to select it (e.g., follow a link).
  8. -
  9. By default, the selected Rotor option will be Speaking Rate; you can currently swipe up and down to increase or decrease the speaking rate.
  10. -
  11. Now turn two fingers around the screen like a dial to show the rotor and move between its options. Here are a few examples of the options available: -
      -
    • Speaking Rate: Change the speaking rate.
    • -
    • Containers: Move between different semantic containers on the page.
    • -
    • Headings: Move between headings on the page.
    • -
    • Links: Move between links on the page.
    • -
    • Form Controls: Move between form controls on the page.
    • -
    • Language: Move between different translations, if they are available.
    • -
    -
  12. -
  13. Select Headings. Now you'll be able to swipe up and down to move between headings on the page.
  14. -
- -

Note: For a more complete reference covering the VoiceOver gestures available and other hints on accessibility testing on iOS, see Test Accessibility on Your Device with VoiceOver.

- -

Control mechanisms

- -

In our CSS and JavaScript accessibility article, we looked at the idea of events that are specific to a certain type of control mechanism (see Mouse-specific events). To recap, these cause accessibility issues because other control mechanisms can't activate the associated functionality.

- -

As an example, the click event is good in terms of accessibility — an associated event handler can be invoked by clicking the element the handler is set on, tabbing to it and pressing Enter/Return, or tapping it on a touchscreen device. Try our simple-button-example.html example (see it running live) to see what we mean.

- -

Alternatively, mouse-specific events such as mousedown and mouseup create problems — their event handlers cannot be invoked using non-mouse controls.

- -

If you try to control our simple-box-drag.html (see example live) example with keyboard or touch, you'll see the problem. This occurs because we are using code such as the following:

- -
div.onmousedown = function() {
-  initialBoxX = div.offsetLeft;
-  initialBoxY = div.offsetTop;
-  movePanel();
-}
-
-document.onmouseup = stopMove;
- -

To enable other forms of control, you need to use different, yet equivalent events — for example, touch events work on touchscreen devices:

- -
div.ontouchstart = function(e) {
-  initialBoxX = div.offsetLeft;
-  initialBoxY = div.offsetTop;
-  positionHandler(e);
-  movePanel();
-}
-
-panel.ontouchend = stopMove;
- -

We've provided a simple example that shows how to use the mouse and touch events together — see multi-control-box-drag.html (see the example live also).

- -

Note: You can also see fully functional examples showing how to implement different control mechanisms at Implementing game control mechanisms.

- -

響應式設計

- -

Responsive design is the practice of making your layouts and other features of your apps dynamically change depending on factors such as screen size and resolution, so they are usable and accessible to users of different device types.

- -

In particular, the most common problems that need to be addressed for mobile are:

- - - -

Note: We won't provide a full discussion of responsive design techniques here, as they are covered in other places around MDN (see above links).

- -

Specific mobile considerations

- -

There are other important issues to consider when making sites more accessible on mobile. We have listed a couple here, but we will add more when we think of them.

- -

Not disabling zoom

- -

Using viewport, it is possible to disable zoom. Alwasy ensure resizing is enabled, and set the width to the device's width in the {{htmlelement("head")}}:

- -
<meta name="viewport" content="width=device-width; user-scalable=yes">
- -

You should never set user-scalable=no if at all possible — many people rely on zoom to be able to see the content of your website, so taking this functionality away is a really bad idea. There are certain situations where zooming might break the UI; in such cases, if you feel that you absolutely need to disable zoom, you should provide some other kind of equivalent, such as a control for increasing the text size in a way that doesn't break your UI.

- -

Keeping menus accessible

- -

Because the screen is so much narrower on mobile devices, it is very common to use media queries and other technologies to make the navigation menu shrink down to a tiny icon at the top of the display — which can be pressed to reveal the menu only if it's needed — when the site is viewed on mobile. This is commonly represented by a "three horizontal lines" icon, and the design pattern is consequently known as a "hamburger menu".

- -

When implementing such a menu, you need to make sure that the control to reveal it is accessible by appropriate control mechanisms (normally touch for mobile), as discussed in Control mechanisms above, and that the rest of the page is moved out of the way or hidden in some way while the menu is being accessed, to avoid confusion with navigating it.

- -

Click here for a good hamburger menu example.

- -

User input

- -

On mobile devices, inputting data tends to be more annoying for users than the equivalent experience on desktop computers. It is more convenient to type text into form inputs using a desktop or laptop keyboard than a touchscreen virtual keyboard or a tiny mobile physical keyboard.

- -

For this reason, it is worth trying to minimize the amount of typing needed. As an example, instead of getting users to fill out their job title each time using a regular text input, you could instead offer a {{htmlelement("select")}} menu containing the most common options (which also helps with consistency in data entry), and offer an "Other" option that displays a text field to type any outliers into. You can see a simple example of this idea in action in common-job-types.html (see the common jobs example live).

- -

It is also worth considering the use of HTML5 form input types such as date on mobile platforms as they handle them well — both Android and iOS, for example, display usable widgets that fit well with the device experience. See html5-form-examples.html for some examples (see the HTML5 form examples live) — try loading these and manipulating them on mobile devices. For example:

- - - -

If you want to provide a different solution for desktops, you could always serve different markup to your mobile devices using feature detection. See input types for raw information on detecting different input types, and also check out our feature detection article for much more information.

- -

總結

- -

In this article we have provided you with some details about common mobile accessibility-specific issues and how to overcome them. We also took you through usage of the most common screenreaders to aid you in accessibility testing.

- -

延伸閱讀

- - - -
{{PreviousMenuNext("Learn/Accessibility/Multimedia","Learn/Accessibility/Accessibility_troubleshooting", "Learn/Accessibility")}}
- -
-

In this module

- - -
-
diff --git a/files/zh-tw/learn/accessibility/mobile/index.md b/files/zh-tw/learn/accessibility/mobile/index.md new file mode 100644 index 00000000000000..dc6f57a840a395 --- /dev/null +++ b/files/zh-tw/learn/accessibility/mobile/index.md @@ -0,0 +1,282 @@ +--- +title: Mobile accessibility +slug: Learn/Accessibility/Mobile +translation_of: Learn/Accessibility/Mobile +--- +{{LearnSidebar}}{{PreviousMenuNext("Learn/Accessibility/Multimedia","Learn/Accessibility/Accessibility_troubleshooting", "Learn/Accessibility")}} + +With web access on mobile devices being so popular, and popular platforms such as iOS and Android having fully fledged accessibility tools, it is important to consider the accessibility of your web content on these platforms. This article looks at mobile-specific accessibility considerations. + + + + + + + + + + + + +
Prerequisites: + Basic computer literacy, a basic understanding of HTML, CSS, and + JavaScript, and an understanding of the + previous articles in the course. +
Objective: + To understand what problems exist with accessibility on mobile devices, + and how to overcome them. +
+ +## 行動裝置上的無障礙 + +The state of accessibility — and support for web standards in general — is good in modern mobile devices. Long gone are the days when mobile devices ran completely different web technologies to desktop browsers, forcing developers to use browser sniffing and serve them completely separate sites (although quite a few companies still detect usage of mobile devices and serve them a separate mobile domain). + +目前,行動裝置通常可以處理“全脂(full fat)”網站,主要平台甚至還內置了屏幕閱讀器,使視障人士能夠成功使用它們。 現代手機行動瀏覽器也傾向於對[WAI-ARIA](/en-US/docs/Learn/Accessibility/WAI-ARIA_basics)有很好的支持。 + +To make a website accessible and usable on mobile, you just need to follow general good web design and accessibility best practices. + +There are some exceptions that need special consideration for mobile; the main ones are: + +- Control mechanisms — Make sure interface controls such as buttons are accessible on mobiles (i.e., mainly touchscreen), as well as desktops/laptops (mainly mouse/keyboard). +- User input — Make user input requirements as painless as possible on mobile (e.g., in forms, keep typing to a minimum). +- Responsive design — Make sure layouts work on mobile, conserve image download sizes, and think about provision of images for high-resolution screens. + +## Summary of screenreader testing on Android and iOS + +The most common mobile platforms have fully functional screenreaders. These function in much the same way as desktop screenreaders, except they are largely operated using touch gestures rather than key combinations. + +Let's look at the main two: TalkBack on Android and VoiceOver on iOS. + +### Android TalkBack + +The TalkBack screenreader is built into the Android operating system. + +To turn it on, select _Settings > Accessibility > TalkBack_, and then press the slider switch to turn it on. Follow any additional on-screen prompts that you are presented with. + +**Note:** Older versions of TalkBack are turned on in [slightly different ways](https://play.google.com/store/apps/details?id=com.google.android.marvin.talkback). + +When TalkBack is turned on, your Android device's basic controls will be a bit different. For example: + +1. Single-tapping an app will select it, and the device will read out what the app is. +2. Swiping left and right will move between apps, or buttons/controls if you are in a control bar. The device will read out each option. +3. Double-tapping anywhere will open the app/select the option. +4. You can also "explore by touch" — hold your finger down on the screen and drag it around, and your device will read out the different apps/items you move across. + +If you want to turn TalkBack off: + +1. Navigate to your _Settings_ app using the above gestures. +2. Navigate to _Accessibility > TalkBack_. +3. Navigate to the slider switch and activate it to turn it off. + +**Note:** You can get to your homescreen at any time by swiping up and left in a smooth motion. If you have more than one homescreen, you can move between them by swiping two fingers left and right. + +For a more complete list of TalkBack gestures, see [Use TalkBack gestures](https://support.google.com/accessibility/android/answer/6151827). + +#### Unlocking the phone + +When TalkBack is turned on, unlocking the phone is a bit different. + +You can do a two-finger swipe up from the bottom of the lock screen. If you've set a passcode or pattern for unlocking your device, you will then be taken to the relevant entry screen to enter it. + +You can also explore by touch to find the _Unlock_ button at the bottom middle of the screen, and then double-tap. + +#### Global and local menus + +TalkBack allows you to access global and local context menus, wherever you have navigated to on the device. The former provides global options relating to the device as a whole, and the latter provides options relating just to the current app/screen you are in. + +To get to these menus: + +1. Access the global menu by quickly swiping down, and then right. +2. Access the local menu by quickly swiping up, and then right. +3. Swipe left and right to cycle between the different options. +4. Once you've selected the option you want, double-click to choose that option. + +For details on all the options available under the global and local context menus, see [Use global and local context menus](https://support.google.com/accessibility/android/answer/6007066). + +#### Browsing web pages + +You can use the local context menu while in a web browser to find options to navigate web pages using just the headings, form controls, or links, or navigate line by line, etc. + +For example, with TalkBack turned on: + +1. Open your web browser. +2. Activate the URL bar. +3. Enter a web page that has a bunch of headings on it, such as the front page of bbc.co.uk. To enter the text of the URL: + + - Select the URL bar by swiping left/right till you get to it, and then double-tapping. + - Hold your finger down on the virtual keyboard until you get the character you want, and then release your finger to type it. Repeat for each character. + - Once you've finished, find the Enter key and press it. + +4. Swipe left and right to move between different items on the page. +5. Swipe up and right with a smooth motion to enter the local content menu. +6. Swipe right until you find the "Headings and Landmarks" option. +7. Double-tap to select it. Now you'll be able to swipe left and right to move between headings and ARIA landmarks. +8. To go back to the default mode, enter the local context menu again by swiping up and right, select "Default", and then double-tap to activate. + +**Note:** See [Get started on Android with TalkBack](https://support.google.com/accessibility/android/answer/6283677?hl=en&ref_topic=3529932) for more complete documentation. + +### iOS VoiceOver + +A mobile version of VoiceOver is built into the iOS operating system. + +To turn it on, go to Your _Settings_ app and select _General > Accessibility > VoiceOver_. Press the _VoiceOver_ slider to enable it (you'll also see a number of other options related to VoiceOver on this page). + +Once VoiceOver is enabled, the iOS's basic control gestures will be a bit different: + +1. A single tap will cause the item you tap on to be selected; your device will speak the item you've tapped on. +2. You can also navigate the items on the screen by swiping left and right to move between them, or by sliding your finger around on the screen to move between different items (when you find the item you want, you can remove your finger to select it). +3. To activate the selected item (e.g., open a selected app), double-tap anywhere on the screen. +4. Swipe with three fingers to scroll through a page. +5. Tap with two fingers to perform a context-relevant action — for example, taking a photo while in the camera app. + +To turn it off again, navigate back to _Settings > General > Accessibility > VoiceOver_ using the above gestures, and toggle the _VoiceOver_ slider back to off. + +#### Unlock phone + +To unlock the phone, you need to press the home button (or swipe) as normal. If you have a passcode set, you can select each number by swiping/sliding (as explained above) and then double-tapping to enter each number when you've found the right one. + +#### Using the Rotor + +When VoiceOver is turned on, you have a navigation feature called the Rotor available to you, which allows you to quickly choose from a number of common useful options. To use it: + +1. Twist two fingers around on the screen like you are turning a dial. Each option will be read aloud as you twist further around. You can go back and forth to cycle through the options. +2. Once you've found the option you want: + + - Release your fingers to select it. + - If it is an option you can iterate the value of (such as Volume or Speaking Rate), you can do a swipe up or down to increase or decrease the value of the selected item. + +The options available under the Rotor are context-sensitive — they will differ depending on what app or view you are in (see below for an example). + +#### Browsing web pages + +Let's have a go at web browsing with VoiceOver: + +1. Open your web browser. +2. Activate the URL bar. +3. Enter a web page that has a bunch of headings on it, such as the front page of bbc.co.uk. To enter the text of the URL: + + - Select the URL bar by swiping left/right until you get to it, and then double-tapping. + - For each character, hold your finger down on the virtual keyboard until you get the character you want, and then release your finger to select it. Double-tap to type it. + - Once you've finished, find the Enter key and press it. + +4. Swipe left and right to move between items on the page. You can double-tap an item to select it (e.g., follow a link). +5. By default, the selected Rotor option will be Speaking Rate; you can currently swipe up and down to increase or decrease the speaking rate. +6. Now turn two fingers around the screen like a dial to show the rotor and move between its options. Here are a few examples of the options available: + + - _Speaking Rate_: Change the speaking rate. + - _Containers_: Move between different semantic containers on the page. + - _Headings_: Move between headings on the page. + - _Links_: Move between links on the page. + - _Form Controls_: Move between form controls on the page. + - _Language_: Move between different translations, if they are available. + +7. Select _Headings_. Now you'll be able to swipe up and down to move between headings on the page. + +**Note:** For a more complete reference covering the VoiceOver gestures available and other hints on accessibility testing on iOS, see [Test Accessibility on Your Device with VoiceOver](https://developer.apple.com/library/content/technotes/TestingAccessibilityOfiOSApps/TestAccessibilityonYourDevicewithVoiceOver/TestAccessibilityonYourDevicewithVoiceOver.html#//apple_ref/doc/uid/TP40012619-CH3). + +## Control mechanisms + +In our CSS and JavaScript accessibility article, we looked at the idea of events that are specific to a certain type of control mechanism (see [Mouse-specific events](/en-US/docs/Learn/Accessibility/CSS_and_JavaScript#mouse-specific_events)). To recap, these cause accessibility issues because other control mechanisms can't activate the associated functionality. + +As an example, the [click](/en-US/docs/Web/API/GlobalEventHandlers/onclick) event is good in terms of accessibility — an associated event handler can be invoked by clicking the element the handler is set on, tabbing to it and pressing Enter/Return, or tapping it on a touchscreen device. Try our [simple-button-example.html](https://github.com/mdn/learning-area/blob/master/accessibility/mobile/simple-button-example.html) example ([see it running live](http://mdn.github.io/learning-area/accessibility/mobile/simple-button-example.html)) to see what we mean. + +Alternatively, mouse-specific events such as [mousedown](/en-US/docs/Web/API/GlobalEventHandlers/onmousedown) and [mouseup](/en-US/docs/Web/API/GlobalEventHandlers/onmouseup) create problems — their event handlers cannot be invoked using non-mouse controls. + +If you try to control our [simple-box-drag.html](https://github.com/mdn/learning-area/blob/master/accessibility/mobile/simple-box-drag.html) ([see example live](http://mdn.github.io/learning-area/accessibility/mobile/simple-box-drag.html)) example with keyboard or touch, you'll see the problem. This occurs because we are using code such as the following: + +```js +div.onmousedown = function() { + initialBoxX = div.offsetLeft; + initialBoxY = div.offsetTop; + movePanel(); +} + +document.onmouseup = stopMove; +``` + +To enable other forms of control, you need to use different, yet equivalent events — for example, touch events work on touchscreen devices: + +```js +div.ontouchstart = function(e) { + initialBoxX = div.offsetLeft; + initialBoxY = div.offsetTop; + positionHandler(e); + movePanel(); +} + +panel.ontouchend = stopMove; +``` + +We've provided a simple example that shows how to use the mouse and touch events together — see [multi-control-box-drag.html](https://github.com/mdn/learning-area/blob/master/accessibility/mobile/multi-control-box-drag.html) ([see the example live](http://mdn.github.io/learning-area/accessibility/mobile/multi-control-box-drag.html) also). + +**Note:** You can also see fully functional examples showing how to implement different control mechanisms at [Implementing game control mechanisms](/en-US/docs/Games/Techniques/Control_mechanisms). + +## 響應式設計 + +[Responsive design](/en-US/docs/Web/Apps/Progressive/Responsive) is the practice of making your layouts and other features of your apps dynamically change depending on factors such as screen size and resolution, so they are usable and accessible to users of different device types. + +In particular, the most common problems that need to be addressed for mobile are: + +- Suitability of layouts for mobile devices. A multi-column layout won't work as well on a narrow screen, for example, and the text size may need to be increased so it is legible. Such issues can be solved by creating a responsive layout using technologies such as [media queries](/en-US/docs/Web/CSS/Media_Queries), [viewport](/en-US/docs/Mozilla/Mobile/Viewport_meta_tag), and [flexbox](/en-US/docs/Learn/CSS/CSS_layout/Flexbox). +- Conserving image sizes downloaded. In general, small screen devices won't need images that are as large as their desktop counterparts, and they are more likely to be on slow network connections. Therefore, it is wise to serve smaller images to narrow screen devices as appropriate. You can handle this using [responsive image techniques](/en-US/docs/Learn/HTML/Multimedia_and_embedding/Responsive_images). +- Thinking about high resolutions. Many mobile devices have high-resolution screens, and therefore need higher-resolution images so that the display can continue to look crisp and sharp. Again, you can serve images as appropriate using responsive image techniques. In addition, many image requirements can be fulfilled using the SVG vector images format, which is well-supported across browsers today. SVG has a small file size and will stay sharp regardless of whatever size is being displayed (see [Adding vector graphics to the web](/en-US/docs/Learn/HTML/Multimedia_and_embedding/Adding_vector_graphics_to_the_Web) for more details). + +**Note:** We won't provide a full discussion of responsive design techniques here, as they are covered in other places around MDN (see above links). + +### Specific mobile considerations + +There are other important issues to consider when making sites more accessible on mobile. We have listed a couple here, but we will add more when we think of them. + +#### Not disabling zoom + +Using [viewport](/en-US/docs/Mozilla/Mobile/Viewport_meta_tag), it is possible to disable zoom. Alwasy ensure resizing is enabled, and set the width to the device's width in the {{htmlelement("head")}}: + +```html + +``` + +You should never set `user-scalable=no` if at all possible — many people rely on zoom to be able to see the content of your website, so taking this functionality away is a really bad idea. There are certain situations where zooming might break the UI; in such cases, if you feel that you absolutely need to disable zoom, you should provide some other kind of equivalent, such as a control for increasing the text size in a way that doesn't break your UI. + +#### Keeping menus accessible + +Because the screen is so much narrower on mobile devices, it is very common to use media queries and other technologies to make the navigation menu shrink down to a tiny icon at the top of the display — which can be pressed to reveal the menu only if it's needed — when the site is viewed on mobile. This is commonly represented by a "three horizontal lines" icon, and the design pattern is consequently known as a "hamburger menu". + +When implementing such a menu, you need to make sure that the control to reveal it is accessible by appropriate control mechanisms (normally touch for mobile), as discussed in [Control mechanisms](#control_mechanisms) above, and that the rest of the page is moved out of the way or hidden in some way while the menu is being accessed, to avoid confusion with navigating it. + +Click here for a [good hamburger menu example](http://fritz-weisshart.de/meg_men/). + +## User input + +On mobile devices, inputting data tends to be more annoying for users than the equivalent experience on desktop computers. It is more convenient to type text into form inputs using a desktop or laptop keyboard than a touchscreen virtual keyboard or a tiny mobile physical keyboard. + +For this reason, it is worth trying to minimize the amount of typing needed. As an example, instead of getting users to fill out their job title each time using a regular text input, you could instead offer a {{htmlelement("select")}} menu containing the most common options (which also helps with consistency in data entry), and offer an "Other" option that displays a text field to type any outliers into. You can see a simple example of this idea in action in [common-job-types.html](https://github.com/mdn/learning-area/blob/master/accessibility/mobile/common-job-types.html) (see the [common jobs example live](http://mdn.github.io/learning-area/accessibility/mobile/common-job-types.html)). + +It is also worth considering the use of HTML5 form input types such as date on mobile platforms as they handle them well — both Android and iOS, for example, display usable widgets that fit well with the device experience. See [html5-form-examples.html](https://github.com/mdn/learning-area/blob/master/accessibility/mobile/html5-form-examples.html) for some examples (see the [HTML5 form examples live](http://mdn.github.io/learning-area/accessibility/mobile/html5-form-examples.html)) — try loading these and manipulating them on mobile devices. For example: + +- Types `number`, `tel`, and `email` display suitable virtual keyboards for entering numbers/telephone numbers. +- Types `time` and `date` display suitable pickers for selecting times and dates. + +If you want to provide a different solution for desktops, you could always serve different markup to your mobile devices using feature detection. See [input types](http://diveinto.html5doctor.com/detect.html#input-types) for raw information on detecting different input types, and also check out our [feature detection article](/en-US/docs/Learn/Tools_and_testing/Cross_browser_testing/Feature_detection) for much more information. + +## 總結 + +In this article we have provided you with some details about common mobile accessibility-specific issues and how to overcome them. We also took you through usage of the most common screenreaders to aid you in accessibility testing. + +## 延伸閱讀 + +- [Guidelines For Mobile Web Development](https://www.smashingmagazine.com/guidelines-for-mobile-web-development/) — A list of articles in _Smashing Magazine_ covering different techniques for mobile web design. +- [Make your site work on touch devices](http://www.creativebloq.com/javascript/make-your-site-work-touch-devices-51411644) — Useful article about using touch events to get interactions working on mobile devices. + +{{PreviousMenuNext("Learn/Accessibility/Multimedia","Learn/Accessibility/Accessibility_troubleshooting", "Learn/Accessibility")}} + +## In this module + +- [What is accessibility?](/en-US/docs/Learn/Accessibility/What_is_accessibility) +- [HTML: A good basis for accessibility](/en-US/docs/Learn/Accessibility/HTML) +- [CSS and JavaScript accessibility best practices](/en-US/docs/Learn/Accessibility/CSS_and_JavaScript) +- [WAI-ARIA basics](/en-US/docs/Learn/Accessibility/WAI-ARIA_basics) +- [Accessible multimedia](/en-US/docs/Learn/Accessibility/Multimedia) +- [Mobile accessibility](/en-US/docs/Learn/Accessibility/Mobile) +- [Accessibility troubleshooting](/en-US/docs/Learn/Accessibility/Accessibility_troubleshooting) diff --git a/files/zh-tw/learn/accessibility/wai-aria_basics/index.html b/files/zh-tw/learn/accessibility/wai-aria_basics/index.html deleted file mode 100644 index c2ca453ba612b1..00000000000000 --- a/files/zh-tw/learn/accessibility/wai-aria_basics/index.html +++ /dev/null @@ -1,421 +0,0 @@ ---- -title: WAI-ARIA基礎 -slug: Learn/Accessibility/WAI-ARIA_basics -translation_of: Learn/Accessibility/WAI-ARIA_basics ---- -
{{LearnSidebar}}
- -
{{PreviousMenuNext("Learn/Accessibility/CSS_and_JavaScript","Learn/Accessibility/Multimedia", "Learn/Accessibility")}}
- -

接續之前的文章,有時在涉及非語意HTML與動態 JavaScript更新的內容製作複雜的UI控制措施將是個難題。WAI-ARIA即是一個能藉由添加進一步的語意幫助處理這種問題的技術 ,讓瀏覽器與輔助科技可以辨識及用以讓使用者知道發生甚麼事情。這裡我們將展示如何以基本水準的運用來增進無障礙使用。

- - - - - - - - - - - - -
先決條件:基本電腦技能、基本瞭解HTML, CSS與JavaScript、瞭解本課程先前文章。
目標:能熟悉WAI-ARIA,以及在必要時如何用於提供有用的附加語意強化無障礙。
- -

甚麼是WAI-ARIA?

- -

開始瞭解甚麼是WAI-ARIA,以及它可為我們做些甚麼。

- -

一個全新問題集

- -

當網站應用程式開始更複雜與動態,新的無障礙特性與問題集就開始出現。

- -

例如,HTML5 導入許多語意的元素來定義一般頁面的特性({{htmlelement("nav")}}, {{htmlelement("footer")}}等) 在沒有這些可用之前,開發者僅簡單使用{{htmlelement("div")}}搭配IDs或classes,如<div class="nav">,但這些是有問題的,因為沒有很簡單的方法可程式化地容易找到特定的頁面特性如主要導覽功能。

- -

起初的解決方案是在頁面的頂端添加一個或更多隱藏的連結去連結到導覽功能(或其他任何的功能),例如:

- -
<a href="#hidden" class="hidden">Skip to navigation</a>
- -

但這仍然不是非常精確,並且僅能使用於螢幕報讀器從頁面頂端閱讀下來的時候。

- -

如同另一個例子,應用程式開始具有複雜的控制措施如日期選取器提供選擇日期,內容滑塊提供選取內容值等。HTML5提供特定的輸入型態來呈現這些控制措施:

- -
<input type="date">
-<input type="range">
- -

這些在跨瀏覽器之間沒有全面性支援,而且也非常困難去為他們指定樣式,而使他們與網站設計整合時不是很好用。因此,開發者時常依賴JavaScript資源庫來產生這些一系列內嵌的控制措施 {{htmlelement("div")}}或具有classnames的表格元素,透過CSS指定樣式與使用JavaScript控制。

- -

這個的問題是視覺上可以運作,但螢幕報讀器則一點也無法理解它們是甚麼,以及它們的使用者僅被告知他們可以看到一堆沒有語意的元素來描述它們的含意。

- -

進入WAI-ARIA

- -

WAI-ARIA 是一個由W3C編撰的規格,定義一套額外的HTML屬性能用於元素上提供額外的語意及改善可及性,當元素缺乏這些條件時可適用。本規格定義三個主要的特點:

- - - -

有關WAI-ARIA屬性的重要觀點是他們不會影響網頁的任何內容,除了透過瀏覽器無障礙API揭露資訊之外(螢幕報讀器即從中獲得資訊)。儘管WAI-ARIA屬性對CSS選擇元素很有用,但不會影響網頁結構、DOM等。

- -
-

注意:你可以在WAI-ARIA規格中找到所有ARIA的角色及其用法的很有用清單,請參見 Definition of Roles連結以獲得更進一步的資訊。

- -

本規格也涵括所有屬性與狀態的清單,請參見 Definitions of States and Properties (all aria-* attributes)連結以獲得更進一步的資訊。

-
- -

哪裡支援WAI-ARIA?

- -

這不是一個容易回答的問題。要難找到一個決定性的資源來陳述何者是支援WAI-ARIA的特點以及在何處,因為:

- -
    -
  1. 在WAI-ARIA規格中有很多特點。
  2. -
  3. 要考量作業系統、瀏覽器與螢幕報讀器的許多組合。
  4. -
- -

最後一點是關鍵—首先要使用螢幕報讀器,你的作業系統必須執行具有必要的無障礙API的瀏覽器去揭露螢幕報讀器必須去完成工作的資訊。大部分主流的作業系統有1個或2個瀏覽器可供螢幕報讀器使用。Paciello Group一則最近的文章提供這些數據—請參見 Rough Guide: browsers, operating systems and screen reader support updated

- -

接著,你必須擔心瀏覽器是否支援ARIA特徵並透過其API揭露,同時螢幕報讀器是否辨識該資訊並以可用的方式向使用者呈現的問題。

- -
    -
  1. 瀏覽器支援一般相當好—在撰文當下, caniuse.com表示全球瀏覽器對WAI-ARIA的支援率大約為88%。
  2. -
  3. 螢幕報讀器對ARIA特徵的支援沒有相當於此水平,但大部分主流的螢幕報讀器是有達到此水平。你可查閱Powermapper的 WAI-ARIA Screen reader compatibility這篇文章了解支援的水平。
  4. -
- -

在本文中,我們未試圖涵蓋每一個WAI-ARIA特徵及其確切的支援細節。相反地,我們將涵蓋最關鍵的WAI-ARIA特徵讓你知道;如果我們沒有提到任何支援細節,你可認定該特徵得到很好的支援。我們會明確地提到這個例外情況。

- -
-

注意:某些JavaScript儲存庫支援WAI-ARIA,亦即當他們產生UI特徵如複雜的表單控制措施,他們添加ARIA屬性來增進這些特徵的無障礙。如果你在尋找第三方的JavaScript解決方案來快速的開發UI,你應該謹慎地考量其UI插件的無障礙作為你決定使用的重要因素。jQuery UI(參見About jQuery UI: Deep accessibility support)、 ExtJSDojo/Dijit是良好範例。

-
- -

何時應該使用WAI-ARIA?

- -

我們討論了促使WAI-ARIA早期建立的一些問題,但基本上WAI-ARIA在4個主要領域很有用:

- -
    -
  1. 路標/地標:ARIA的角色屬性值可作為地標,不是複製HTML5元素的語意(如{{htmlelement("nav")}}),就是超越HTML5語意而對不同的功能區域提供路標,如搜尋、頁籤群組、頁籤、清單框等。
  2. -
  3. 動態內容更新:螢幕報讀器往往難以報讀不斷改變的內容;當某個內容區域更新時,我們可以使用aria-live通知螢幕報讀器的使用者,例如透過 XMLHttpRequestDOM APIs
  4. -
  5. 增強鍵盤無障礙:內建的HTML元素具有原生的鍵盤無障礙;當其他元素伴隨使用JavaScript模擬相似的互動時,鍵盤無障礙操作與螢幕報讀器報讀會遭遇問題。如果這是不可避免的,WAI-ARIA提供讓其他元素獲得焦點的一種方法(使用 tabindex)。
  6. -
  7. 非語意控制措施的無障礙:當一系列巢狀的<div>搭配CSS/JavaScript用於創建一個複雜的UI特徵,或者一個透過JavaScript大幅增強/改變的原生控制措施,無障礙會遭遇到困難—如果沒有語意或其他線索,螢幕報讀器使用者將發覺難以理解該特徵的作用。在這種情況下,ARIA可以幫助提供缺失的部分使用如按鈕、清單框或頁籤群組等角色組合,以及aria-required 或aria-posinset等屬性對功能性提供進一步的線索。
  8. -
- -

記住一件事 — 僅在必需時才使用WAI-ARIA! 理想情況下,你應該總是使用原生HTML特徵提供螢幕報讀器所需要的語意來告訴其使用者接下來將發生甚麼事情。有時候這是不可能的情形,不是因為你受限於控制該程式碼,就是因為你創建一些複雜而無法用簡易的HTML元素來開發。在這種情況下,WAI-ARIA可作為有價值的無障礙增強工作。

- -

再說一次,只有需要的時候才使用它!

- -
-

注意: 請確保有各類實際的使用者來測試你的網站 — 非身障者、使用螢幕報讀器者、使用鍵盤導覽者等。他們將比你更能了解它運作的效果。

-
- -

實作WAI-ARIA開發

- -

在下一個章節我們將更仔細地看看這4個領域,並附帶實際的範例。在繼續之前,你應該將備妥螢幕報讀器測試設置,以便在過程中你可以測試這些範例。

- -

更多資訊請參見螢幕報讀器測試章節。

- -

路標/地標

- -

WAI-ARIA添加角色屬性給瀏覽器,讓你可以在必要時添加額外的語意值到你網站上的元素。這第一個主要的領域在為螢幕報讀器提供資訊方面非常有用,讓螢幕報讀器的使用者可以找到常見的頁面元素。我們來看個範例 — 網站-無-角色範例(看實際頁面)有以下的結構:

- -
<header>
-  <h1>...</h1>
-  <nav>
-    <ul>...</ul>
-    <form>
-      <!-- search form  -->
-    </form>
-  </nav>
-</header>
-
-<main>
-  <article>...</article>
-  <aside>...</aside>
-</main>
-
-<footer>...</footer>
- -

若你嘗試在現代瀏覽器中使用螢幕報讀器來測試此範例,你將可以獲得一些有用的資訊。例如,VoiceOver給你以下的資訊:

- - - -

如果你到VoiceOver地標選單(使用VoiceOver主鍵+ U,然後使用游標鍵循環整個選單選項),你會看到大部分元素被列的很好,因此可以很快地訪問他們。

- -

- -

然而,這裡我們可以做得更好,搜尋表單是一個人們想要找到的很重要的地標,但是它並沒有列在地標選項之中或者被視為顯著的地標,除了在實際輸入而被召喚作為搜尋輸入之外(<input type="search">)。另外,有些舊的瀏覽器(大部分是指IE8)無法辨識HTML5元素的語意。

- -

讓我們使用一些ARIA特徵來改善它。首先,我們將添加一些角色屬性到我們的HTML結構。你可以試著複製我們原始的檔案(參見index.htmlstyle.css),或者瀏覽我們的網站-aria-角色範例(看實際頁面),其結構如下:

- -
<header>
-  <h1>...</h1>
-  <nav role="navigation">
-    <ul>...</ul>
-    <form role="search">
-      <!-- search form  -->
-    </form>
-  </nav>
-</header>
-
-<main>
-  <article role="article">...</article>
-  <aside role="complementary">...</aside>
-</main>
-
-<footer>...</footer>
- -

在本範例中我們也將給你一個額外的特徵—{{htmlelement("input")}} 元素賦予 aria-label屬性,藉由給予描述性的標籤讓螢幕報讀器可以報讀出來,即使我們沒有包含{{htmlelement("label")}}元素。像這種情況就非常有用—搜尋表單是一個非常常見、容易辨識的特徵,而添加視覺的標籤可能破壞頁面的設計。

- -
<input type="search" name="q" placeholder="Search query" aria-label="Search through site content">
- -

現在如果我們使用VoiceOver來看這個範例,我們可以獲得一些改善:

- - - -

除此之外,該網站對舊瀏覽器如IE8的使用者更可能無障礙;為了這個目的,包含ARIA角色是值得的。如果為了某些原因,你的網站僅使用 <div>建置,那麼肯定你應該包含ARIA角色來提供這些非常需要的語意!

- -

當ARIA超越從HTML5所能獲得的語意時,搜尋表單的改進語意已經顯示實現的可能性。你將會在下面看到更多關於這些語意與ARIA屬性的能力,尤其在Accessibility of non-semantic controls章節。現在,我們先來看看ARIA如何幫助動態內容更新。

- -

動態內容更新

- -

從文本內容到附著於圖片的替代文字,其內容載入至DOM中可方便螢幕報讀器使用。因此,大部分使用文字內容的傳統靜態網站能輕易讓視覺障礙者無障礙使用。

- -

問題在於現代網頁應用程式通常不只是靜態的文字—他們傾向有很多動態更新的內容,例如透過像XMLHttpRequest, Fetch, 或DOM APIs等機制更新的內容而不必重新載入全部的頁面。這些有時稱為即時區塊。

- -

我們來看一個簡單的範例—請看 aria-no-live.html (看實際頁面)。本範例中我們有簡單的隨機引言框:

- -
<section>
-  <h1>Random quote</h1>
-  <blockquote>
-    <p></p>
-  </blockquote>
-</section>
- -

我們的JavaScript透過含有一系列的隨機引言與其作者的 XMLHttpRequest 載入一個JSON檔案。一旦這些完成,我們就開始 setInterval() 迴圈每10秒載入新的隨機引言到引言框之中。

- -
var intervalID = window.setInterval(showQuote, 10000);
- -

這個運作正常,但對無障礙不是很好—此內容更新無法被螢幕報讀器所偵測,所以他們的使用者不知道發生甚麼事情。這是一個相當平凡的例子,但只要想像一下如果你正在創建一個有著大量不斷更新內容的複雜UI,如聊天室、一個策略型的遊戲UI、或者一個即時更新的購物車顯示窗—則將不可能以任何有效的方式使用該應用程式而沒有某種提醒使用者該更新內容的方法。

- -

很幸運地WAI-ARIA提供一項有用的機制來提供這些警告—即aria-live 屬性。將此屬性用在元素上可讓螢幕報讀器讀出更新的內容。報讀內容的緊急性決定於以下屬性值:

- - - -

一般而言, assertive 設置足以讓你的更新內容在他們出現時依序地讀出,因此如果同時有多個事件改變,你將獲得所有的更新。只有對非常高優先順序的更新使用 rude 才能覆蓋其他所有的更新。

- -

我們希望你複製 aria-no-live.htmlquotes.json,並更新 <section> 標籤如下所示:

- -
<section aria-live="assertive">
- -

這將使螢幕報讀器在內容更新時讀出更新的內容。

- -
-

注意: 如果你嘗試從 XMLHttpRequest 執行 file:// URL大部分的瀏覽器會拋出安全異常,例如你直接上傳該檔案到瀏覽器(透過雙擊滑鼠鍵等)。為了這項可以執行,你需要將檔案上傳到一個網站伺服器如 GitHub,或本機網站伺服器如 Python's SimpleHTTPServer

-
- -

這裡有一項額外的考量—只有文字更新才讀出。如果我們也總是讀出標題,那將很好,以讓使用者記住讀出的內容。為做到這樣,我們可以添加 aria-atomic 屬性到這個部分,再次更新您的 <section> 標籤如下所示:

- -
<section aria-live="assertive" aria-atomic="true">
- -

aria-atomic="true"屬性告訴螢幕報讀器以一個原子單位方式讀出完整的元素內容,而不僅只讀出更新的部分。

- -
-

注意:你可以查看完成的範例 aria-live.html (看實際頁面)。

-
- -
-

注意: aria-relevant 屬性在即時區塊更新時對於控制讀出甚麼內容也相當有用,例如你可以僅獲得讀出新增或移除的內容。

-
- -

增強鍵盤無障礙

- -

如同在本模組其他章節所討論, HTML關於無障礙的關鍵優勢之一是內建鍵盤無障礙特徵如按鈕、表單控制措施及連結。一般而言,你可以使用tab鍵在控制措施之間移動,輸入(Enter)/返回(Return)鍵用來選擇或觸發控制措施,以及偶爾需要其他的控制措施(例如上下游標在 <select> 框中的選項間移動)。

- -

然而,有時你最終必須撰寫不是使用非語意的元素如按鈕(或其他控制的型態),或者使用可獲焦點的控制措施用作非正確目的程式碼。你可能嘗試修正一些繼承來的不好的程式碼,或者你可能創建需要某些種類的複雜插件。

- -

讓非焦點的程式碼可獲得焦點,WAI-ARIA使用一些新值擴展 tabindex 屬性:

- - - -

我們更詳細討論這一點並在我們的HTML無障礙文章中展示典型的實作—請參見 Building keyboard accessibility back in.

- -

非語意控制措施的無障礙

- -

本部份接續前一章節—當一系列巢狀的 <div>搭配CSS/JavaScript用於創建一個複雜的UI特徵,或者一個透過JavaScript大幅增強/改變的原生控制措施,不僅鍵盤無障礙會遭遇到困難,而且如果沒有語意或其他線索,螢幕報讀器使用者也會發覺難以理解該特徵的作用。在這種情況下,ARIA可以幫助提供缺失的語意。

- -

表單驗證與錯誤警告

- -

首先,讓我們再看一次在我們的CSS與JavaScript無障礙文章中第一次看的表單範例(請閱讀 Keeping it unobtrusive完整回顧)。在本章節文末我們展示當你試著送出表單而驗證錯誤時,出現我們包含一些在錯誤訊息框的ARIA屬性。

- -
<div class="errors" role="alert" aria-relevant="all">
-  <ul>
-  </ul>
-</div>
- - - -

我們可進一步使用我們的ARIA,並提供更多的驗證協助。如何指出區塊是否需要在第一個位置,以及年齡的範圍應該多少?

- -
    -
  1. 在此,複製我們的 form-validation.htmlvalidation.js 檔案,並將他們儲存在本機目錄。
  2. -
  3. 在文字編輯器開啟他們並且看一下該程式碼如何運作。
  4. -
  5. 首先,在開始的 <form> 標籤之上增加一個段落,如下所示,並且用星號標記兩個表單的 <label>。這是一般我們對有視力的使用者標記必要區塊的方法。 -
    <p>Fields marked with an asterisk (*) are required.</p>
    -
  6. -
  7. 這讓視覺有意義,但這對螢幕報讀器使用者不能輕易理解。很幸運地,WAI-ARIA提供 aria-required 屬性以提示螢幕報讀器應告訴使用者需要填寫的表單輸入欄位。更新<input> 元素如下: -
    <input type="text" name="name" id="name" aria-required="true">
    -
    -<input type="number" name="age" id="age" aria-required="true">
    -
  8. -
  9. 如果你現在儲存本範例並使用螢幕報讀器測試,你應該聽到這個內容 "Enter your name star, required, edit text"。
  10. -
  11. 如果我們給予螢幕報讀器使用者與視覺的使用者有關年齡的值應該是甚麼的概念,這樣也將會很有用。這個或許常以提示或在表單輸入區內預設文本的方式呈現。WAI-ARIA用包含 aria-valueminaria-valuemax 屬性來指定最小與最大值,但這些目前未受到很好的支持;比較受支持的特徵是 HTML5 placeholder 屬性,它在沒有輸入值的時間將含有的訊息顯示在輸入框,並能由許多螢幕報讀器讀出。更新你的數值輸入如下所示: -
    <input type="number" name="age" id="age" placeholder="Enter 1 to 150" aria-required="true">
    -
  12. -
- -
-

注意:你可以查看完成的範例 form-validation-updated.html

-
- -

除了傳統的 {{htmlelement("label")}} 元素之外,WAI-ARIA也能賦予一些進階的表單標籤技術。我們已經談論過使用 aria-label 屬性在我們不希望標籤讓有視覺的使用者看見的地方來提供標籤(參見上述 路標/地標 章節。如果你想要指定一個非<label> 元素當作標籤或具有相同標籤多重的表單輸入標籤,這裡有使用其他屬性如 aria-labelledby 的其他標籤技術,如果你想要其他的訊息與表單輸入關聯並且報讀出來,使用 aria-describedby。更多細節請參見 WebAIM's Advanced Form Labeling article

- -

還有許多其他有用的屬性與狀態,用來指出表單元素的狀態。例如, aria-disabled="true" 可用於指出表單區域是處於停用的狀態。許多瀏覽器只會跳過停用的表單區塊,並且甚至不會被螢幕報讀器讀出,但在某些情況下,他們可被感知,所以最好包含此屬性讓螢幕報讀器知道停用的輸入事實上即是停用的狀態。

- -

如果輸入的停用狀態可能產生改變,也最好在發生時指出,以及其結果為何。例如,在我們的 form-validation-checkbox-disabled.html 展示中,當核取框被核取時,可以讓另一個表單輸入允許輸入更進一步的資訊。我們已經設置一個隱藏的即時區塊:

- -
<p class="hidden-alert" aria-live="assertive"></p>
- -

這是使用絕對位置從視窗中隱藏。當核取/未核取時,我們更新在隱藏的即時區塊中的文字,告訴螢幕報讀器使用者選取這個核取框時結果會是甚麼,以及更新 aria-disabled 的狀態,連同一些視覺的指示:

- -
function toggleMusician(bool) {
-  var instruItem = formItems[formItems.length-1];
-  if(bool) {
-    instruItem.input.disabled = false;
-    instruItem.label.style.color = '#000';
-    instruItem.input.setAttribute('aria-disabled', 'false');
-    hiddenAlert.textContent = 'Instruments played field now enabled; use it to tell us what you play.';
-  } else {
-    instruItem.input.disabled = true;
-    instruItem.label.style.color = '#999';
-    instruItem.input.setAttribute('aria-disabled', 'true');
-    instruItem.input.removeAttribute('aria-label');
-    hiddenAlert.textContent = 'Instruments played field now disabled.';
-  }
-}
- -

描述非語意按鈕為按鈕

- -

本課程我們已經談過幾次按鈕、連結或表單元素(參見HTML無障礙文章的 UI controls ,以及前述增強鍵盤無障礙的原生無障礙(以及在使用其他元素偽造背後的無障礙議題)。基本上,使用 tabindex 與一些 JavaScript,在很多情況下,你可以在沒有太多困難下增加鍵盤無障礙支援功能。

- -

但螢幕報讀器的情況如何呢?他們仍然無法將這些元素視為按鈕。如果我們用螢幕報讀器測試我們的 fake-div-buttons.html 範例,我們偽造的按鈕將會用句子如 "Click me!, group"讀出,很顯然地令人困惑。

- -

我們可以使用WAI-ARIA角色來修正它。請複製 fake-div-buttons.html在本機,並且對每個按鈕<div>增加 role="button" ,範例如下:

- -
<div data-message="This is from the first button" tabindex="0" role="button">Click me!</div>
- -

現在當你使用螢幕報讀器測試它時,按鈕將會用句子如"Click me!, button" 讀出—這樣好多了。

- -
-

注意:記住最好盡可能使用正確的語意元素,如果你希望創建一個按鈕,並且可使用 {{htmlelement("button")}} 元素,就應該使用 {{htmlelement("button")}} 元素!

-
- -

透過複雜的插件引導使用者

- -

除了標準HTML可用外,還有一堆其他角色可以辨識非語意的元素結構作為一般的使用者介面特徵,例如 combobox, slider, tabpanel, tree。你可在 Deque university code library中找到很多有用的範例,可給你這些控制措施如何做到無障礙的想法。

- -

我們來看看我們自己的範例,我們回到我們簡單的絕對位置頁籤的介面(參見在我們的CSS與JavaScript無障礙文章中的 Hiding things ),你可以找到 頁籤資訊框範例(看原始碼).

- -

本範例以鍵盤無障礙而言運作正常—你可以開心地在不同的頁籤間跳位,並且選擇他們顯示該頁籤的內容,也相當地容易操作—你可以滾動內容並使用標題來導覽,即使你看不到螢幕上正發生的事情。然而內容是甚麼並非很明顯—螢幕報讀器目前以連結的清單報讀內容,以及有三個標題的內容。這樣無法給你了解內容之間的關係。最好給予使用者更多關於內容結構的線索。

- -

為改善這些,我們創建新的範例版本為 aria-tabbed-info-box.html (看實際頁面),我們已經更新頁籤介面的結構如下:

- -
<ul role="tablist">
-  <li class="active" role="tab" aria-selected="true" aria-setsize="3" aria-posinset="1" tabindex="0">Tab 1</li>
-  <li role="tab" aria-selected="false" aria-setsize="3" aria-posinset="2" tabindex="0">Tab 2</li>
-  <li role="tab" aria-selected="false" aria-setsize="3" aria-posinset="3" tabindex="0">Tab 3</li>
-</ul>
-<div class="panels">
-  <article class="active-panel" role="tabpanel" aria-hidden="false">
-    ...
-  </article>
-  <article role="tabpanel" aria-hidden="true">
-    ...
-  </article>
-  <article role="tabpanel" aria-hidden="true">
-    ...
-  </article>
-</div>
- -
-

注意: 這裡最引人注目的是我們移除在原來範例中的連結,並且只使用清單項目作為頁籤—這樣做是因為對螢幕報讀器使用者比較少困擾(連結並非真正地帶妳到哪個地方;他們只是改變視窗),並且可讓組件大小/位置在組件特徵中有很好的運作—當這些是放在連結上的時候,瀏覽器將維持報讀"1 of 1",而非"1 of 3"、"2 of 3"等。

-
- -

新的特徵如下:

- - - -

在我們的測試中,這些新的結構確實提供整體的改善。頁籤現在被認定為頁籤(如螢幕報讀器讀出"索引標籤"),被選取的頁籤以”已選取”指出並讀出頁籤的名稱,螢幕報讀器也告訴你目前所在的頁籤數目。此外,因為設置 aria-hidden (只有非隱藏的頁籤才設定aria-hidden="false" ),非隱藏的頁籤是唯一你可以向下導覽的內容,意即所選取的內容很容易找到。

- -
-

注意:如果有任何你很明確地不希望螢幕報讀器讀出的內容,你可賦予它們 aria-hidden="true" 屬性。

-
- -

總結

- -

本文並未涵蓋所有WAI-ARIA的內容,但應該給予你足夠的資訊來了解如何使用它,以及了解一些你會遇到而需要它的最常見型態。

- -

相關參考資訊

- - - -

{{PreviousMenuNext("Learn/Accessibility/CSS_and_JavaScript","Learn/Accessibility/Multimedia", "Learn/Accessibility")}}

- -

- -

本模組章節

- - - -

diff --git a/files/zh-tw/learn/accessibility/wai-aria_basics/index.md b/files/zh-tw/learn/accessibility/wai-aria_basics/index.md new file mode 100644 index 00000000000000..80503c78806c8f --- /dev/null +++ b/files/zh-tw/learn/accessibility/wai-aria_basics/index.md @@ -0,0 +1,407 @@ +--- +title: WAI-ARIA基礎 +slug: Learn/Accessibility/WAI-ARIA_basics +translation_of: Learn/Accessibility/WAI-ARIA_basics +--- +{{LearnSidebar}}{{PreviousMenuNext("Learn/Accessibility/CSS_and_JavaScript","Learn/Accessibility/Multimedia", "Learn/Accessibility")}} + +接續之前的文章,有時在涉及非語意 HTML 與動態 JavaScript 更新的內容製作複雜的 UI 控制措施將是個難題。WAI-ARIA 即是一個能藉由添加進一步的語意幫助處理這種問題的技術 ,讓瀏覽器與輔助科技可以辨識及用以讓使用者知道發生甚麼事情。這裡我們將展示如何以基本水準的運用來增進無障礙使用。 + + + + + + + + + + + + +
先決條件:基本電腦技能、基本瞭解HTML, CSS與JavaScript、瞭解本課程先前文章。
目標: + 能熟悉WAI-ARIA,以及在必要時如何用於提供有用的附加語意強化無障礙。 +
+ +## 甚麼是 WAI-ARIA? + +開始瞭解甚麼是 WAI-ARIA,以及它可為我們做些甚麼。 + +### **一個全新問題集** + +當網站應用程式開始更複雜與動態,新的無障礙特性與問題集就開始出現。 + +例如,HTML5 導入許多語意的元素來定義一般頁面的特性({{htmlelement("nav")}}, {{htmlelement("footer")}}等) 在沒有這些可用之前,開發者僅簡單使用{{htmlelement("div")}}搭配 IDs 或 classes,如\