@ohos-ports/ember-a11y-refocus 5.2.1-beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE.md +9 -0
- package/README.md +226 -0
- package/addon-main.cjs +5 -0
- package/declarations/components/navigation-narrator.d.ts +61 -0
- package/declarations/components/navigation-narrator.d.ts.map +1 -0
- package/declarations/index.d.ts +3 -0
- package/declarations/index.d.ts.map +1 -0
- package/declarations/template-registry.d.ts +5 -0
- package/declarations/template-registry.d.ts.map +1 -0
- package/declarations/utils/routing.d.ts +13 -0
- package/declarations/utils/routing.d.ts.map +1 -0
- package/declarations/utils/validators.d.ts +9 -0
- package/declarations/utils/validators.d.ts.map +1 -0
- package/dist/_app_/components/navigation-narrator.js +1 -0
- package/dist/components/navigation-narrator.js +114 -0
- package/dist/components/navigation-narrator.js.map +1 -0
- package/dist/index.js +3 -0
- package/dist/index.js.map +1 -0
- package/dist/styles/navigation-narrator.css +27 -0
- package/dist/template-registry.js +2 -0
- package/dist/template-registry.js.map +1 -0
- package/dist/utils/routing.js +37 -0
- package/dist/utils/routing.js.map +1 -0
- package/dist/utils/validators.js +8 -0
- package/dist/utils/validators.js.map +1 -0
- package/package.json +128 -0
- package/src/components/navigation-narrator.gts +175 -0
- package/src/index.ts +2 -0
- package/src/styles/navigation-narrator.css +27 -0
- package/src/template-registry.ts +9 -0
- package/src/utils/routing.ts +68 -0
- package/src/utils/validators.ts +13 -0
package/LICENSE.md
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2021
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
6
|
+
|
|
7
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
8
|
+
|
|
9
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,226 @@
|
|
|
1
|
+
# ember-a11y-refocus
|
|
2
|
+
|
|
3
|
+
[](https://www.npmjs.com/package/ember-a11y-refocus)
|
|
4
|
+
[](http://emberobserver.com/addons/ember-a11y-refocus)
|
|
5
|
+
[](https://github.com/ember-a11y/ember-a11y-refocus/actions/workflows/publish.yml)
|
|
6
|
+
|
|
7
|
+
## What This Addon Does
|
|
8
|
+
|
|
9
|
+
In order to provide a mechanism for Ember applications to meet certain WCAG Success Criteria, this addon does three things:
|
|
10
|
+
|
|
11
|
+
1. Transition message: it adds a message to the page to let the screen reader user know that the route has changed.
|
|
12
|
+
2. Transition focus management: it moves the focus to that message for the screen reader user, effectively resetting focus in Ember apps (similar to how a native web page/site works).
|
|
13
|
+
3. Skip link: It provides a bypass mechanism so the user can skip to the page's primary content (see <https://www.w3.org/TR/WCAG20-TECHS/G1.html>).
|
|
14
|
+
|
|
15
|
+
There are quite a few options, and many things are customizable.
|
|
16
|
+
Make sure to read the whole README file to fully understand how to use this addon!
|
|
17
|
+
|
|
18
|
+
## Why This Addon is Needed
|
|
19
|
+
|
|
20
|
+
Single-Page Applications(SPAs) use `pushState` to allow portions of the page to be updated or replaced without a whole new page being rendered. While this was a positive gain for performance on the web, it has made an entire type of web app not accessible (usable) for folks who depend on assistive technology(such as screen-readers) to use the web. With the prolific rise of JavaScript frameworks as the tool of choice for building modern web applications, screen-reader users have become increasingly left out of many experiences of the modern web that have become necessary for everyday life, such as online banking, paying bills, and ordering products and services.
|
|
21
|
+
|
|
22
|
+
Since `pushState` does nothing to inform the browser--and, by extent, the screen reader--that new content is present, the screen-reader user has no way of knowing that new content exists, or that navigation to a new page was successful. Additionally, focus remains where it was, instead of being reset in a predictable fashion.
|
|
23
|
+
|
|
24
|
+
## Installation
|
|
25
|
+
|
|
26
|
+
```bash
|
|
27
|
+
pnpm add ember-a11y-refocus
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
Or with npm:
|
|
31
|
+
|
|
32
|
+
```bash
|
|
33
|
+
npm install ember-a11y-refocus
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
## Usage
|
|
37
|
+
|
|
38
|
+
- Insert `<NavigationNarrator/>` into your application.hbs file, inside of the `<header>` element.
|
|
39
|
+
- Next, add `id="main"` to the primary content element in your application (should be the `<main>` element).
|
|
40
|
+
|
|
41
|
+
Example:
|
|
42
|
+
|
|
43
|
+
```html
|
|
44
|
+
<header>
|
|
45
|
+
<NavigationNarrator/>
|
|
46
|
+
<!-- other header content-->
|
|
47
|
+
</header>
|
|
48
|
+
<main id="main">
|
|
49
|
+
<!--main content-->
|
|
50
|
+
</main>
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
Gjs/Gts:
|
|
54
|
+
|
|
55
|
+
- Import the `NavigationNarrator`
|
|
56
|
+
- Insert `<NavigationNarrator/>` component into your template file, inside of the `<header>` element.
|
|
57
|
+
- Next, add `id="main"` to the primary content element in your application (should be the `<main>` element).
|
|
58
|
+
|
|
59
|
+
Example:
|
|
60
|
+
|
|
61
|
+
```gjs
|
|
62
|
+
import { NavigationNarrator } from 'ember-a11y-refocus';
|
|
63
|
+
|
|
64
|
+
<template>
|
|
65
|
+
<header>
|
|
66
|
+
<NavigationNarrator/>
|
|
67
|
+
<!-- other header content-->
|
|
68
|
+
</header>
|
|
69
|
+
<main id="main">
|
|
70
|
+
<!--main content-->
|
|
71
|
+
</main>
|
|
72
|
+
</template>
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
Template Registry is available for loose mode users:
|
|
76
|
+
|
|
77
|
+
```ts
|
|
78
|
+
import type EmberA11yRefocusRegistry from 'ember-a11y-refocus/template-registry';
|
|
79
|
+
|
|
80
|
+
declare module '@glint/environment-ember-loose/registry' {
|
|
81
|
+
export default interface Registry
|
|
82
|
+
extends EmberA11yRefocusRegistry {}
|
|
83
|
+
}
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
Minimal CSS is provided to style the skip link and navigation message.
|
|
87
|
+
|
|
88
|
+
```diff
|
|
89
|
+
/* app/app.ts */
|
|
90
|
+
+ import 'ember-a11y-refocus/styles/navigation-narrator.css';
|
|
91
|
+
+
|
|
92
|
+
import Application from '@ember/application';
|
|
93
|
+
import loadInitializers from 'ember-load-initializers';
|
|
94
|
+
import Resolver from 'ember-resolver';
|
|
95
|
+
|
|
96
|
+
import config from './config/environment';
|
|
97
|
+
|
|
98
|
+
export default class App extends Application {
|
|
99
|
+
modulePrefix = config.modulePrefix;
|
|
100
|
+
podModulePrefix = config.podModulePrefix;
|
|
101
|
+
Resolver = Resolver;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
loadInitializers(App, config.modulePrefix);
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
<details>
|
|
108
|
+
|
|
109
|
+
<summary>Use Sass?</summary>
|
|
110
|
+
|
|
111
|
+
If your build tool resolves node module paths (e.g. Vite), the full specifier works directly:
|
|
112
|
+
|
|
113
|
+
```scss
|
|
114
|
+
/* app/styles/app.scss */
|
|
115
|
+
@use "ember-a11y-refocus/styles/navigation-narrator.css";
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
For classic Ember apps using `ember-cli-sass`, add the path to `includePaths`:
|
|
119
|
+
|
|
120
|
+
```js
|
|
121
|
+
// ember-cli-build.js
|
|
122
|
+
const app = new EmberApp(defaults, {
|
|
123
|
+
sassOptions: {
|
|
124
|
+
includePaths: ['node_modules/ember-a11y-refocus/dist/styles'],
|
|
125
|
+
},
|
|
126
|
+
});
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
Then import with the short path:
|
|
130
|
+
|
|
131
|
+
```scss
|
|
132
|
+
/* app/styles/app.scss */
|
|
133
|
+
@use "navigation-narrator.css";
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
</details>
|
|
137
|
+
|
|
138
|
+
### Feature: Customizing the definition of a route change
|
|
139
|
+
|
|
140
|
+
This addon provides support for custom definitions of which route changes should trigger refocusing behavior.
|
|
141
|
+
To use this functionality, pass `routeChangeValidator` when you invoke the component, and add your custom action in the appropriate controller (likely the application controller).
|
|
142
|
+
|
|
143
|
+
So when you add the component to your application template:
|
|
144
|
+
|
|
145
|
+
```hbs
|
|
146
|
+
<NavigationNarrator @routeChangeValidator={{this.myCustomValidator}} />
|
|
147
|
+
```
|
|
148
|
+
|
|
149
|
+
This is what the controller could look like:
|
|
150
|
+
|
|
151
|
+
```js
|
|
152
|
+
import Controller from '@ember/controller';
|
|
153
|
+
|
|
154
|
+
export default class ApplicationController extends Controller {
|
|
155
|
+
myCustomValidator(transition) {
|
|
156
|
+
// Custom logic goes here...
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
```
|
|
160
|
+
|
|
161
|
+
The validator function:
|
|
162
|
+
|
|
163
|
+
- Receives a [Transition](https://api.emberjs.com/ember/release/classes/Transition) object containing information about the source and destination routes
|
|
164
|
+
- Should return `true` if refocusing should occur, otherwise `false`
|
|
165
|
+
|
|
166
|
+
**Note:** If you wish to extend the default behavior (rather than completely replacing it), you can import the default validator like so:
|
|
167
|
+
|
|
168
|
+
```js
|
|
169
|
+
import Controller from '@ember/controller';
|
|
170
|
+
import { defaultValidator } from 'ember-a11y-refocus';
|
|
171
|
+
|
|
172
|
+
export default class ApplicationController extends Controller {
|
|
173
|
+
myCustomValidator(transition) {
|
|
174
|
+
if (transition.from.name === 'special') { // this if statement is where you'd put your custom route validation
|
|
175
|
+
return false;
|
|
176
|
+
} else { // include this to get the defaultValidator as a fallback
|
|
177
|
+
return defaultValidator(transition);
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
```
|
|
182
|
+
|
|
183
|
+
## Additional Options
|
|
184
|
+
|
|
185
|
+
All of these are optional and have default values.
|
|
186
|
+
|
|
187
|
+
- `skipLink` - pass `{{false}}` if you do not want to implement a bypass block/skip link.
|
|
188
|
+
- `skipTo` - pass a specific element ID that should receive focus on skip. Defaults to `#main`.
|
|
189
|
+
- `skipText` - customize the text passed in the skip link. Defaults to `Skip to main content`.
|
|
190
|
+
- `navigationText` - customize the text passed as the navigation message. Defaults to `The page navigation is complete. You may now navigate the page content as you wish`.
|
|
191
|
+
- `excludeAllQueryParams` - pass `{{true}}` if you want to exclude all query params from the route change check/focus management. Really shouldn't do this, but you might be upgrading an older app and need this for a little bit, or you are using QPs in a specific way and would like to otherwise benefit from the accessibility options in this addon. If you only need to exclude _some_ QPs, use the [custom validator function](https://github.com/ember-a11y/ember-a11y-refocus?tab=readme-ov-file#customizing-the-definition-of-a-route-change) instead.
|
|
192
|
+
|
|
193
|
+
## FastBoot
|
|
194
|
+
|
|
195
|
+
With FastBoot, you'll want to guard the `<NavigationNarrator />` from rendering. Like so:
|
|
196
|
+
|
|
197
|
+
```hbs
|
|
198
|
+
{{#unless this.fastboot.isFastBoot}}
|
|
199
|
+
<NavigationNarrator />
|
|
200
|
+
{{/unless}}
|
|
201
|
+
```
|
|
202
|
+
|
|
203
|
+
Where `this.fastboot` is the fastboot service injected in the application controller.
|
|
204
|
+
|
|
205
|
+
## FAQs
|
|
206
|
+
|
|
207
|
+
### What about async data loading?
|
|
208
|
+
|
|
209
|
+
Async data can be loaded as it normally would be. Since this addon does not use `aria-live`, it won't interfere with or compete with other loading states. This will only give the user with a screen reader a message that the route (URL) has changed, and place the focus where they expect it to be (reset to the top left of the page).
|
|
210
|
+
|
|
211
|
+
### What if I want to put focus somewhere specific in the app flow?
|
|
212
|
+
|
|
213
|
+
Since this will run before other content, focus can be programmatically moved by the developer to go somewhere else. The message should still read out, and is findable by users with screen readers.
|
|
214
|
+
|
|
215
|
+
## Compatibility
|
|
216
|
+
|
|
217
|
+
- Ember.js v4.12 or above
|
|
218
|
+
- Node.js v22 or above
|
|
219
|
+
|
|
220
|
+
## Contributing
|
|
221
|
+
|
|
222
|
+
Contributions are welcome.
|
|
223
|
+
|
|
224
|
+
## License
|
|
225
|
+
|
|
226
|
+
This project is licensed under the [MIT License](LICENSE.md).
|
package/addon-main.cjs
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import Component from '@glimmer/component';
|
|
2
|
+
import type RouterService from '@ember/routing/router-service';
|
|
3
|
+
import type Owner from '@ember/owner';
|
|
4
|
+
import type Transition from '@ember/routing/transition';
|
|
5
|
+
import type { Timer } from '@ember/runloop';
|
|
6
|
+
export interface NavigationNarratorSignature {
|
|
7
|
+
Args: {
|
|
8
|
+
/** Whether to include the skip link. Defaults to `true`. */
|
|
9
|
+
skipLink?: boolean;
|
|
10
|
+
/** CSS selector the skip link jumps to. Defaults to `'#main'`. */
|
|
11
|
+
skipTo?: string;
|
|
12
|
+
/** Text content of the skip link. Defaults to `'Skip to main content'`. */
|
|
13
|
+
skipText?: string;
|
|
14
|
+
/** Text announced by a screen reader after navigation. */
|
|
15
|
+
navigationText?: string;
|
|
16
|
+
/** Custom logic for determining whether a transition should trigger narration. */
|
|
17
|
+
routeChangeValidator?: (transition: Transition) => boolean;
|
|
18
|
+
/** Whether to ignore query param changes during route comparisons. Defaults to `false`. */
|
|
19
|
+
excludeAllQueryParams?: boolean;
|
|
20
|
+
};
|
|
21
|
+
Element: HTMLElement;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* 🎧 NavigationNarrator
|
|
25
|
+
*
|
|
26
|
+
* Announces route changes for screen readers using a visually-hidden element,
|
|
27
|
+
* and optionally renders a "Skip to main content" link.
|
|
28
|
+
*
|
|
29
|
+
* Usage:
|
|
30
|
+
* ```gjs
|
|
31
|
+
* import { NavigationNarrator } from 'ember-a11y-refocus';
|
|
32
|
+
*
|
|
33
|
+
* <template>
|
|
34
|
+
* <NavigationNarrator />
|
|
35
|
+
* </template>
|
|
36
|
+
* ```
|
|
37
|
+
*/
|
|
38
|
+
export default class NavigationNarrator extends Component<NavigationNarratorSignature> {
|
|
39
|
+
readonly router: RouterService;
|
|
40
|
+
isSkipLinkFocused: boolean;
|
|
41
|
+
timer: Timer | undefined;
|
|
42
|
+
transition: Transition | undefined;
|
|
43
|
+
constructor(owner: Owner, args: NavigationNarratorSignature['Args']);
|
|
44
|
+
/** Whether to include the skip link. Defaults to `true`. */
|
|
45
|
+
get skipLink(): boolean;
|
|
46
|
+
/** Selector for the skip link target. Defaults to `'#main'`. */
|
|
47
|
+
get skipTo(): string;
|
|
48
|
+
/** Text for the skip link. Defaults to `'Skip to main content'`. */
|
|
49
|
+
get skipText(): string;
|
|
50
|
+
/** Text announced by screen readers after route transition. */
|
|
51
|
+
get navigationText(): string;
|
|
52
|
+
/** Validator function for transitions. */
|
|
53
|
+
get routeChangeValidator(): (transition: Transition) => boolean;
|
|
54
|
+
/** Whether to ignore query param changes. Defaults to `false`. */
|
|
55
|
+
get excludeAllQueryParams(): boolean;
|
|
56
|
+
/** Whether the current transition includes query param changes. */
|
|
57
|
+
get hasQueryParams(): boolean;
|
|
58
|
+
onRouteChange: (transition: Transition) => void;
|
|
59
|
+
handleSkipLinkFocus: () => void;
|
|
60
|
+
}
|
|
61
|
+
//# sourceMappingURL=navigation-narrator.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"navigation-narrator.d.ts","sourceRoot":"","sources":["../../src/components/navigation-narrator.gts"],"names":[],"mappings":"AA+KA,OAAO,SAAS,MAAM,oBAAoB,CAAC;AAS3C,OAAO,KAAK,aAAa,MAAM,+BAA+B,CAAC;AAC/D,OAAO,KAAK,KAAK,MAAM,cAAc,CAAC;AACtC,OAAO,KAAK,UAAU,MAAM,2BAA2B,CAAC;AACxD,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,gBAAgB,CAAC;AAE5C,MAAM,WAAW,2BAA2B;IAC1C,IAAI,EAAE;QACJ,4DAA4D;QAC5D,QAAQ,CAAC,EAAE,OAAO,CAAC;QAEnB,kEAAkE;QAClE,MAAM,CAAC,EAAE,MAAM,CAAC;QAEhB,2EAA2E;QAC3E,QAAQ,CAAC,EAAE,MAAM,CAAC;QAElB,0DAA0D;QAC1D,cAAc,CAAC,EAAE,MAAM,CAAC;QAExB,kFAAkF;QAClF,oBAAoB,CAAC,EAAE,CAAC,UAAU,EAAE,UAAU,KAAK,OAAO,CAAC;QAE3D,2FAA2F;QAC3F,qBAAqB,CAAC,EAAE,OAAO,CAAC;KACjC,CAAC;IAEF,OAAO,EAAE,WAAW,CAAC;CACtB;AAED;;;;;;;;;;;;;;GAcG;AACH,MAAM,CAAC,OAAO,OAAO,kBAAmB,SAAQ,SAAS,CAAC,2BAA2B,CAAC;IACpF,SAA0B,MAAM,EAAE,aAAa,CAAC;IAEvC,iBAAiB,UAAS;IAEnC,KAAK,EAAE,KAAK,GAAG,SAAS,CAAC;IACzB,UAAU,EAAE,UAAU,GAAG,SAAS,CAAC;gBAEvB,KAAK,EAAE,KAAK,EAAE,IAAI,EAAE,2BAA2B,CAAC,MAAM,CAAC;IAanE,4DAA4D;IAC5D,IAAI,QAAQ,YAEX;IAED,gEAAgE;IAChE,IAAI,MAAM,WAET;IAED,oEAAoE;IACpE,IAAI,QAAQ,WAEX;IAED,+DAA+D;IAC/D,IAAI,cAAc,WAKjB;IAED,0CAA0C;IAC1C,IAAI,oBAAoB,iBArEc,UAAU,KAAK,OAAO,CAuE3D;IAED,kEAAkE;IAClE,IAAI,qBAAqB,YAExB;IAED,mEAAmE;IACnE,IAAI,cAAc,YASjB;IAED,aAAa,GAAI,YAAY,UAAU,UA2BrC;IAEF,mBAAmB,aAEjB;CAmCH"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,IAAI,kBAAkB,EAAE,MAAM,sCAAsC,CAAC;AACrF,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"template-registry.d.ts","sourceRoot":"","sources":["../src/template-registry.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,kBAAkB,MAAM,sCAAsC,CAAC;AAE3E,MAAM,CAAC,OAAO,WAAW,wBAAwB;IAC/C,kBAAkB,EAAE,OAAO,kBAAkB,CAAC;CAC/C"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type RouteInfo from '@ember/routing/route-info';
|
|
2
|
+
export interface RouteInfoLike {
|
|
3
|
+
name: string;
|
|
4
|
+
params: Record<string, unknown>;
|
|
5
|
+
queryParams: Record<string, unknown>;
|
|
6
|
+
parent: RouteInfoLike | RouteInfo | null;
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* Returns true if the given RouteInfo objects represent the same route in the
|
|
10
|
+
* tree, with matching params and query params.
|
|
11
|
+
*/
|
|
12
|
+
export declare function routeInfoEqual(a: RouteInfoLike | RouteInfo | null | undefined | void, b: RouteInfoLike | RouteInfo | null | undefined | void): boolean;
|
|
13
|
+
//# sourceMappingURL=routing.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"routing.d.ts","sourceRoot":"","sources":["../../src/utils/routing.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,SAAS,MAAM,2BAA2B,CAAC;AAEvD,MAAM,WAAW,aAAa;IAC5B,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAChC,WAAW,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACrC,MAAM,EAAE,aAAa,GAAG,SAAS,GAAG,IAAI,CAAC;CAC1C;AAED;;;GAGG;AACH,wBAAgB,cAAc,CAC5B,CAAC,EAAE,aAAa,GAAG,SAAS,GAAG,IAAI,GAAG,SAAS,GAAG,IAAI,EACtD,CAAC,EAAE,aAAa,GAAG,SAAS,GAAG,IAAI,GAAG,SAAS,GAAG,IAAI,GACrD,OAAO,CAoCT"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type RouteInfo from '@ember/routing/route-info';
|
|
2
|
+
import type { RouteInfoLike } from './routing.ts';
|
|
3
|
+
interface TransitionLike {
|
|
4
|
+
from?: RouteInfoLike | RouteInfo | null | undefined | void;
|
|
5
|
+
to?: RouteInfoLike | RouteInfo | null | undefined | void;
|
|
6
|
+
}
|
|
7
|
+
export declare function defaultValidator(transition: TransitionLike): boolean;
|
|
8
|
+
export {};
|
|
9
|
+
//# sourceMappingURL=validators.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validators.d.ts","sourceRoot":"","sources":["../../src/utils/validators.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,SAAS,MAAM,2BAA2B,CAAC;AACvD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAElD,UAAU,cAAc;IACtB,IAAI,CAAC,EAAE,aAAa,GAAG,SAAS,GAAG,IAAI,GAAG,SAAS,GAAG,IAAI,CAAC;IAC3D,EAAE,CAAC,EAAE,aAAa,GAAG,SAAS,GAAG,IAAI,GAAG,SAAS,GAAG,IAAI,CAAC;CAC1D;AAED,wBAAgB,gBAAgB,CAAC,UAAU,EAAE,cAAc,GAAG,OAAO,CAEpE"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default } from "ember-a11y-refocus/components/navigation-narrator";
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
import Component from '@glimmer/component';
|
|
2
|
+
import { service } from '@ember/service';
|
|
3
|
+
import { tracked } from '@glimmer/tracking';
|
|
4
|
+
import { on } from '@ember/modifier';
|
|
5
|
+
import { registerDestructor } from '@ember/destroyable';
|
|
6
|
+
import { cancel, schedule } from '@ember/runloop';
|
|
7
|
+
import { defaultValidator } from '../utils/validators.js';
|
|
8
|
+
import { precompileTemplate } from '@ember/template-compilation';
|
|
9
|
+
import { setComponentTemplate } from '@ember/component';
|
|
10
|
+
import { g, i } from 'decorator-transforms/runtime-esm';
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* 🎧 NavigationNarrator
|
|
14
|
+
*
|
|
15
|
+
* Announces route changes for screen readers using a visually-hidden element,
|
|
16
|
+
* and optionally renders a "Skip to main content" link.
|
|
17
|
+
*
|
|
18
|
+
* Usage:
|
|
19
|
+
* ```gjs
|
|
20
|
+
* import { NavigationNarrator } from 'ember-a11y-refocus';
|
|
21
|
+
*
|
|
22
|
+
* <template>
|
|
23
|
+
* <NavigationNarrator />
|
|
24
|
+
* </template>
|
|
25
|
+
* ```
|
|
26
|
+
*/
|
|
27
|
+
class NavigationNarrator extends Component {
|
|
28
|
+
static {
|
|
29
|
+
g(this.prototype, "router", [service]);
|
|
30
|
+
}
|
|
31
|
+
#router = (i(this, "router"), void 0);
|
|
32
|
+
static {
|
|
33
|
+
g(this.prototype, "isSkipLinkFocused", [tracked], function () {
|
|
34
|
+
return false;
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
#isSkipLinkFocused = (i(this, "isSkipLinkFocused"), void 0);
|
|
38
|
+
timer;
|
|
39
|
+
transition;
|
|
40
|
+
constructor(owner, args) {
|
|
41
|
+
super(owner, args);
|
|
42
|
+
this.router.on('routeDidChange', this.onRouteChange);
|
|
43
|
+
registerDestructor(this, () => {
|
|
44
|
+
// eslint-disable-next-line ember/no-runloop
|
|
45
|
+
cancel(this.timer);
|
|
46
|
+
this.timer = undefined;
|
|
47
|
+
this.router.off('routeDidChange', this.onRouteChange);
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
/** Whether to include the skip link. Defaults to `true`. */
|
|
51
|
+
get skipLink() {
|
|
52
|
+
return this.args.skipLink ?? true;
|
|
53
|
+
}
|
|
54
|
+
/** Selector for the skip link target. Defaults to `'#main'`. */
|
|
55
|
+
get skipTo() {
|
|
56
|
+
return this.args.skipTo ?? '#main';
|
|
57
|
+
}
|
|
58
|
+
/** Text for the skip link. Defaults to `'Skip to main content'`. */
|
|
59
|
+
get skipText() {
|
|
60
|
+
return this.args.skipText ?? 'Skip to main content';
|
|
61
|
+
}
|
|
62
|
+
/** Text announced by screen readers after route transition. */
|
|
63
|
+
get navigationText() {
|
|
64
|
+
return this.args.navigationText ?? 'The page navigation is complete. You may now navigate the page content as you wish.';
|
|
65
|
+
}
|
|
66
|
+
/** Validator function for transitions. */
|
|
67
|
+
get routeChangeValidator() {
|
|
68
|
+
return this.args.routeChangeValidator ?? defaultValidator;
|
|
69
|
+
}
|
|
70
|
+
/** Whether to ignore query param changes. Defaults to `false`. */
|
|
71
|
+
get excludeAllQueryParams() {
|
|
72
|
+
return this.args.excludeAllQueryParams ?? false;
|
|
73
|
+
}
|
|
74
|
+
/** Whether the current transition includes query param changes. */
|
|
75
|
+
get hasQueryParams() {
|
|
76
|
+
if (Object.keys(this.transition?.from?.queryParams || {}).length || Object.keys(this.transition?.to?.queryParams || {}).length > 0) {
|
|
77
|
+
return true;
|
|
78
|
+
} else {
|
|
79
|
+
return false;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
onRouteChange = transition => {
|
|
83
|
+
this.transition = transition; // We need to do this because we can't pass an argument to a getter
|
|
84
|
+
// add a check to see if it's the same route
|
|
85
|
+
const hasSameRoute = this.transition.from?.name === this.transition.to?.name;
|
|
86
|
+
if (this.excludeAllQueryParams && this.hasQueryParams && hasSameRoute) {
|
|
87
|
+
return;
|
|
88
|
+
}
|
|
89
|
+
const shouldFocus = this.routeChangeValidator(transition);
|
|
90
|
+
// leaving this here for now because maybe it needs to be used in a custom validator function
|
|
91
|
+
if (!shouldFocus) {
|
|
92
|
+
return;
|
|
93
|
+
}
|
|
94
|
+
// eslint-disable-next-line ember/no-runloop
|
|
95
|
+
this.timer = schedule('afterRender', this, function () {
|
|
96
|
+
this.timer = undefined;
|
|
97
|
+
document.body.querySelector('#ember-a11y-refocus-nav-message')?.focus();
|
|
98
|
+
});
|
|
99
|
+
};
|
|
100
|
+
handleSkipLinkFocus = () => {
|
|
101
|
+
this.isSkipLinkFocused = !this.isSkipLinkFocused;
|
|
102
|
+
};
|
|
103
|
+
static {
|
|
104
|
+
setComponentTemplate(precompileTemplate("<div tabindex=\"-1\" id=\"ember-a11y-refocus-nav-message\" class=\"ember-sr-only ember-sr-only-focusable\">\n {{this.navigationText}}\n</div>\n\n{{#if this.skipLink}}\n <a href={{this.skipTo}} id=\"ember-a11y-refocus-skip-link\" class=\"ember-a11y-refocus-skip-link\n {{if this.isSkipLinkFocused \"active\"}}\" {{on \"focus\" this.handleSkipLinkFocus}} {{on \"blur\" this.handleSkipLinkFocus}}>\n {{this.skipText}}\n </a>\n{{/if}}", {
|
|
105
|
+
strictMode: true,
|
|
106
|
+
scope: () => ({
|
|
107
|
+
on
|
|
108
|
+
})
|
|
109
|
+
}), this);
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
export { NavigationNarrator as default };
|
|
114
|
+
//# sourceMappingURL=navigation-narrator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"navigation-narrator.js","sources":["../../src/components/navigation-narrator.gts"],"sourcesContent":["import Component from '@glimmer/component';\nimport { service } from '@ember/service';\nimport { tracked } from '@glimmer/tracking';\nimport { on } from '@ember/modifier';\nimport { registerDestructor } from '@ember/destroyable';\nimport { schedule, cancel } from '@ember/runloop';\n\nimport { defaultValidator } from '../utils/validators.ts';\n\nimport type RouterService from '@ember/routing/router-service';\nimport type Owner from '@ember/owner';\nimport type Transition from '@ember/routing/transition';\nimport type { Timer } from '@ember/runloop';\n\nexport interface NavigationNarratorSignature {\n Args: {\n /** Whether to include the skip link. Defaults to `true`. */\n skipLink?: boolean;\n\n /** CSS selector the skip link jumps to. Defaults to `'#main'`. */\n skipTo?: string;\n\n /** Text content of the skip link. Defaults to `'Skip to main content'`. */\n skipText?: string;\n\n /** Text announced by a screen reader after navigation. */\n navigationText?: string;\n\n /** Custom logic for determining whether a transition should trigger narration. */\n routeChangeValidator?: (transition: Transition) => boolean;\n\n /** Whether to ignore query param changes during route comparisons. Defaults to `false`. */\n excludeAllQueryParams?: boolean;\n };\n\n Element: HTMLElement;\n}\n\n/**\n * 🎧 NavigationNarrator\n *\n * Announces route changes for screen readers using a visually-hidden element,\n * and optionally renders a \"Skip to main content\" link.\n *\n * Usage:\n * ```gjs\n * import { NavigationNarrator } from 'ember-a11y-refocus';\n *\n * <template>\n * <NavigationNarrator />\n * </template>\n * ```\n */\nexport default class NavigationNarrator extends Component<NavigationNarratorSignature> {\n @service declare readonly router: RouterService;\n\n @tracked isSkipLinkFocused = false;\n\n timer: Timer | undefined;\n transition: Transition | undefined;\n\n constructor(owner: Owner, args: NavigationNarratorSignature['Args']) {\n super(owner, args);\n\n this.router.on('routeDidChange', this.onRouteChange);\n\n registerDestructor(this, () => {\n // eslint-disable-next-line ember/no-runloop\n cancel(this.timer);\n this.timer = undefined;\n this.router.off('routeDidChange', this.onRouteChange);\n });\n }\n\n /** Whether to include the skip link. Defaults to `true`. */\n get skipLink() {\n return this.args.skipLink ?? true;\n }\n\n /** Selector for the skip link target. Defaults to `'#main'`. */\n get skipTo() {\n return this.args.skipTo ?? '#main';\n }\n\n /** Text for the skip link. Defaults to `'Skip to main content'`. */\n get skipText() {\n return this.args.skipText ?? 'Skip to main content';\n }\n\n /** Text announced by screen readers after route transition. */\n get navigationText() {\n return (\n this.args.navigationText ??\n 'The page navigation is complete. You may now navigate the page content as you wish.'\n );\n }\n\n /** Validator function for transitions. */\n get routeChangeValidator() {\n return this.args.routeChangeValidator ?? defaultValidator;\n }\n\n /** Whether to ignore query param changes. Defaults to `false`. */\n get excludeAllQueryParams() {\n return this.args.excludeAllQueryParams ?? false;\n }\n\n /** Whether the current transition includes query param changes. */\n get hasQueryParams() {\n if (\n Object.keys(this.transition?.from?.queryParams || {}).length ||\n Object.keys(this.transition?.to?.queryParams || {}).length > 0\n ) {\n return true;\n } else {\n return false;\n }\n }\n\n onRouteChange = (transition: Transition) => {\n this.transition = transition; // We need to do this because we can't pass an argument to a getter\n\n // add a check to see if it's the same route\n const hasSameRoute =\n this.transition.from?.name === this.transition.to?.name;\n\n if (this.excludeAllQueryParams && this.hasQueryParams && hasSameRoute) {\n return;\n }\n\n const shouldFocus = this.routeChangeValidator(transition);\n\n // leaving this here for now because maybe it needs to be used in a custom validator function\n if (!shouldFocus) {\n return;\n }\n\n // eslint-disable-next-line ember/no-runloop\n this.timer = schedule('afterRender', this, function () {\n this.timer = undefined;\n (\n document.body.querySelector(\n '#ember-a11y-refocus-nav-message',\n ) as HTMLElement\n )?.focus();\n });\n };\n\n handleSkipLinkFocus = () => {\n this.isSkipLinkFocused = !this.isSkipLinkFocused;\n };\n\n <template>\n <div\n tabindex=\"-1\"\n id=\"ember-a11y-refocus-nav-message\"\n class=\"ember-sr-only ember-sr-only-focusable\"\n >\n {{this.navigationText}}\n </div>\n\n {{#if this.skipLink}}\n <a\n href={{this.skipTo}}\n id=\"ember-a11y-refocus-skip-link\"\n class=\"ember-a11y-refocus-skip-link\n {{if this.isSkipLinkFocused 'active'}}\"\n {{on \"focus\" this.handleSkipLinkFocus}}\n {{on \"blur\" this.handleSkipLinkFocus}}\n >\n {{this.skipText}}\n </a>\n {{/if}}\n </template>\n}\n"],"names":["NavigationNarrator","Component","g","prototype","service","i","tracked","timer","transition","constructor","owner","args","router","on","onRouteChange","registerDestructor","cancel","undefined","off","skipLink","skipTo","skipText","navigationText","routeChangeValidator","defaultValidator","excludeAllQueryParams","hasQueryParams","Object","keys","from","queryParams","length","to","hasSameRoute","name","shouldFocus","schedule","document","body","querySelector","focus","handleSkipLinkFocus","isSkipLinkFocused","setComponentTemplate","precompileTemplate","strictMode","scope"],"mappings":"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"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
#ember-a11y-refocus-nav-message {
|
|
2
|
+
position: absolute;
|
|
3
|
+
width: 1px;
|
|
4
|
+
height: 1px;
|
|
5
|
+
padding: 0;
|
|
6
|
+
overflow: hidden;
|
|
7
|
+
clip-path: inset(50%);
|
|
8
|
+
white-space: nowrap;
|
|
9
|
+
border: 0;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
.ember-a11y-refocus-skip-link {
|
|
13
|
+
position: absolute;
|
|
14
|
+
left: 0;
|
|
15
|
+
top: 0;
|
|
16
|
+
background-color: rgb(0 0 0 / 75%);
|
|
17
|
+
font-size: 0.75rem;
|
|
18
|
+
color: #fff;
|
|
19
|
+
padding: 0.25rem;
|
|
20
|
+
text-decoration: none;
|
|
21
|
+
transform: translateY(-100%);
|
|
22
|
+
transition: transform 0.3s ease-in-out;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
.ember-a11y-refocus-skip-link:focus {
|
|
26
|
+
transform: translateY(0);
|
|
27
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"template-registry.js","sources":[],"sourcesContent":[],"names":[],"mappings":""}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Returns true if the given RouteInfo objects represent the same route in the
|
|
3
|
+
* tree, with matching params and query params.
|
|
4
|
+
*/
|
|
5
|
+
function routeInfoEqual(a, b) {
|
|
6
|
+
let current_a = a;
|
|
7
|
+
let current_b = b;
|
|
8
|
+
do {
|
|
9
|
+
if (!current_a || !current_b) {
|
|
10
|
+
return false;
|
|
11
|
+
}
|
|
12
|
+
if (current_a.name !== current_b.name) {
|
|
13
|
+
return false;
|
|
14
|
+
}
|
|
15
|
+
if (!shallowEqual(current_a.params, current_b.params)) {
|
|
16
|
+
return false;
|
|
17
|
+
}
|
|
18
|
+
if (!shallowEqual(current_a.queryParams, current_b.queryParams)) {
|
|
19
|
+
return false;
|
|
20
|
+
}
|
|
21
|
+
current_a = current_a.parent;
|
|
22
|
+
current_b = current_b.parent;
|
|
23
|
+
} while (current_a || current_b);
|
|
24
|
+
return true;
|
|
25
|
+
}
|
|
26
|
+
function shallowEqual(a, b) {
|
|
27
|
+
const keys = new Set([...Object.keys(a), ...Object.keys(b)]);
|
|
28
|
+
for (const key of keys) {
|
|
29
|
+
if (a[key] !== b[key]) {
|
|
30
|
+
return false;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
return true;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export { routeInfoEqual };
|
|
37
|
+
//# sourceMappingURL=routing.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"routing.js","sources":["../../src/utils/routing.ts"],"sourcesContent":["import type RouteInfo from '@ember/routing/route-info';\n\nexport interface RouteInfoLike {\n name: string;\n params: Record<string, unknown>;\n queryParams: Record<string, unknown>;\n parent: RouteInfoLike | RouteInfo | null;\n}\n\n/**\n * Returns true if the given RouteInfo objects represent the same route in the\n * tree, with matching params and query params.\n */\nexport function routeInfoEqual(\n a: RouteInfoLike | RouteInfo | null | undefined | void,\n b: RouteInfoLike | RouteInfo | null | undefined | void,\n): boolean {\n let current_a: RouteInfoLike | RouteInfo | null | undefined | void = a;\n let current_b: RouteInfoLike | RouteInfo | null | undefined | void = b;\n\n do {\n if (!current_a || !current_b) {\n return false;\n }\n\n if (current_a.name !== current_b.name) {\n return false;\n }\n\n if (\n !shallowEqual(\n current_a.params as Record<string, unknown>,\n current_b.params as Record<string, unknown>,\n )\n ) {\n return false;\n }\n\n if (\n !shallowEqual(\n current_a.queryParams as Record<string, unknown>,\n current_b.queryParams as Record<string, unknown>,\n )\n ) {\n return false;\n }\n\n current_a = current_a.parent;\n current_b = current_b.parent;\n } while (current_a || current_b);\n\n return true;\n}\n\nfunction shallowEqual(\n a: Record<string, unknown>,\n b: Record<string, unknown>,\n): boolean {\n const keys = new Set([...Object.keys(a), ...Object.keys(b)]);\n\n for (const key of keys) {\n if (a[key] !== b[key]) {\n return false;\n }\n }\n\n return true;\n}\n"],"names":["routeInfoEqual","a","b","current_a","current_b","name","shallowEqual","params","queryParams","parent","keys","Set","Object","key"],"mappings":"AASA;AACA;AACA;AACA;AACO,SAASA,cAAcA,CAC5BC,CAAsD,EACtDC,CAAsD,EAC7C;EACT,IAAIC,SAA8D,GAAGF,CAAC;EACtE,IAAIG,SAA8D,GAAGF,CAAC;EAEtE,GAAG;AACD,IAAA,IAAI,CAACC,SAAS,IAAI,CAACC,SAAS,EAAE;AAC5B,MAAA,OAAO,KAAK;AACd,IAAA;AAEA,IAAA,IAAID,SAAS,CAACE,IAAI,KAAKD,SAAS,CAACC,IAAI,EAAE;AACrC,MAAA,OAAO,KAAK;AACd,IAAA;IAEA,IACE,CAACC,YAAY,CACXH,SAAS,CAACI,MAAM,EAChBH,SAAS,CAACG,MACZ,CAAC,EACD;AACA,MAAA,OAAO,KAAK;AACd,IAAA;IAEA,IACE,CAACD,YAAY,CACXH,SAAS,CAACK,WAAW,EACrBJ,SAAS,CAACI,WACZ,CAAC,EACD;AACA,MAAA,OAAO,KAAK;AACd,IAAA;IAEAL,SAAS,GAAGA,SAAS,CAACM,MAAM;IAC5BL,SAAS,GAAGA,SAAS,CAACK,MAAM;EAC9B,CAAC,QAAQN,SAAS,IAAIC,SAAS;AAE/B,EAAA,OAAO,IAAI;AACb;AAEA,SAASE,YAAYA,CACnBL,CAA0B,EAC1BC,CAA0B,EACjB;EACT,MAAMQ,IAAI,GAAG,IAAIC,GAAG,CAAC,CAAC,GAAGC,MAAM,CAACF,IAAI,CAACT,CAAC,CAAC,EAAE,GAAGW,MAAM,CAACF,IAAI,CAACR,CAAC,CAAC,CAAC,CAAC;AAE5D,EAAA,KAAK,MAAMW,GAAG,IAAIH,IAAI,EAAE;IACtB,IAAIT,CAAC,CAACY,GAAG,CAAC,KAAKX,CAAC,CAACW,GAAG,CAAC,EAAE;AACrB,MAAA,OAAO,KAAK;AACd,IAAA;AACF,EAAA;AAEA,EAAA,OAAO,IAAI;AACb;;;;"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validators.js","sources":["../../src/utils/validators.ts"],"sourcesContent":["import { routeInfoEqual } from './routing.ts';\n\nimport type RouteInfo from '@ember/routing/route-info';\nimport type { RouteInfoLike } from './routing.ts';\n\ninterface TransitionLike {\n from?: RouteInfoLike | RouteInfo | null | undefined | void;\n to?: RouteInfoLike | RouteInfo | null | undefined | void;\n}\n\nexport function defaultValidator(transition: TransitionLike): boolean {\n return !routeInfoEqual(transition.from, transition.to);\n}\n"],"names":["defaultValidator","transition","routeInfoEqual","from","to"],"mappings":";;AAUO,SAASA,gBAAgBA,CAACC,UAA0B,EAAW;EACpE,OAAO,CAACC,cAAc,CAACD,UAAU,CAACE,IAAI,EAAEF,UAAU,CAACG,EAAE,CAAC;AACxD;;;;"}
|
package/package.json
ADDED
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@ohos-ports/ember-a11y-refocus",
|
|
3
|
+
"version": "5.2.1-beta.1",
|
|
4
|
+
"description": "Accessibility addon to announce route change, reset focus, and provide a skip link",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"ember-addon",
|
|
7
|
+
"accessibility",
|
|
8
|
+
"a11y",
|
|
9
|
+
"skiplink"
|
|
10
|
+
],
|
|
11
|
+
"repository": {
|
|
12
|
+
"type": "git",
|
|
13
|
+
"url": "https://github.com/ohos-ports/ohos-ports.git",
|
|
14
|
+
"directory": "ports/ember-a11y-refocus/5.2.1"
|
|
15
|
+
},
|
|
16
|
+
"license": "MIT",
|
|
17
|
+
"author": "Melanie Sumner <melaniersumner@gmail.com>",
|
|
18
|
+
"contributors": [
|
|
19
|
+
{
|
|
20
|
+
"name": "Alexey Kulakov"
|
|
21
|
+
}
|
|
22
|
+
],
|
|
23
|
+
"imports": {
|
|
24
|
+
"#src/*": "./src/*"
|
|
25
|
+
},
|
|
26
|
+
"exports": {
|
|
27
|
+
".": {
|
|
28
|
+
"types": "./declarations/index.d.ts",
|
|
29
|
+
"default": "./dist/index.js"
|
|
30
|
+
},
|
|
31
|
+
"./addon-main.js": "./addon-main.cjs",
|
|
32
|
+
"./*.css": "./dist/*.css",
|
|
33
|
+
"./*": {
|
|
34
|
+
"types": "./declarations/*.d.ts",
|
|
35
|
+
"default": "./dist/*.js"
|
|
36
|
+
}
|
|
37
|
+
},
|
|
38
|
+
"files": [
|
|
39
|
+
"addon-main.cjs",
|
|
40
|
+
"declarations",
|
|
41
|
+
"dist",
|
|
42
|
+
"src"
|
|
43
|
+
],
|
|
44
|
+
"dependencies": {
|
|
45
|
+
"@embroider/addon-shim": "^1.10.2",
|
|
46
|
+
"decorator-transforms": "^2.3.1"
|
|
47
|
+
},
|
|
48
|
+
"devDependencies": {
|
|
49
|
+
"@babel/core": "^7.29.0",
|
|
50
|
+
"@babel/eslint-parser": "^7.28.6",
|
|
51
|
+
"@babel/plugin-transform-typescript": "^7.28.6",
|
|
52
|
+
"@babel/runtime": "^7.28.6",
|
|
53
|
+
"@ember/app-tsconfig": "^2.0.0",
|
|
54
|
+
"@ember/library-tsconfig": "^2.0.0",
|
|
55
|
+
"@ember/test-helpers": "^5.4.1",
|
|
56
|
+
"@ember/test-waiters": "^4.1.1",
|
|
57
|
+
"@embroider/addon-dev": "^8.3.0",
|
|
58
|
+
"@embroider/compat": "^4.1.13",
|
|
59
|
+
"@embroider/core": "^4.4.3",
|
|
60
|
+
"@embroider/macros": "^1.19.7",
|
|
61
|
+
"@embroider/vite": "^1.5.2",
|
|
62
|
+
"@eslint/js": "^9.39.3",
|
|
63
|
+
"@glint/ember-tsc": "^1.1.1",
|
|
64
|
+
"@glint/template": "^1.7.4",
|
|
65
|
+
"@glint/tsserver-plugin": "^2.1.0",
|
|
66
|
+
"@ohos-ports/glimmer-component": "^2.1.1-beta.0",
|
|
67
|
+
"@ohos-ports/rollup": "^4.62.2-beta.2",
|
|
68
|
+
"@rollup/plugin-babel": "^6.1.0",
|
|
69
|
+
"@types/qunit": "^2.19.13",
|
|
70
|
+
"babel-plugin-ember-template-compilation": "^4.0.0",
|
|
71
|
+
"concurrently": "^9.2.1",
|
|
72
|
+
"ember-page-title": "^9.0.3",
|
|
73
|
+
"ember-qunit": "^9.0.4",
|
|
74
|
+
"ember-source": "^6.11.0",
|
|
75
|
+
"ember-strict-application-resolver": "^0.1.1",
|
|
76
|
+
"ember-template-lint": "^7.9.3",
|
|
77
|
+
"eslint": "^9.39.3",
|
|
78
|
+
"eslint-config-prettier": "^10.1.8",
|
|
79
|
+
"eslint-plugin-ember": "^12.7.5",
|
|
80
|
+
"eslint-plugin-import": "^2.32.0",
|
|
81
|
+
"eslint-plugin-n": "^17.24.0",
|
|
82
|
+
"globals": "^17.3.0",
|
|
83
|
+
"prettier": "^3.8.1",
|
|
84
|
+
"prettier-plugin-ember-template-tag": "^2.1.3",
|
|
85
|
+
"publint": "^0.3.17",
|
|
86
|
+
"qunit": "^2.25.0",
|
|
87
|
+
"qunit-dom": "^3.5.0",
|
|
88
|
+
"release-plan": "^0.17.4",
|
|
89
|
+
"rollup-plugin-copy": "^3.5.0",
|
|
90
|
+
"testem": "^3.17.0",
|
|
91
|
+
"typescript": "~5.9.3",
|
|
92
|
+
"typescript-eslint": "^8.56.0",
|
|
93
|
+
"vite": "^7.3.1"
|
|
94
|
+
},
|
|
95
|
+
"engines": {
|
|
96
|
+
"node": "22.x",
|
|
97
|
+
"pnpm": ">= 10"
|
|
98
|
+
},
|
|
99
|
+
"ember": {
|
|
100
|
+
"edition": "octane"
|
|
101
|
+
},
|
|
102
|
+
"ember-addon": {
|
|
103
|
+
"version": 2,
|
|
104
|
+
"type": "addon",
|
|
105
|
+
"main": "addon-main.cjs",
|
|
106
|
+
"app-js": {
|
|
107
|
+
"./components/navigation-narrator.js": "./dist/_app_/components/navigation-narrator.js"
|
|
108
|
+
}
|
|
109
|
+
},
|
|
110
|
+
"scripts": {
|
|
111
|
+
"build": "rollup --config",
|
|
112
|
+
"format": "prettier . --cache --write",
|
|
113
|
+
"lint": "concurrently \"pnpm:lint:*(!fix)\" --names \"lint:\" --prefixColors auto",
|
|
114
|
+
"lint:fix": "concurrently \"pnpm:lint:*:fix\" --names \"fix:\" --prefixColors auto && pnpm run format",
|
|
115
|
+
"lint:format": "prettier . --cache --check",
|
|
116
|
+
"lint:hbs": "ember-template-lint . --no-error-on-unmatched-pattern",
|
|
117
|
+
"lint:hbs:fix": "ember-template-lint . --fix --no-error-on-unmatched-pattern",
|
|
118
|
+
"lint:js": "eslint . --cache",
|
|
119
|
+
"lint:js:fix": "eslint . --fix",
|
|
120
|
+
"lint:publish": "pnpm build && publint run --level error",
|
|
121
|
+
"lint:types": "ember-tsc --noEmit",
|
|
122
|
+
"start": "vite dev",
|
|
123
|
+
"test": "vite build --mode=development --out-dir dist-tests && testem --file testem.cjs ci --port 0"
|
|
124
|
+
},
|
|
125
|
+
"bugs": {
|
|
126
|
+
"url": "https://github.com/ohos-ports/ohos-ports/issues"
|
|
127
|
+
}
|
|
128
|
+
}
|
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
import Component from '@glimmer/component';
|
|
2
|
+
import { service } from '@ember/service';
|
|
3
|
+
import { tracked } from '@glimmer/tracking';
|
|
4
|
+
import { on } from '@ember/modifier';
|
|
5
|
+
import { registerDestructor } from '@ember/destroyable';
|
|
6
|
+
import { schedule, cancel } from '@ember/runloop';
|
|
7
|
+
|
|
8
|
+
import { defaultValidator } from '../utils/validators.ts';
|
|
9
|
+
|
|
10
|
+
import type RouterService from '@ember/routing/router-service';
|
|
11
|
+
import type Owner from '@ember/owner';
|
|
12
|
+
import type Transition from '@ember/routing/transition';
|
|
13
|
+
import type { Timer } from '@ember/runloop';
|
|
14
|
+
|
|
15
|
+
export interface NavigationNarratorSignature {
|
|
16
|
+
Args: {
|
|
17
|
+
/** Whether to include the skip link. Defaults to `true`. */
|
|
18
|
+
skipLink?: boolean;
|
|
19
|
+
|
|
20
|
+
/** CSS selector the skip link jumps to. Defaults to `'#main'`. */
|
|
21
|
+
skipTo?: string;
|
|
22
|
+
|
|
23
|
+
/** Text content of the skip link. Defaults to `'Skip to main content'`. */
|
|
24
|
+
skipText?: string;
|
|
25
|
+
|
|
26
|
+
/** Text announced by a screen reader after navigation. */
|
|
27
|
+
navigationText?: string;
|
|
28
|
+
|
|
29
|
+
/** Custom logic for determining whether a transition should trigger narration. */
|
|
30
|
+
routeChangeValidator?: (transition: Transition) => boolean;
|
|
31
|
+
|
|
32
|
+
/** Whether to ignore query param changes during route comparisons. Defaults to `false`. */
|
|
33
|
+
excludeAllQueryParams?: boolean;
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
Element: HTMLElement;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* 🎧 NavigationNarrator
|
|
41
|
+
*
|
|
42
|
+
* Announces route changes for screen readers using a visually-hidden element,
|
|
43
|
+
* and optionally renders a "Skip to main content" link.
|
|
44
|
+
*
|
|
45
|
+
* Usage:
|
|
46
|
+
* ```gjs
|
|
47
|
+
* import { NavigationNarrator } from 'ember-a11y-refocus';
|
|
48
|
+
*
|
|
49
|
+
* <template>
|
|
50
|
+
* <NavigationNarrator />
|
|
51
|
+
* </template>
|
|
52
|
+
* ```
|
|
53
|
+
*/
|
|
54
|
+
export default class NavigationNarrator extends Component<NavigationNarratorSignature> {
|
|
55
|
+
@service declare readonly router: RouterService;
|
|
56
|
+
|
|
57
|
+
@tracked isSkipLinkFocused = false;
|
|
58
|
+
|
|
59
|
+
timer: Timer | undefined;
|
|
60
|
+
transition: Transition | undefined;
|
|
61
|
+
|
|
62
|
+
constructor(owner: Owner, args: NavigationNarratorSignature['Args']) {
|
|
63
|
+
super(owner, args);
|
|
64
|
+
|
|
65
|
+
this.router.on('routeDidChange', this.onRouteChange);
|
|
66
|
+
|
|
67
|
+
registerDestructor(this, () => {
|
|
68
|
+
// eslint-disable-next-line ember/no-runloop
|
|
69
|
+
cancel(this.timer);
|
|
70
|
+
this.timer = undefined;
|
|
71
|
+
this.router.off('routeDidChange', this.onRouteChange);
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/** Whether to include the skip link. Defaults to `true`. */
|
|
76
|
+
get skipLink() {
|
|
77
|
+
return this.args.skipLink ?? true;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/** Selector for the skip link target. Defaults to `'#main'`. */
|
|
81
|
+
get skipTo() {
|
|
82
|
+
return this.args.skipTo ?? '#main';
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/** Text for the skip link. Defaults to `'Skip to main content'`. */
|
|
86
|
+
get skipText() {
|
|
87
|
+
return this.args.skipText ?? 'Skip to main content';
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/** Text announced by screen readers after route transition. */
|
|
91
|
+
get navigationText() {
|
|
92
|
+
return (
|
|
93
|
+
this.args.navigationText ??
|
|
94
|
+
'The page navigation is complete. You may now navigate the page content as you wish.'
|
|
95
|
+
);
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/** Validator function for transitions. */
|
|
99
|
+
get routeChangeValidator() {
|
|
100
|
+
return this.args.routeChangeValidator ?? defaultValidator;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
/** Whether to ignore query param changes. Defaults to `false`. */
|
|
104
|
+
get excludeAllQueryParams() {
|
|
105
|
+
return this.args.excludeAllQueryParams ?? false;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
/** Whether the current transition includes query param changes. */
|
|
109
|
+
get hasQueryParams() {
|
|
110
|
+
if (
|
|
111
|
+
Object.keys(this.transition?.from?.queryParams || {}).length ||
|
|
112
|
+
Object.keys(this.transition?.to?.queryParams || {}).length > 0
|
|
113
|
+
) {
|
|
114
|
+
return true;
|
|
115
|
+
} else {
|
|
116
|
+
return false;
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
onRouteChange = (transition: Transition) => {
|
|
121
|
+
this.transition = transition; // We need to do this because we can't pass an argument to a getter
|
|
122
|
+
|
|
123
|
+
// add a check to see if it's the same route
|
|
124
|
+
const hasSameRoute =
|
|
125
|
+
this.transition.from?.name === this.transition.to?.name;
|
|
126
|
+
|
|
127
|
+
if (this.excludeAllQueryParams && this.hasQueryParams && hasSameRoute) {
|
|
128
|
+
return;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
const shouldFocus = this.routeChangeValidator(transition);
|
|
132
|
+
|
|
133
|
+
// leaving this here for now because maybe it needs to be used in a custom validator function
|
|
134
|
+
if (!shouldFocus) {
|
|
135
|
+
return;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
// eslint-disable-next-line ember/no-runloop
|
|
139
|
+
this.timer = schedule('afterRender', this, function () {
|
|
140
|
+
this.timer = undefined;
|
|
141
|
+
(
|
|
142
|
+
document.body.querySelector(
|
|
143
|
+
'#ember-a11y-refocus-nav-message',
|
|
144
|
+
) as HTMLElement
|
|
145
|
+
)?.focus();
|
|
146
|
+
});
|
|
147
|
+
};
|
|
148
|
+
|
|
149
|
+
handleSkipLinkFocus = () => {
|
|
150
|
+
this.isSkipLinkFocused = !this.isSkipLinkFocused;
|
|
151
|
+
};
|
|
152
|
+
|
|
153
|
+
<template>
|
|
154
|
+
<div
|
|
155
|
+
tabindex="-1"
|
|
156
|
+
id="ember-a11y-refocus-nav-message"
|
|
157
|
+
class="ember-sr-only ember-sr-only-focusable"
|
|
158
|
+
>
|
|
159
|
+
{{this.navigationText}}
|
|
160
|
+
</div>
|
|
161
|
+
|
|
162
|
+
{{#if this.skipLink}}
|
|
163
|
+
<a
|
|
164
|
+
href={{this.skipTo}}
|
|
165
|
+
id="ember-a11y-refocus-skip-link"
|
|
166
|
+
class="ember-a11y-refocus-skip-link
|
|
167
|
+
{{if this.isSkipLinkFocused 'active'}}"
|
|
168
|
+
{{on "focus" this.handleSkipLinkFocus}}
|
|
169
|
+
{{on "blur" this.handleSkipLinkFocus}}
|
|
170
|
+
>
|
|
171
|
+
{{this.skipText}}
|
|
172
|
+
</a>
|
|
173
|
+
{{/if}}
|
|
174
|
+
</template>
|
|
175
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
#ember-a11y-refocus-nav-message {
|
|
2
|
+
position: absolute;
|
|
3
|
+
width: 1px;
|
|
4
|
+
height: 1px;
|
|
5
|
+
padding: 0;
|
|
6
|
+
overflow: hidden;
|
|
7
|
+
clip-path: inset(50%);
|
|
8
|
+
white-space: nowrap;
|
|
9
|
+
border: 0;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
.ember-a11y-refocus-skip-link {
|
|
13
|
+
position: absolute;
|
|
14
|
+
left: 0;
|
|
15
|
+
top: 0;
|
|
16
|
+
background-color: rgb(0 0 0 / 75%);
|
|
17
|
+
font-size: 0.75rem;
|
|
18
|
+
color: #fff;
|
|
19
|
+
padding: 0.25rem;
|
|
20
|
+
text-decoration: none;
|
|
21
|
+
transform: translateY(-100%);
|
|
22
|
+
transition: transform 0.3s ease-in-out;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
.ember-a11y-refocus-skip-link:focus {
|
|
26
|
+
transform: translateY(0);
|
|
27
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
// Easily allow apps, which are not yet using strict mode templates, to consume your Glint types, by importing this file.
|
|
2
|
+
// Add all your components, helpers and modifiers to the template registry here, so apps don't have to do this.
|
|
3
|
+
// See https://typed-ember.gitbook.io/glint/environments/ember/authoring-addons
|
|
4
|
+
|
|
5
|
+
import type NavigationNarrator from './components/navigation-narrator.gts';
|
|
6
|
+
|
|
7
|
+
export default interface EmberA11yRefocusRegistry {
|
|
8
|
+
NavigationNarrator: typeof NavigationNarrator;
|
|
9
|
+
}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import type RouteInfo from '@ember/routing/route-info';
|
|
2
|
+
|
|
3
|
+
export interface RouteInfoLike {
|
|
4
|
+
name: string;
|
|
5
|
+
params: Record<string, unknown>;
|
|
6
|
+
queryParams: Record<string, unknown>;
|
|
7
|
+
parent: RouteInfoLike | RouteInfo | null;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Returns true if the given RouteInfo objects represent the same route in the
|
|
12
|
+
* tree, with matching params and query params.
|
|
13
|
+
*/
|
|
14
|
+
export function routeInfoEqual(
|
|
15
|
+
a: RouteInfoLike | RouteInfo | null | undefined | void,
|
|
16
|
+
b: RouteInfoLike | RouteInfo | null | undefined | void,
|
|
17
|
+
): boolean {
|
|
18
|
+
let current_a: RouteInfoLike | RouteInfo | null | undefined | void = a;
|
|
19
|
+
let current_b: RouteInfoLike | RouteInfo | null | undefined | void = b;
|
|
20
|
+
|
|
21
|
+
do {
|
|
22
|
+
if (!current_a || !current_b) {
|
|
23
|
+
return false;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
if (current_a.name !== current_b.name) {
|
|
27
|
+
return false;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
if (
|
|
31
|
+
!shallowEqual(
|
|
32
|
+
current_a.params as Record<string, unknown>,
|
|
33
|
+
current_b.params as Record<string, unknown>,
|
|
34
|
+
)
|
|
35
|
+
) {
|
|
36
|
+
return false;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
if (
|
|
40
|
+
!shallowEqual(
|
|
41
|
+
current_a.queryParams as Record<string, unknown>,
|
|
42
|
+
current_b.queryParams as Record<string, unknown>,
|
|
43
|
+
)
|
|
44
|
+
) {
|
|
45
|
+
return false;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
current_a = current_a.parent;
|
|
49
|
+
current_b = current_b.parent;
|
|
50
|
+
} while (current_a || current_b);
|
|
51
|
+
|
|
52
|
+
return true;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
function shallowEqual(
|
|
56
|
+
a: Record<string, unknown>,
|
|
57
|
+
b: Record<string, unknown>,
|
|
58
|
+
): boolean {
|
|
59
|
+
const keys = new Set([...Object.keys(a), ...Object.keys(b)]);
|
|
60
|
+
|
|
61
|
+
for (const key of keys) {
|
|
62
|
+
if (a[key] !== b[key]) {
|
|
63
|
+
return false;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
return true;
|
|
68
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { routeInfoEqual } from './routing.ts';
|
|
2
|
+
|
|
3
|
+
import type RouteInfo from '@ember/routing/route-info';
|
|
4
|
+
import type { RouteInfoLike } from './routing.ts';
|
|
5
|
+
|
|
6
|
+
interface TransitionLike {
|
|
7
|
+
from?: RouteInfoLike | RouteInfo | null | undefined | void;
|
|
8
|
+
to?: RouteInfoLike | RouteInfo | null | undefined | void;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export function defaultValidator(transition: TransitionLike): boolean {
|
|
12
|
+
return !routeInfoEqual(transition.from, transition.to);
|
|
13
|
+
}
|