Skip to content

Commit 94a9685

Browse files
committed
feat: add allowed roles to role query types
Closes #666
1 parent 4ad3673 commit 94a9685

File tree

3 files changed

+295
-118
lines changed

3 files changed

+295
-118
lines changed

types/__tests__/type-tests.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,9 @@ async function testByRole() {
113113
name === 'Login' && element.hasAttribute('disabled'),
114114
}) === null,
115115
)
116+
117+
// allow to query for a role that isn't included in the types
118+
console.assert(queryByRole(element, 'foo') === null)
116119
}
117120

118121
function testA11yHelper() {

types/matches.d.ts

Lines changed: 139 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,145 @@
11
export type MatcherFunction = (content: string, element: HTMLElement) => boolean
22
export type Matcher = string | RegExp | MatcherFunction
33

4+
// important to use String here
5+
// this gives us intellisense but it can also accept values
6+
// that are not included in the union types
7+
export type ByRoleMatcher = AllowedRoles | String | RegExp | MatcherFunction
8+
export type AllowedRoles =
9+
| 'alert'
10+
| 'alertdialog'
11+
| 'application'
12+
| 'article'
13+
| 'banner'
14+
| 'blockquote'
15+
| 'button'
16+
| 'caption'
17+
| 'cell'
18+
| 'checkbox'
19+
| 'code'
20+
| 'columnheader'
21+
| 'combobox'
22+
| 'complementary'
23+
| 'contentinfo'
24+
| 'definition'
25+
| 'deletion'
26+
| 'dialog'
27+
| 'directory'
28+
| 'document'
29+
| 'emphasis'
30+
| 'feed'
31+
| 'figure'
32+
| 'form'
33+
| 'generic'
34+
| 'grid'
35+
| 'gridcell'
36+
| 'group'
37+
| 'heading'
38+
| 'img'
39+
| 'insertion'
40+
| 'link'
41+
| 'list'
42+
| 'listbox'
43+
| 'listitem'
44+
| 'log'
45+
| 'main'
46+
| 'marquee'
47+
| 'math'
48+
| 'menu'
49+
| 'menubar'
50+
| 'menuitem'
51+
| 'menuitemcheckbox'
52+
| 'menuitemradio'
53+
| 'meter'
54+
| 'navigation'
55+
| 'none'
56+
| 'note'
57+
| 'option'
58+
| 'paragraph'
59+
| 'presentation'
60+
| 'progressbar'
61+
| 'radio'
62+
| 'radiogroup'
63+
| 'region'
64+
| 'row'
65+
| 'rowgroup'
66+
| 'rowheader'
67+
| 'scrollbar'
68+
| 'search'
69+
| 'searchbox'
70+
| 'separator'
71+
| 'slider'
72+
| 'spinbutton'
73+
| 'status'
74+
| 'strong'
75+
| 'subscript'
76+
| 'superscript'
77+
| 'switch'
78+
| 'tab'
79+
| 'table'
80+
| 'tablist'
81+
| 'tabpanel'
82+
| 'term'
83+
| 'textbox'
84+
| 'time'
85+
| 'timer'
86+
| 'toolbar'
87+
| 'tooltip'
88+
| 'tree'
89+
| 'treegrid'
90+
| 'treeitem'
91+
| 'command'
92+
| 'composite'
93+
| 'input'
94+
| 'landmark'
95+
| 'range'
96+
| 'roletype'
97+
| 'section'
98+
| 'sectionhead'
99+
| 'select'
100+
| 'structure'
101+
| 'widget'
102+
| 'window'
103+
| 'doc-abstract'
104+
| 'doc-acknowledgments'
105+
| 'doc-afterword'
106+
| 'doc-appendix'
107+
| 'doc-backlink'
108+
| 'doc-biblioentry'
109+
| 'doc-bibliography'
110+
| 'doc-biblioref'
111+
| 'doc-chapter'
112+
| 'doc-colophon'
113+
| 'doc-conclusion'
114+
| 'doc-cover'
115+
| 'doc-credit'
116+
| 'doc-credits'
117+
| 'doc-dedication'
118+
| 'doc-endnote'
119+
| 'doc-endnotes'
120+
| 'doc-epigraph'
121+
| 'doc-epilogue'
122+
| 'doc-errata'
123+
| 'doc-example'
124+
| 'doc-footnote'
125+
| 'doc-foreword'
126+
| 'doc-glossary'
127+
| 'doc-glossref'
128+
| 'doc-index'
129+
| 'doc-introduction'
130+
| 'doc-noteref'
131+
| 'doc-notice'
132+
| 'doc-pagebreak'
133+
| 'doc-pagelist'
134+
| 'doc-part'
135+
| 'doc-preface'
136+
| 'doc-prologue'
137+
| 'doc-pullquote'
138+
| 'doc-qna'
139+
| 'doc-subtitle'
140+
| 'doc-tip'
141+
| 'doc-toc'
142+
4143
export type NormalizerFn = (text: string) => string
5144

6145
export interface MatcherOptions {

0 commit comments

Comments
 (0)