@@ -3,22 +3,24 @@ import { getAccessibleValue } from "../getAccessibleValue";
33import { getItemText } from "../../getItemText" ;
44import { getNodeByIdRef } from "../../getNodeByIdRef" ;
55
6- enum State {
7- BUSY = "busy" ,
8- CHECKED = "checked" ,
9- CURRENT = "current item" ,
10- DISABLED = "disabled" ,
11- EXPANDED = "expanded" ,
12- INVALID = "invalid" ,
13- MODAL = "modal" ,
14- MULTI_SELECTABLE = "multi-selectable" ,
15- PARTIALLY_CHECKED = "partially checked" ,
16- PARTIALLY_PRESSED = "partially pressed" ,
17- PRESSED = "pressed" ,
18- READ_ONLY = "read only" ,
19- REQUIRED = "required" ,
20- SELECTED = "selected" ,
21- }
6+ type ValueOf < T > = T [ keyof T ] ;
7+
8+ const STATE = {
9+ BUSY : "busy" ,
10+ CHECKED : "checked" ,
11+ CURRENT : "current item" ,
12+ DISABLED : "disabled" ,
13+ EXPANDED : "expanded" ,
14+ INVALID : "invalid" ,
15+ MODAL : "modal" ,
16+ MULTI_SELECTABLE : "multi-selectable" ,
17+ PARTIALLY_CHECKED : "partially checked" ,
18+ PARTIALLY_PRESSED : "partially pressed" ,
19+ PRESSED : "pressed" ,
20+ READ_ONLY : "read only" ,
21+ REQUIRED : "required" ,
22+ SELECTED : "selected" ,
23+ } ;
2224
2325// https://www.w3.org/TR/wai-aria-1.2/#state_prop_def
2426const ariaPropertyToVirtualLabelMap : Record <
@@ -35,8 +37,8 @@ const ariaPropertyToVirtualLabelMap: Record<
3537 } ) ,
3638 "aria-braillelabel" : null , // Currently won't do - not implementing a braille screen reader
3739 "aria-brailleroledescription" : null , // Currently won't do - not implementing a braille screen reader
38- "aria-busy" : state ( State . BUSY ) ,
39- "aria-checked" : tristate ( State . CHECKED , State . PARTIALLY_CHECKED ) ,
40+ "aria-busy" : state ( STATE . BUSY ) ,
41+ "aria-checked" : tristate ( STATE . CHECKED , STATE . PARTIALLY_CHECKED ) ,
4042 "aria-colcount" : integer ( "column count" ) ,
4143 "aria-colindex" : integer ( "column index" ) ,
4244 "aria-colindextext" : string ( "column index" ) ,
@@ -48,16 +50,16 @@ const ariaPropertyToVirtualLabelMap: Record<
4850 location : "current location" ,
4951 date : "current date" ,
5052 time : "current time" ,
51- true : State . CURRENT ,
52- false : `not ${ State . CURRENT } ` ,
53+ true : STATE . CURRENT ,
54+ false : `not ${ STATE . CURRENT } ` ,
5355 } ) ,
5456 "aria-describedby" : null , // Handled by accessible description
5557 "aria-description" : null , // Handled by accessible description
5658 "aria-details" : idRefs ( "linked details" , "linked details" , false ) ,
57- "aria-disabled" : state ( State . DISABLED ) ,
59+ "aria-disabled" : state ( STATE . DISABLED ) ,
5860 "aria-dropeffect" : null , // Deprecated in WAI-ARIA 1.1
5961 "aria-errormessage" : errorMessageIdRefs ( "error message" , "error messages" ) ,
60- "aria-expanded" : state ( State . EXPANDED ) ,
62+ "aria-expanded" : state ( STATE . EXPANDED ) ,
6163 "aria-flowto" : idRefs ( "alternate reading order" , "alternate reading orders" ) , // Handled by virtual.perform()
6264 "aria-grabbed" : null , // Deprecated in WAI-ARIA 1.1
6365 "aria-haspopup" : token ( {
@@ -78,34 +80,34 @@ const ariaPropertyToVirtualLabelMap: Record<
7880 "aria-hidden" : null , // Excluded from accessibility tree
7981 "aria-invalid" : token ( {
8082 grammar : "grammatical error detected" ,
81- false : `not ${ State . INVALID } ` ,
83+ false : `not ${ STATE . INVALID } ` ,
8284 spelling : "spelling error detected" ,
83- true : State . INVALID ,
85+ true : STATE . INVALID ,
8486 } ) ,
8587 "aria-keyshortcuts" : string ( "key shortcuts" ) ,
8688 "aria-label" : null , // Handled by accessible name
8789 "aria-labelledby" : null , // Handled by accessible name
8890 "aria-level" : integer ( "level" ) ,
8991 "aria-live" : null , // Handled by live region logic
90- "aria-modal" : state ( State . MODAL ) ,
91- "aria-multiselectable" : state ( State . MULTI_SELECTABLE ) ,
92+ "aria-modal" : state ( STATE . MODAL ) ,
93+ "aria-multiselectable" : state ( STATE . MULTI_SELECTABLE ) ,
9294 "aria-orientation" : token ( {
9395 horizontal : "orientated horizontally" ,
9496 vertical : "orientated vertically" ,
9597 } ) ,
9698 "aria-owns" : null , // Handled by accessibility tree construction
9799 "aria-placeholder" : string ( "placeholder" ) ,
98100 "aria-posinset" : integer ( "position" ) ,
99- "aria-pressed" : tristate ( State . PRESSED , State . PARTIALLY_PRESSED ) ,
100- "aria-readonly" : state ( State . READ_ONLY ) ,
101+ "aria-pressed" : tristate ( STATE . PRESSED , STATE . PARTIALLY_PRESSED ) ,
102+ "aria-readonly" : state ( STATE . READ_ONLY ) ,
101103 "aria-relevant" : null , // Handled by live region logic
102- "aria-required" : state ( State . REQUIRED ) ,
104+ "aria-required" : state ( STATE . REQUIRED ) ,
103105 "aria-roledescription" : null , // Handled by accessible description
104106 "aria-rowcount" : integer ( "row count" ) ,
105107 "aria-rowindex" : integer ( "row index" ) ,
106108 "aria-rowindextext" : string ( "row index" ) ,
107109 "aria-rowspan" : integer ( "row span" ) ,
108- "aria-selected" : state ( State . SELECTED ) ,
110+ "aria-selected" : state ( STATE . SELECTED ) ,
109111 "aria-setsize" : integer ( "set size" ) ,
110112 "aria-sort" : token ( {
111113 ascending : "sorted in ascending order" ,
@@ -126,7 +128,7 @@ interface MapperArgs {
126128 node ?: HTMLElement ;
127129}
128130
129- function state ( stateValue : State ) {
131+ function state ( stateValue : ValueOf < typeof STATE > ) {
130132 return function stateMapper ( { attributeValue, negative } : MapperArgs ) {
131133 if ( negative ) {
132134 return attributeValue !== "false" ? `not ${ stateValue } ` : stateValue ;
@@ -198,7 +200,10 @@ function idRef(propertyName: string) {
198200 } ;
199201}
200202
201- function tristate ( stateValue : State , mixedValue : State ) {
203+ function tristate (
204+ stateValue : ValueOf < typeof STATE > ,
205+ mixedValue : ValueOf < typeof STATE >
206+ ) {
202207 return function stateMapper ( { attributeValue } : MapperArgs ) {
203208 if ( attributeValue === "mixed" ) {
204209 return mixedValue ;
0 commit comments