@a11y-ngx/aria-hidden 中文文档教程

发布于 3年前 浏览 23 项目主页 更新于 3年前

Accessibility - Aria Hidden Directive

为匹配 [aht] 选择器的标签提供 aria-hidden="true" 属性的 Angular 4+ / 指令。

Introduction

aria-hidden="true" 阻止屏幕阅读器读取该元素及其所有子元素。 这可以帮助屏幕阅读器用户不接触纯粹的装饰性内容(例如图标)或折叠的内容等。 请明智地使用它

❗ Important to consider

由于某些用户可能视力不佳,他们可以将 TAB 键与屏幕阅读器结合使用,因此:

  1. 不要直接在任何交互元素上使用它,例如 < code>,

  2. < em>不要在包含任何交互元素的任何标签元素上使用它。

  3. 不要在任何带有 tabindex="0" 或 grater 的标签元素上使用它。

⚠️ 在上面列出的某些示例中使用 aria-hidden="true" 可能会破坏某些用户的可访问性。

Installation

  1. 安装 npm 包:

    npm install @a11y-ngx/aria-hidden --save

  2. 导入 A11yAriaHiddenModule 到你的模块中:

import { NgModule } from '@angular/core';
...
import { A11yAriaHiddenModule } from '@a11y-ngx/aria-hidden';

@NgModule({
    declarations: [...],
    imports: [
        ...
        A11yAriaHiddenModule
    ],
    providers: [...],
    bootstrap: [...]
})
export class AppModule { }

注意: 已测试 Angular 4

For Angular 4 use

安装后,在 /node_modules/@a11y-ngx/aria- 中编辑文件 a11y-ngx-aria-hidden.metadata.json hidden 文件夹并将 version 属性的值

Done

{"__symbolic":"module","version":4,"metadata":{...

{"__symbolic":"module","version":3,"metadata":{...

降级!

Usage

aht 添加到您需要对屏幕阅读器隐藏的任何标记元素。

Code

<i class="my-icon" [aht]="false"></i>
<i class="my-icon" aht></i>

Output

<i class="my-icon"></i> <!-- Not Hidden for Screen Readers -->
<i class="my-icon" aria-hidden="true"></i> <!-- Hidden for Screen Readers -->

Accessibility - Aria Hidden Directive

Angular 4+ / Directive that provides aria-hidden="true" attribute for the tags that match [aht] selector.

Introduction

aria-hidden="true" prevents the screen reader to read that element and all of its children. This can help screen reader users not to reach purely decorative content (such as icons) or collapsed content, among others. Please, use it wisely.

❗ Important to consider

Since some users may have low vision, they can use the TAB key in combination with the screen reader, so:

  1. Do not use it directly on any interactive elements, such as <a>, <button>, <input>, <textarea>, etc.

  2. Do not use it on any tag element that contains any interactive element.

  3. Do not use it on any tag element with tabindex="0" or grater.

⚠️ The use of aria-hidden="true" on some of the examples listed above could break accessibility for some users.

Installation

  1. Install npm package:

    npm install @a11y-ngx/aria-hidden --save

  2. Import A11yAriaHiddenModule into your module:

import { NgModule } from '@angular/core';
...
import { A11yAriaHiddenModule } from '@a11y-ngx/aria-hidden';

@NgModule({
    declarations: [...],
    imports: [
        ...
        A11yAriaHiddenModule
    ],
    providers: [...],
    bootstrap: [...]
})
export class AppModule { }

???? NOTE: Tested up to Angular 4

For Angular 4 use

Once installed, edit the file a11y-ngx-aria-hidden.metadata.json within the /node_modules/@a11y-ngx/aria-hidden folder and downgrade the value from the version property

from

{"__symbolic":"module","version":4,"metadata":{...

to

{"__symbolic":"module","version":3,"metadata":{...

Done!

Usage

Add aht to any tag element you need to hide from the screen reader.

Code

<i class="my-icon" [aht]="false"></i>
<i class="my-icon" aht></i>

Output

<i class="my-icon"></i> <!-- Not Hidden for Screen Readers -->
<i class="my-icon" aria-hidden="true"></i> <!-- Hidden for Screen Readers -->
    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文