@react-aria/live-announcer 3.1.2 → 3.3.0
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/dist/import.mjs +98 -0
- package/dist/main.js +3 -3
- package/dist/main.js.map +1 -1
- package/dist/module.js +3 -3
- package/dist/module.js.map +1 -1
- package/package.json +7 -2
- package/src/LiveAnnouncer.tsx +5 -5
package/dist/import.mjs
ADDED
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright 2020 Adobe. All rights reserved.
|
|
3
|
+
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
* you may not use this file except in compliance with the License. You may obtain a copy
|
|
5
|
+
* of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
6
|
+
*
|
|
7
|
+
* Unless required by applicable law or agreed to in writing, software distributed under
|
|
8
|
+
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
9
|
+
* OF ANY KIND, either express or implied. See the License for the specific language
|
|
10
|
+
* governing permissions and limitations under the License.
|
|
11
|
+
*/ /*
|
|
12
|
+
* Copyright 2020 Adobe. All rights reserved.
|
|
13
|
+
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
14
|
+
* you may not use this file except in compliance with the License. You may obtain a copy
|
|
15
|
+
* of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
16
|
+
*
|
|
17
|
+
* Unless required by applicable law or agreed to in writing, software distributed under
|
|
18
|
+
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
19
|
+
* OF ANY KIND, either express or implied. See the License for the specific language
|
|
20
|
+
* governing permissions and limitations under the License.
|
|
21
|
+
*/ /* Inspired by https://github.com/AlmeroSteyn/react-aria-live */ const $319e236875307eab$var$LIVEREGION_TIMEOUT_DELAY = 7000;
|
|
22
|
+
let $319e236875307eab$var$liveAnnouncer = null;
|
|
23
|
+
function $319e236875307eab$export$a9b970dcc4ae71a9(message, assertiveness = "assertive", timeout = $319e236875307eab$var$LIVEREGION_TIMEOUT_DELAY) {
|
|
24
|
+
if (!$319e236875307eab$var$liveAnnouncer) $319e236875307eab$var$liveAnnouncer = new $319e236875307eab$var$LiveAnnouncer();
|
|
25
|
+
$319e236875307eab$var$liveAnnouncer.announce(message, assertiveness, timeout);
|
|
26
|
+
}
|
|
27
|
+
function $319e236875307eab$export$d10ae4f68404609a(assertiveness) {
|
|
28
|
+
if ($319e236875307eab$var$liveAnnouncer) $319e236875307eab$var$liveAnnouncer.clear(assertiveness);
|
|
29
|
+
}
|
|
30
|
+
function $319e236875307eab$export$d8686216b8b81b2f() {
|
|
31
|
+
if ($319e236875307eab$var$liveAnnouncer) {
|
|
32
|
+
$319e236875307eab$var$liveAnnouncer.destroy();
|
|
33
|
+
$319e236875307eab$var$liveAnnouncer = null;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
// LiveAnnouncer is implemented using vanilla DOM, not React. That's because as of React 18
|
|
37
|
+
// ReactDOM.render is deprecated, and the replacement, ReactDOM.createRoot is moved into a
|
|
38
|
+
// subpath import `react-dom/client`. That makes it hard for us to support multiple React versions.
|
|
39
|
+
// As a global API, we can't use portals without introducing a breaking API change. LiveAnnouncer
|
|
40
|
+
// is simple enough to implement without React, so that's what we do here.
|
|
41
|
+
// See this discussion for more details: https://github.com/reactwg/react-18/discussions/125#discussioncomment-2382638
|
|
42
|
+
class $319e236875307eab$var$LiveAnnouncer {
|
|
43
|
+
createLog(ariaLive) {
|
|
44
|
+
let node = document.createElement("div");
|
|
45
|
+
node.setAttribute("role", "log");
|
|
46
|
+
node.setAttribute("aria-live", ariaLive);
|
|
47
|
+
node.setAttribute("aria-relevant", "additions");
|
|
48
|
+
return node;
|
|
49
|
+
}
|
|
50
|
+
destroy() {
|
|
51
|
+
if (!this.node) return;
|
|
52
|
+
document.body.removeChild(this.node);
|
|
53
|
+
this.node = null;
|
|
54
|
+
}
|
|
55
|
+
announce(message, assertiveness = "assertive", timeout = $319e236875307eab$var$LIVEREGION_TIMEOUT_DELAY) {
|
|
56
|
+
if (!this.node) return;
|
|
57
|
+
let node = document.createElement("div");
|
|
58
|
+
node.textContent = message;
|
|
59
|
+
if (assertiveness === "assertive") this.assertiveLog.appendChild(node);
|
|
60
|
+
else this.politeLog.appendChild(node);
|
|
61
|
+
if (message !== "") setTimeout(()=>{
|
|
62
|
+
node.remove();
|
|
63
|
+
}, timeout);
|
|
64
|
+
}
|
|
65
|
+
clear(assertiveness) {
|
|
66
|
+
if (!this.node) return;
|
|
67
|
+
if (!assertiveness || assertiveness === "assertive") this.assertiveLog.innerHTML = "";
|
|
68
|
+
if (!assertiveness || assertiveness === "polite") this.politeLog.innerHTML = "";
|
|
69
|
+
}
|
|
70
|
+
constructor(){
|
|
71
|
+
this.node = document.createElement("div");
|
|
72
|
+
this.node.dataset.liveAnnouncer = "true";
|
|
73
|
+
// copied from VisuallyHidden
|
|
74
|
+
Object.assign(this.node.style, {
|
|
75
|
+
border: 0,
|
|
76
|
+
clip: "rect(0 0 0 0)",
|
|
77
|
+
clipPath: "inset(50%)",
|
|
78
|
+
height: "1px",
|
|
79
|
+
margin: "-1px",
|
|
80
|
+
overflow: "hidden",
|
|
81
|
+
padding: 0,
|
|
82
|
+
position: "absolute",
|
|
83
|
+
width: "1px",
|
|
84
|
+
whiteSpace: "nowrap"
|
|
85
|
+
});
|
|
86
|
+
this.assertiveLog = this.createLog("assertive");
|
|
87
|
+
this.node.appendChild(this.assertiveLog);
|
|
88
|
+
this.politeLog = this.createLog("polite");
|
|
89
|
+
this.node.appendChild(this.politeLog);
|
|
90
|
+
document.body.prepend(this.node);
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
|
|
95
|
+
|
|
96
|
+
|
|
97
|
+
export {$319e236875307eab$export$a9b970dcc4ae71a9 as announce, $319e236875307eab$export$d10ae4f68404609a as clearAnnouncer, $319e236875307eab$export$d8686216b8b81b2f as destroyAnnouncer};
|
|
98
|
+
//# sourceMappingURL=module.js.map
|
package/dist/main.js
CHANGED
|
@@ -82,12 +82,12 @@ class $97cebfa4133ebec3$var$LiveAnnouncer {
|
|
|
82
82
|
border: 0,
|
|
83
83
|
clip: "rect(0 0 0 0)",
|
|
84
84
|
clipPath: "inset(50%)",
|
|
85
|
-
height:
|
|
86
|
-
margin: "
|
|
85
|
+
height: "1px",
|
|
86
|
+
margin: "-1px",
|
|
87
87
|
overflow: "hidden",
|
|
88
88
|
padding: 0,
|
|
89
89
|
position: "absolute",
|
|
90
|
-
width:
|
|
90
|
+
width: "1px",
|
|
91
91
|
whiteSpace: "nowrap"
|
|
92
92
|
});
|
|
93
93
|
this.assertiveLog = this.createLog("assertive");
|
package/dist/main.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":";;;;;;;AAAA;;;;;;;;;;ACAA;;;;;;;;;;CAUC,GAED,AAEA,8DAA8D,GAC9D,MAAM,iDAA2B;AAEjC,IAAI,
|
|
1
|
+
{"mappings":";;;;;;;AAAA;;;;;;;;;;ACAA;;;;;;;;;;CAUC,GAED,AAEA,8DAA8D,GAC9D,MAAM,iDAA2B;AAEjC,IAAI,sCAAsC,IAAI;AAKvC,SAAS,0CACd,OAAe,EACf,gBAA+B,WAAW,EAC1C,UAAU,8CAAwB,EAClC;IACA,IAAI,CAAC,qCACH,sCAAgB,IAAI;IAGtB,oCAAc,QAAQ,CAAC,SAAS,eAAe;AACjD;AAKO,SAAS,0CAAe,aAA4B,EAAE;IAC3D,IAAI,qCACF,oCAAc,KAAK,CAAC;AAExB;AAKO,SAAS,4CAAmB;IACjC,IAAI,qCAAe;QACjB,oCAAc,OAAO;QACrB,sCAAgB,IAAI;IACtB,CAAC;AACH;AAEA,2FAA2F;AAC3F,0FAA0F;AAC1F,mGAAmG;AACnG,iGAAiG;AACjG,0EAA0E;AAC1E,sHAAsH;AACtH,MAAM;IA+BJ,UAAU,QAAgB,EAAE;QAC1B,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ACnC,IAAI,CAAC,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,YAAY;QAEvC,IAAI,CAAC,SAAS,GAAG,IAAI,CAAC,SAAS,CAAC;QAChC,IAAI,CAAC,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,SAAS;QAEpC,SAAS,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI;IACjC;AAqDF;;CDnIC,GACD","sources":["packages/@react-aria/live-announcer/src/index.ts","packages/@react-aria/live-announcer/src/LiveAnnouncer.tsx"],"sourcesContent":["/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\nexport {announce, clearAnnouncer, destroyAnnouncer} from './LiveAnnouncer';\n","/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\ntype Assertiveness = 'assertive' | 'polite';\n\n/* Inspired by https://github.com/AlmeroSteyn/react-aria-live */\nconst LIVEREGION_TIMEOUT_DELAY = 7000;\n\nlet liveAnnouncer: LiveAnnouncer | null = null;\n\n/**\n * Announces the message using screen reader technology.\n */\nexport function announce(\n message: string,\n assertiveness: Assertiveness = 'assertive',\n timeout = LIVEREGION_TIMEOUT_DELAY\n) {\n if (!liveAnnouncer) {\n liveAnnouncer = new LiveAnnouncer();\n }\n\n liveAnnouncer.announce(message, assertiveness, timeout);\n}\n\n/**\n * Stops all queued announcements.\n */\nexport function clearAnnouncer(assertiveness: Assertiveness) {\n if (liveAnnouncer) {\n liveAnnouncer.clear(assertiveness);\n }\n}\n\n/**\n * Removes the announcer from the DOM.\n */\nexport function destroyAnnouncer() {\n if (liveAnnouncer) {\n liveAnnouncer.destroy();\n liveAnnouncer = null;\n }\n}\n\n// LiveAnnouncer is implemented using vanilla DOM, not React. That's because as of React 18\n// ReactDOM.render is deprecated, and the replacement, ReactDOM.createRoot is moved into a\n// subpath import `react-dom/client`. That makes it hard for us to support multiple React versions.\n// As a global API, we can't use portals without introducing a breaking API change. LiveAnnouncer\n// is simple enough to implement without React, so that's what we do here.\n// See this discussion for more details: https://github.com/reactwg/react-18/discussions/125#discussioncomment-2382638\nclass LiveAnnouncer {\n node: HTMLElement | null;\n assertiveLog: HTMLElement;\n politeLog: HTMLElement;\n\n constructor() {\n this.node = document.createElement('div');\n this.node.dataset.liveAnnouncer = 'true';\n // copied from VisuallyHidden\n Object.assign(this.node.style, {\n border: 0,\n clip: 'rect(0 0 0 0)',\n clipPath: 'inset(50%)',\n height: '1px',\n margin: '-1px',\n overflow: 'hidden',\n padding: 0,\n position: 'absolute',\n width: '1px',\n whiteSpace: 'nowrap'\n });\n\n this.assertiveLog = this.createLog('assertive');\n this.node.appendChild(this.assertiveLog);\n\n this.politeLog = this.createLog('polite');\n this.node.appendChild(this.politeLog);\n\n document.body.prepend(this.node);\n }\n\n createLog(ariaLive: string) {\n let node = document.createElement('div');\n node.setAttribute('role', 'log');\n node.setAttribute('aria-live', ariaLive);\n node.setAttribute('aria-relevant', 'additions');\n return node;\n }\n\n destroy() {\n if (!this.node) {\n return;\n }\n\n document.body.removeChild(this.node);\n this.node = null;\n }\n\n announce(message: string, assertiveness = 'assertive', timeout = LIVEREGION_TIMEOUT_DELAY) {\n if (!this.node) {\n return;\n }\n\n let node = document.createElement('div');\n node.textContent = message;\n\n if (assertiveness === 'assertive') {\n this.assertiveLog.appendChild(node);\n } else {\n this.politeLog.appendChild(node);\n }\n\n if (message !== '') {\n setTimeout(() => {\n node.remove();\n }, timeout);\n }\n }\n\n clear(assertiveness: Assertiveness) {\n if (!this.node) {\n return;\n }\n\n if (!assertiveness || assertiveness === 'assertive') {\n this.assertiveLog.innerHTML = '';\n }\n\n if (!assertiveness || assertiveness === 'polite') {\n this.politeLog.innerHTML = '';\n }\n }\n}\n"],"names":[],"version":3,"file":"main.js.map"}
|
package/dist/module.js
CHANGED
|
@@ -75,12 +75,12 @@ class $319e236875307eab$var$LiveAnnouncer {
|
|
|
75
75
|
border: 0,
|
|
76
76
|
clip: "rect(0 0 0 0)",
|
|
77
77
|
clipPath: "inset(50%)",
|
|
78
|
-
height:
|
|
79
|
-
margin: "
|
|
78
|
+
height: "1px",
|
|
79
|
+
margin: "-1px",
|
|
80
80
|
overflow: "hidden",
|
|
81
81
|
padding: 0,
|
|
82
82
|
position: "absolute",
|
|
83
|
-
width:
|
|
83
|
+
width: "1px",
|
|
84
84
|
whiteSpace: "nowrap"
|
|
85
85
|
});
|
|
86
86
|
this.assertiveLog = this.createLog("assertive");
|
package/dist/module.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":"AAAA;;;;;;;;;;ACAA;;;;;;;;;;CAUC,GAED,AAEA,8DAA8D,GAC9D,MAAM,iDAA2B;AAEjC,IAAI,
|
|
1
|
+
{"mappings":"AAAA;;;;;;;;;;ACAA;;;;;;;;;;CAUC,GAED,AAEA,8DAA8D,GAC9D,MAAM,iDAA2B;AAEjC,IAAI,sCAAsC,IAAI;AAKvC,SAAS,0CACd,OAAe,EACf,gBAA+B,WAAW,EAC1C,UAAU,8CAAwB,EAClC;IACA,IAAI,CAAC,qCACH,sCAAgB,IAAI;IAGtB,oCAAc,QAAQ,CAAC,SAAS,eAAe;AACjD;AAKO,SAAS,0CAAe,aAA4B,EAAE;IAC3D,IAAI,qCACF,oCA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AAG;QAClC,6BAA6B;QAC7B,OAAO,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,KAAK,EAAE;YAC7B,QAAQ;YACR,MAAM;YACN,UAAU;YACV,QAAQ;YACR,QAAQ;YACR,UAAU;YACV,SAAS;YACT,UAAU;YACV,OAAO;YACP,YAAY;QACd;QAEA,IAAI,CAAC,YAAY,GAAG,IAAI,CAAC,SAAS,CAAC;QACnC,IAAI,CAAC,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,YAAY;QAEvC,IAAI,CAAC,SAAS,GAAG,IAAI,CAAC,SAAS,CAAC;QAChC,IAAI,CAAC,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,SAAS;QAEpC,SAAS,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI;IACjC;AAqDF;;CDnIC,GACD","sources":["packages/@react-aria/live-announcer/src/index.ts","packages/@react-aria/live-announcer/src/LiveAnnouncer.tsx"],"sourcesContent":["/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\nexport {announce, clearAnnouncer, destroyAnnouncer} from './LiveAnnouncer';\n","/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\ntype Assertiveness = 'assertive' | 'polite';\n\n/* Inspired by https://github.com/AlmeroSteyn/react-aria-live */\nconst LIVEREGION_TIMEOUT_DELAY = 7000;\n\nlet liveAnnouncer: LiveAnnouncer | null = null;\n\n/**\n * Announces the message using screen reader technology.\n */\nexport function announce(\n message: string,\n assertiveness: Assertiveness = 'assertive',\n timeout = LIVEREGION_TIMEOUT_DELAY\n) {\n if (!liveAnnouncer) {\n liveAnnouncer = new LiveAnnouncer();\n }\n\n liveAnnouncer.announce(message, assertiveness, timeout);\n}\n\n/**\n * Stops all queued announcements.\n */\nexport function clearAnnouncer(assertiveness: Assertiveness) {\n if (liveAnnouncer) {\n liveAnnouncer.clear(assertiveness);\n }\n}\n\n/**\n * Removes the announcer from the DOM.\n */\nexport function destroyAnnouncer() {\n if (liveAnnouncer) {\n liveAnnouncer.destroy();\n liveAnnouncer = null;\n }\n}\n\n// LiveAnnouncer is implemented using vanilla DOM, not React. That's because as of React 18\n// ReactDOM.render is deprecated, and the replacement, ReactDOM.createRoot is moved into a\n// subpath import `react-dom/client`. That makes it hard for us to support multiple React versions.\n// As a global API, we can't use portals without introducing a breaking API change. LiveAnnouncer\n// is simple enough to implement without React, so that's what we do here.\n// See this discussion for more details: https://github.com/reactwg/react-18/discussions/125#discussioncomment-2382638\nclass LiveAnnouncer {\n node: HTMLElement | null;\n assertiveLog: HTMLElement;\n politeLog: HTMLElement;\n\n constructor() {\n this.node = document.createElement('div');\n this.node.dataset.liveAnnouncer = 'true';\n // copied from VisuallyHidden\n Object.assign(this.node.style, {\n border: 0,\n clip: 'rect(0 0 0 0)',\n clipPath: 'inset(50%)',\n height: '1px',\n margin: '-1px',\n overflow: 'hidden',\n padding: 0,\n position: 'absolute',\n width: '1px',\n whiteSpace: 'nowrap'\n });\n\n this.assertiveLog = this.createLog('assertive');\n this.node.appendChild(this.assertiveLog);\n\n this.politeLog = this.createLog('polite');\n this.node.appendChild(this.politeLog);\n\n document.body.prepend(this.node);\n }\n\n createLog(ariaLive: string) {\n let node = document.createElement('div');\n node.setAttribute('role', 'log');\n node.setAttribute('aria-live', ariaLive);\n node.setAttribute('aria-relevant', 'additions');\n return node;\n }\n\n destroy() {\n if (!this.node) {\n return;\n }\n\n document.body.removeChild(this.node);\n this.node = null;\n }\n\n announce(message: string, assertiveness = 'assertive', timeout = LIVEREGION_TIMEOUT_DELAY) {\n if (!this.node) {\n return;\n }\n\n let node = document.createElement('div');\n node.textContent = message;\n\n if (assertiveness === 'assertive') {\n this.assertiveLog.appendChild(node);\n } else {\n this.politeLog.appendChild(node);\n }\n\n if (message !== '') {\n setTimeout(() => {\n node.remove();\n }, timeout);\n }\n }\n\n clear(assertiveness: Assertiveness) {\n if (!this.node) {\n return;\n }\n\n if (!assertiveness || assertiveness === 'assertive') {\n this.assertiveLog.innerHTML = '';\n }\n\n if (!assertiveness || assertiveness === 'polite') {\n this.politeLog.innerHTML = '';\n }\n }\n}\n"],"names":[],"version":3,"file":"module.js.map"}
|
package/package.json
CHANGED
|
@@ -1,10 +1,15 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@react-aria/live-announcer",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.3.0",
|
|
4
4
|
"description": "Spectrum UI components in React",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"main": "dist/main.js",
|
|
7
7
|
"module": "dist/module.js",
|
|
8
|
+
"exports": {
|
|
9
|
+
"types": "./dist/types.d.ts",
|
|
10
|
+
"import": "./dist/import.mjs",
|
|
11
|
+
"require": "./dist/main.js"
|
|
12
|
+
},
|
|
8
13
|
"types": "dist/types.d.ts",
|
|
9
14
|
"source": "src/index.ts",
|
|
10
15
|
"files": [
|
|
@@ -22,5 +27,5 @@
|
|
|
22
27
|
"publishConfig": {
|
|
23
28
|
"access": "public"
|
|
24
29
|
},
|
|
25
|
-
"gitHead": "
|
|
30
|
+
"gitHead": "9d1ba9bd8ebcd63bf3495ade16d349bcb71795ce"
|
|
26
31
|
}
|
package/src/LiveAnnouncer.tsx
CHANGED
|
@@ -15,7 +15,7 @@ type Assertiveness = 'assertive' | 'polite';
|
|
|
15
15
|
/* Inspired by https://github.com/AlmeroSteyn/react-aria-live */
|
|
16
16
|
const LIVEREGION_TIMEOUT_DELAY = 7000;
|
|
17
17
|
|
|
18
|
-
let liveAnnouncer: LiveAnnouncer = null;
|
|
18
|
+
let liveAnnouncer: LiveAnnouncer | null = null;
|
|
19
19
|
|
|
20
20
|
/**
|
|
21
21
|
* Announces the message using screen reader technology.
|
|
@@ -58,7 +58,7 @@ export function destroyAnnouncer() {
|
|
|
58
58
|
// is simple enough to implement without React, so that's what we do here.
|
|
59
59
|
// See this discussion for more details: https://github.com/reactwg/react-18/discussions/125#discussioncomment-2382638
|
|
60
60
|
class LiveAnnouncer {
|
|
61
|
-
node: HTMLElement;
|
|
61
|
+
node: HTMLElement | null;
|
|
62
62
|
assertiveLog: HTMLElement;
|
|
63
63
|
politeLog: HTMLElement;
|
|
64
64
|
|
|
@@ -70,12 +70,12 @@ class LiveAnnouncer {
|
|
|
70
70
|
border: 0,
|
|
71
71
|
clip: 'rect(0 0 0 0)',
|
|
72
72
|
clipPath: 'inset(50%)',
|
|
73
|
-
height:
|
|
74
|
-
margin: '
|
|
73
|
+
height: '1px',
|
|
74
|
+
margin: '-1px',
|
|
75
75
|
overflow: 'hidden',
|
|
76
76
|
padding: 0,
|
|
77
77
|
position: 'absolute',
|
|
78
|
-
width:
|
|
78
|
+
width: '1px',
|
|
79
79
|
whiteSpace: 'nowrap'
|
|
80
80
|
});
|
|
81
81
|
|