Skip to content

Commit 04dd5ca

Browse files
committed
remove jsdoc and add comments that are actually helpful in code editors
1 parent 7cdb587 commit 04dd5ca

File tree

2 files changed

+70
-63
lines changed

2 files changed

+70
-63
lines changed

addon/src/components/navigation-narrator.gts

Lines changed: 47 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -14,21 +14,44 @@ import type { Timer } from '@ember/runloop';
1414

1515
export interface NavigationNarratorSignature {
1616
Args: {
17+
/** Whether to include the skip link. Defaults to `true`. */
1718
skipLink?: boolean;
19+
20+
/** CSS selector the skip link jumps to. Defaults to `'#main'`. */
1821
skipTo?: string;
22+
23+
/** Text content of the skip link. Defaults to `'Skip to main content'`. */
1924
skipText?: string;
25+
26+
/** Text announced by a screen reader after navigation. */
2027
navigationText?: string;
28+
29+
/** Custom logic for determining whether a transition should trigger narration. */
2130
routeChangeValidator?: (transition: Transition) => boolean;
22-
excludeAllQueryParams?: boolean;
23-
};
2431

25-
Blocks: {
26-
default: [];
32+
/** Whether to ignore query param changes during route comparisons. Defaults to `false`. */
33+
excludeAllQueryParams?: boolean;
2734
};
2835

2936
Element: HTMLElement;
3037
}
3138

39+
40+
/**
41+
* 🎧 NavigationNarrator
42+
*
43+
* Announces route changes for screen readers using a visually-hidden element,
44+
* and optionally renders a "Skip to main content" link.
45+
*
46+
* Usage:
47+
* ```gts
48+
* import { NavigationNarrator } from 'ember-a11y-refocus';
49+
*
50+
* <template>
51+
* <NavigationNarrator />
52+
* </template>
53+
* ```
54+
*/
3255
export default class NavigationNarrator extends Component<NavigationNarratorSignature> {
3356
@service declare readonly router: RouterService;
3457

@@ -37,74 +60,53 @@ export default class NavigationNarrator extends Component<NavigationNarratorSign
3760
timer: Timer | undefined;
3861
transition: Transition | undefined;
3962

40-
/*
41-
* @param skipLink
42-
* @type {boolean}
43-
* @description Whether or not to include the skip link in the page. If you don't want the skip link to be included, you can set this to false.
44-
* @default true
45-
*/
63+
constructor(owner: Owner, args: NavigationNarratorSignature['Args']) {
64+
super(owner, args);
65+
66+
this.router.on('routeDidChange', this.onRouteChange);
67+
68+
registerDestructor(this, () => {
69+
// eslint-disable-next-line ember/no-runloop
70+
cancel(this.timer);
71+
this.timer = undefined;
72+
this.router.off('routeDidChange', this.onRouteChange);
73+
});
74+
}
75+
76+
/** Whether to include the skip link. Defaults to `true`. */
4677
get skipLink() {
4778
return this.args.skipLink ?? true;
4879
}
4980

50-
/*
51-
* @param skipTo
52-
* @type {string}
53-
* @description Element selector for what the skip link should jump to. A default is provided but this can be customized.
54-
* @default '#main'
55-
*/
81+
/** Selector for the skip link target. Defaults to `'#main'`. */
5682
get skipTo() {
5783
return this.args.skipTo ?? '#main';
5884
}
5985

60-
/*
61-
* @param skipText
62-
* @type {string}
63-
* @description text of the bypass block/skip link. Default text is provided but it can be customized.
64-
* @default 'Skip to main content'
65-
*/
86+
/** Text for the skip link. Defaults to `'Skip to main content'`. */
6687
get skipText() {
6788
return this.args.skipText ?? 'Skip to main content';
6889
}
6990

70-
/*
71-
* @param navigationText
72-
* @type {string}
73-
* @description The text to be read by the screen reader when the page navigation is complete. While a default message is provided, it can be customized to better fit the needs of your application.
74-
* @default 'The page navigation is complete. You may now navigate the page content as you wish.'
75-
*/
91+
/** Text announced by screen readers after route transition. */
7692
get navigationText() {
7793
return (
7894
this.args.navigationText ??
7995
'The page navigation is complete. You may now navigate the page content as you wish.'
8096
);
8197
}
8298

83-
/*
84-
* @param routeChangeValidator
85-
* @type {function}
86-
* @description A function that can be used to provide a custom definition of a route transition. Typically used if you have some query params that you don't want to trigger the route transition (but you would otherwise mostly want it to behave per Ember's default).
87-
*/
99+
/** Validator function for transitions. */
88100
get routeChangeValidator() {
89101
return this.args.routeChangeValidator ?? defaultValidator;
90102
}
91103

92-
/*
93-
* @param excludeAllQueryParams
94-
* @type {boolean}
95-
* @description Whether or not to include all query params in definition of a route transition. If you want to include/exclude _some_ query params, the routeChangeValidator function should be used instead.
96-
* @default false
97-
*/
104+
/** Whether to ignore query param changes. Defaults to `false`. */
98105
get excludeAllQueryParams() {
99106
return this.args.excludeAllQueryParams ?? false;
100107
}
101108

102-
/*
103-
* @param hasQueryParams
104-
* @type {boolean}
105-
* @description Check for queryParams.
106-
* @default false
107-
*/
109+
/** Whether the current transition includes query param changes. */
108110
get hasQueryParams() {
109111
if (
110112
Object.keys(this.transition?.from?.queryParams || {}).length ||
@@ -116,19 +118,6 @@ export default class NavigationNarrator extends Component<NavigationNarratorSign
116118
}
117119
}
118120

119-
constructor(owner: Owner, args: NavigationNarratorSignature['Args']) {
120-
super(owner, args);
121-
122-
this.router.on('routeDidChange', this.onRouteChange);
123-
124-
registerDestructor(this, () => {
125-
// eslint-disable-next-line ember/no-runloop
126-
cancel(this.timer);
127-
this.timer = undefined;
128-
this.router.off('routeDidChange', this.onRouteChange);
129-
});
130-
}
131-
132121
onRouteChange = (transition: Transition) => {
133122
this.transition = transition; // We need to do this because we can't pass an argument to a getter
134123

test-app/app/templates/application.gts

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,23 @@ interface ApplicationRouteSignature {
1616

1717
<nav>
1818
<ul>
19-
<li><LinkTo @route="index">Home</LinkTo></li>
20-
<li><LinkTo @route="alpha">Alpha</LinkTo></li>
21-
<li><LinkTo @route="bravo">Bravo</LinkTo></li>
19+
<li>
20+
<LinkTo @route="index">
21+
Home
22+
</LinkTo>
23+
</li>
24+
25+
<li>
26+
<LinkTo @route="alpha">
27+
Alpha
28+
</LinkTo>
29+
</li>
30+
31+
<li>
32+
<LinkTo @route="bravo">
33+
Bravo
34+
</LinkTo>
35+
</li>
2236
</ul>
2337
</nav>
2438
</header>
@@ -28,7 +42,11 @@ interface ApplicationRouteSignature {
2842
</main>
2943

3044
<footer>
31-
<p><a href="https://github.com/ember-a11y/ember-a11y-refocus">GitHub Repo</a></p>
32-
<p><a href="/tests">Tests (for development)</a></p>
45+
<p>
46+
<a href="https://github.com/ember-a11y/ember-a11y-refocus">GitHub Repo</a>
47+
</p>
48+
<p>
49+
<a href="/tests">Tests (for development)</a>
50+
</p>
3351
</footer>
3452
</template> satisfies TOC<ApplicationRouteSignature>;

0 commit comments

Comments
 (0)