@cloudscape-design/components 3.0.798 → 3.0.800
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/attribute-editor/additional-info.js +2 -2
- package/attribute-editor/additional-info.js.map +1 -1
- package/attribute-editor/internal.d.ts.map +1 -1
- package/attribute-editor/internal.js +2 -2
- package/attribute-editor/internal.js.map +1 -1
- package/button/internal.d.ts.map +1 -1
- package/button/internal.js +5 -3
- package/button/internal.js.map +1 -1
- package/button-group/icon-button-item.d.ts.map +1 -1
- package/button-group/icon-button-item.js +3 -2
- package/button-group/icon-button-item.js.map +1 -1
- package/cards/index.js +3 -3
- package/cards/index.js.map +1 -1
- package/code-editor/index.d.ts.map +1 -1
- package/code-editor/index.js +2 -2
- package/code-editor/index.js.map +1 -1
- package/code-editor/status-bar.js +2 -2
- package/code-editor/status-bar.js.map +1 -1
- package/date-picker/index.js +2 -2
- package/date-picker/index.js.map +1 -1
- package/date-range-picker/calendar/header/index.js +2 -2
- package/date-range-picker/calendar/header/index.js.map +1 -1
- package/date-range-picker/calendar/index.d.ts.map +1 -1
- package/date-range-picker/calendar/index.js +2 -2
- package/date-range-picker/calendar/index.js.map +1 -1
- package/date-range-picker/dropdown.d.ts.map +1 -1
- package/date-range-picker/dropdown.js +2 -2
- package/date-range-picker/dropdown.js.map +1 -1
- package/drawer/implementation.d.ts.map +1 -1
- package/drawer/implementation.js +2 -2
- package/drawer/implementation.js.map +1 -1
- package/flashbar/flash.d.ts.map +1 -1
- package/flashbar/flash.js +2 -2
- package/flashbar/flash.js.map +1 -1
- package/form/internal.js +2 -2
- package/form/internal.js.map +1 -1
- package/form-field/internal.js +3 -3
- package/form-field/internal.js.map +1 -1
- package/help-panel/implementation.js +2 -2
- package/help-panel/implementation.js.map +1 -1
- package/internal/analytics/index.d.ts.map +1 -1
- package/internal/analytics/index.js +1 -0
- package/internal/analytics/index.js.map +1 -1
- package/internal/analytics/interfaces.d.ts +8 -0
- package/internal/analytics/interfaces.d.ts.map +1 -1
- package/internal/analytics/interfaces.js.map +1 -1
- package/internal/components/chart-plot/index.js +2 -2
- package/internal/components/chart-plot/index.js.map +1 -1
- package/internal/components/chart-status-container/index.d.ts.map +1 -1
- package/internal/components/chart-status-container/index.js +3 -1
- package/internal/components/chart-status-container/index.js.map +1 -1
- package/internal/components/dropdown-footer/index.d.ts.map +1 -1
- package/internal/components/dropdown-footer/index.js +2 -2
- package/internal/components/dropdown-footer/index.js.map +1 -1
- package/internal/components/live-region/controller.d.ts +35 -0
- package/internal/components/live-region/controller.d.ts.map +1 -0
- package/internal/components/live-region/controller.js +77 -0
- package/internal/components/live-region/controller.js.map +1 -0
- package/internal/components/live-region/index.d.ts +5 -64
- package/internal/components/live-region/index.d.ts.map +1 -1
- package/internal/components/live-region/index.js +11 -122
- package/internal/components/live-region/index.js.map +1 -1
- package/internal/components/live-region/interfaces.d.ts +34 -0
- package/internal/components/live-region/interfaces.d.ts.map +1 -0
- package/internal/components/live-region/interfaces.js +4 -0
- package/internal/components/live-region/interfaces.js.map +1 -0
- package/internal/components/live-region/internal.d.ts +31 -0
- package/internal/components/live-region/internal.d.ts.map +1 -0
- package/internal/components/live-region/internal.js +80 -0
- package/internal/components/live-region/internal.js.map +1 -0
- package/internal/components/live-region/styles.css.js +2 -2
- package/internal/components/live-region/styles.scoped.css +146 -4
- package/internal/components/live-region/styles.selectors.js +2 -2
- package/internal/context/modal-context.d.ts +7 -6
- package/internal/context/modal-context.d.ts.map +1 -1
- package/internal/context/modal-context.js +5 -1
- package/internal/context/modal-context.js.map +1 -1
- package/internal/environment.js +1 -1
- package/internal/environment.json +1 -1
- package/internal/hooks/use-modal-component-analytics/index.d.ts +3 -0
- package/internal/hooks/use-modal-component-analytics/index.d.ts.map +1 -0
- package/internal/hooks/use-modal-component-analytics/index.js +35 -0
- package/internal/hooks/use-modal-component-analytics/index.js.map +1 -0
- package/internal/hooks/use-performance-marks/index.d.ts.map +1 -1
- package/internal/hooks/use-performance-marks/index.js.map +1 -1
- package/internal/manifest.json +1 -1
- package/modal/internal.d.ts.map +1 -1
- package/modal/internal.js +40 -2
- package/modal/internal.js.map +1 -1
- package/package.json +1 -1
- package/pie-chart/pie-chart.js +2 -2
- package/pie-chart/pie-chart.js.map +1 -1
- package/progress-bar/index.js +2 -2
- package/progress-bar/index.js.map +1 -1
- package/s3-resource-selector/s3-in-context/index.d.ts.map +1 -1
- package/s3-resource-selector/s3-in-context/index.js +2 -3
- package/s3-resource-selector/s3-in-context/index.js.map +1 -1
- package/s3-resource-selector/s3-modal/basic-table.js +2 -2
- package/s3-resource-selector/s3-modal/basic-table.js.map +1 -1
- package/select/parts/filter.d.ts +1 -1
- package/spinner/internal.d.ts.map +1 -1
- package/spinner/internal.js +2 -0
- package/spinner/internal.js.map +1 -1
- package/table/body-cell/disabled-inline-editor.d.ts.map +1 -1
- package/table/body-cell/disabled-inline-editor.js +2 -1
- package/table/body-cell/disabled-inline-editor.js.map +1 -1
- package/table/body-cell/index.d.ts.map +1 -1
- package/table/body-cell/index.js +2 -2
- package/table/body-cell/index.js.map +1 -1
- package/table/body-cell/inline-editor.d.ts.map +1 -1
- package/table/body-cell/inline-editor.js +4 -4
- package/table/body-cell/inline-editor.js.map +1 -1
- package/table/internal.js +2 -2
- package/table/internal.js.map +1 -1
- package/table/no-data-cell.js +2 -2
- package/table/no-data-cell.js.map +1 -1
- package/table/progressive-loading/items-loader.js +3 -3
- package/table/progressive-loading/items-loader.js.map +1 -1
- package/tag-editor/index.js +2 -2
- package/tag-editor/index.js.map +1 -1
- package/test-utils/dom/internal/live-region.d.ts +4 -0
- package/test-utils/dom/internal/live-region.js +11 -0
- package/test-utils/dom/internal/live-region.js.map +1 -0
- package/test-utils/selectors/internal/live-region.d.ts +4 -0
- package/test-utils/selectors/internal/live-region.js +11 -0
- package/test-utils/selectors/internal/live-region.js.map +1 -0
- package/test-utils/tsconfig.tsbuildinfo +1 -1
- package/text-filter/search-results.js +2 -2
- package/text-filter/search-results.js.map +1 -1
- package/tutorial-panel/components/tutorial-list/index.js +2 -2
- package/tutorial-panel/components/tutorial-list/index.js.map +1 -1
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
import styles from './styles.css.js';
|
|
4
|
+
/**
|
|
5
|
+
* The controller that manages a single live region container. It has a timer
|
|
6
|
+
* to make sure announcements are throttled correctly. It can also make sure
|
|
7
|
+
* that a message is announced again even if it matches the previous content
|
|
8
|
+
* of the live region.
|
|
9
|
+
*
|
|
10
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/ARIA_Live_Regions
|
|
11
|
+
*/
|
|
12
|
+
export class LiveRegionController {
|
|
13
|
+
constructor(politeness, delay = LiveRegionController.defaultDelay) {
|
|
14
|
+
this.politeness = politeness;
|
|
15
|
+
this.delay = delay;
|
|
16
|
+
this._addedTerminalPeriod = false;
|
|
17
|
+
this._nextAnnouncement = '';
|
|
18
|
+
this._element = document.createElement('div');
|
|
19
|
+
this._element.className = styles.announcer;
|
|
20
|
+
this._element.setAttribute('aria-live', this.politeness);
|
|
21
|
+
this._element.setAttribute('aria-atomic', 'true');
|
|
22
|
+
this._element.setAttribute('data-awsui-live-announcer', 'true');
|
|
23
|
+
document.body.appendChild(this._element);
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Reset the state of the controller and clear any active announcements.
|
|
27
|
+
*/
|
|
28
|
+
destroy() {
|
|
29
|
+
var _a;
|
|
30
|
+
(_a = this._element) === null || _a === void 0 ? void 0 : _a.remove();
|
|
31
|
+
if (this._timeoutId !== undefined) {
|
|
32
|
+
clearTimeout(this._timeoutId);
|
|
33
|
+
this._timeoutId = undefined;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
announce({ message, forceReannounce = false }) {
|
|
37
|
+
if (!message) {
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
this._nextAnnouncement = message.trim();
|
|
41
|
+
if (this.delay === 0 || forceReannounce) {
|
|
42
|
+
// If the delay is 0, just skip the timeout shenanigans and update the
|
|
43
|
+
// element synchronously. Great for tests.
|
|
44
|
+
return this._updateElement(forceReannounce);
|
|
45
|
+
}
|
|
46
|
+
if (this._timeoutId === undefined) {
|
|
47
|
+
this._timeoutId = setTimeout(() => this._updateElement(false), this.delay * 1000);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
_updateElement(forceReannounce) {
|
|
51
|
+
if (this._nextAnnouncement !== this._lastAnnouncement) {
|
|
52
|
+
// The aria-atomic does not work properly in Voice Over, causing
|
|
53
|
+
// certain parts of the content to be ignored. To fix that,
|
|
54
|
+
// we assign the source text content as a single node.
|
|
55
|
+
this._element.textContent = this._nextAnnouncement;
|
|
56
|
+
this._addedTerminalPeriod = false;
|
|
57
|
+
}
|
|
58
|
+
else if (forceReannounce) {
|
|
59
|
+
// A (generally) safe way of forcing re-announcements is toggling the
|
|
60
|
+
// terminal period. If we only keep adding periods, it's going to be
|
|
61
|
+
// eventually interpreted as an ellipsis.
|
|
62
|
+
this._element.textContent = this._nextAnnouncement + (this._addedTerminalPeriod ? '' : '.');
|
|
63
|
+
this._addedTerminalPeriod = !this._addedTerminalPeriod;
|
|
64
|
+
}
|
|
65
|
+
// Track the announced text for deduplication.
|
|
66
|
+
this._lastAnnouncement = this._nextAnnouncement;
|
|
67
|
+
// Reset the state for the next announcement.
|
|
68
|
+
this._timeoutId = undefined;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* The default delay for announcements when no delay is explicitly provided.
|
|
73
|
+
* During internal unit testing, you can import this and explicitly set it to
|
|
74
|
+
* 0 to make the live region update the DOM without waiting for a timer.
|
|
75
|
+
*/
|
|
76
|
+
LiveRegionController.defaultDelay = 2;
|
|
77
|
+
//# sourceMappingURL=controller.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,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,CAAC;QAExC,IAAI,IAAI,CAAC,KAAK,KAAK,CAAC,IAAI,eAAe,EAAE;YACvC,sEAAsE;YACtE,0CAA0C;YAC1C,OAAO,IAAI,CAAC,cAAc,CAAC,eAAe,CAAC,CAAC;SAC7C;QAED,IAAI,IAAI,CAAC,UAAU,KAAK,SAAS,EAAE;YACjC,IAAI,CAAC,UAAU,GAAG,UAAU,CAAC,GAAG,EAAE,CAAC,IAAI,CAAC,cAAc,CAAC,KAAK,CAAC,EAAE,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC,CAAC;SACnF;IACH,CAAC;IAEO,cAAc,CAAC,eAAwB;QAC7C,IAAI,IAAI,CAAC,iBAAiB,KAAK,IAAI,CAAC,iBAAiB,EAAE;YACrD,gEAAgE;YAChE,2DAA2D;YAC3D,sDAAsD;YACtD,IAAI,CAAC,QAAQ,CAAC,WAAW,GAAG,IAAI,CAAC,iBAAiB,CAAC;YACnD,IAAI,CAAC,oBAAoB,GAAG,KAAK,CAAC;SACnC;aAAM,IAAI,eAAe,EAAE;YAC1B,qEAAqE;YACrE,oEAAoE;YACpE,yCAAyC;YACzC,IAAI,CAAC,QAAQ,CAAC,WAAW,GAAG,IAAI,CAAC,iBAAiB,GAAG,CAAC,IAAI,CAAC,oBAAoB,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC;YAC5F,IAAI,CAAC,oBAAoB,GAAG,CAAC,IAAI,CAAC,oBAAoB,CAAC;SACxD;QAED,8CAA8C;QAC9C,IAAI,CAAC,iBAAiB,GAAG,IAAI,CAAC,iBAAiB,CAAC;QAEhD,6CAA6C;QAC7C,IAAI,CAAC,UAAU,GAAG,SAAS,CAAC;IAC9B,CAAC;;AA1ED;;;;GAIG;AACW,iCAAY,GAAG,CAAC,CAAC","sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\n\nimport styles from './styles.css.js';\n\n/**\n * The controller that manages a single live region container. It has a timer\n * to make sure announcements are throttled correctly. It can also make sure\n * that a message is announced again even if it matches the previous content\n * of the live region.\n *\n * @see https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/ARIA_Live_Regions\n */\nexport class LiveRegionController {\n /**\n * The default delay for announcements when no delay is explicitly provided.\n * During internal unit testing, you can import this and explicitly set it to\n * 0 to make the live region update the DOM without waiting for a timer.\n */\n public static defaultDelay = 2;\n\n private _element: HTMLElement;\n private _timeoutId: number | undefined;\n private _lastAnnouncement: string | undefined;\n private _addedTerminalPeriod = false;\n private _nextAnnouncement = '';\n\n constructor(\n public readonly politeness: 'polite' | 'assertive',\n public readonly delay = LiveRegionController.defaultDelay\n ) {\n this._element = document.createElement('div');\n this._element.className = styles.announcer;\n this._element.setAttribute('aria-live', this.politeness);\n this._element.setAttribute('aria-atomic', 'true');\n this._element.setAttribute('data-awsui-live-announcer', 'true');\n document.body.appendChild(this._element);\n }\n\n /**\n * Reset the state of the controller and clear any active announcements.\n */\n destroy() {\n this._element?.remove();\n if (this._timeoutId !== undefined) {\n clearTimeout(this._timeoutId);\n this._timeoutId = undefined;\n }\n }\n\n announce({ message, forceReannounce = false }: { message?: string; delay?: number; forceReannounce?: boolean }) {\n if (!message) {\n return;\n }\n\n this._nextAnnouncement = message.trim();\n\n if (this.delay === 0 || forceReannounce) {\n // If the delay is 0, just skip the timeout shenanigans and update the\n // element synchronously. Great for tests.\n return this._updateElement(forceReannounce);\n }\n\n if (this._timeoutId === undefined) {\n this._timeoutId = setTimeout(() => this._updateElement(false), this.delay * 1000);\n }\n }\n\n private _updateElement(forceReannounce: boolean) {\n if (this._nextAnnouncement !== this._lastAnnouncement) {\n // The aria-atomic does not work properly in Voice Over, causing\n // certain parts of the content to be ignored. To fix that,\n // we assign the source text content as a single node.\n this._element.textContent = this._nextAnnouncement;\n this._addedTerminalPeriod = false;\n } else if (forceReannounce) {\n // A (generally) safe way of forcing re-announcements is toggling the\n // terminal period. If we only keep adding periods, it's going to be\n // eventually interpreted as an ellipsis.\n this._element.textContent = this._nextAnnouncement + (this._addedTerminalPeriod ? '' : '.');\n this._addedTerminalPeriod = !this._addedTerminalPeriod;\n }\n\n // Track the announced text for deduplication.\n this._lastAnnouncement = this._nextAnnouncement;\n\n // Reset the state for the next announcement.\n this._timeoutId = undefined;\n }\n}\n"]}
|
|
@@ -1,65 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
import {
|
|
3
|
-
export
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
visible?: boolean;
|
|
7
|
-
tagName?: 'span' | 'div';
|
|
8
|
-
id?: string;
|
|
9
|
-
/**
|
|
10
|
-
* Use a list of strings and/or existing DOM elements for building the
|
|
11
|
-
* announcement text. This avoids rendering separate content just for this
|
|
12
|
-
* LiveRegion.
|
|
13
|
-
*
|
|
14
|
-
* If this property is set, the `children` will be ignored.
|
|
15
|
-
*/
|
|
16
|
-
source?: Array<string | React.RefObject<HTMLElement> | undefined>;
|
|
17
|
-
}
|
|
18
|
-
/**
|
|
19
|
-
* The live region is hidden in the layout, but visible for screen readers.
|
|
20
|
-
* It's purpose it to announce changes e.g. when custom navigation logic is used.
|
|
21
|
-
*
|
|
22
|
-
* The way live region works differently in different browsers and screen readers and
|
|
23
|
-
* it is recommended to manually test every new implementation.
|
|
24
|
-
*
|
|
25
|
-
* If you notice there are different words being merged together,
|
|
26
|
-
* check if there are text nodes not being wrapped in elements, like:
|
|
27
|
-
* ```
|
|
28
|
-
* <LiveRegion>
|
|
29
|
-
* {title}
|
|
30
|
-
* <span><Details /></span>
|
|
31
|
-
* </LiveRegion>
|
|
32
|
-
* ```
|
|
33
|
-
*
|
|
34
|
-
* To fix, wrap "title" in an element:
|
|
35
|
-
* ```
|
|
36
|
-
* <LiveRegion>
|
|
37
|
-
* <span>{title}</span>
|
|
38
|
-
* <span><Details /></span>
|
|
39
|
-
* </LiveRegion>
|
|
40
|
-
* ```
|
|
41
|
-
*
|
|
42
|
-
* Or create a single text node if possible:
|
|
43
|
-
* ```
|
|
44
|
-
* <LiveRegion>
|
|
45
|
-
* {`${title} ${details}`}
|
|
46
|
-
* </LiveRegion>
|
|
47
|
-
* ```
|
|
48
|
-
*
|
|
49
|
-
* The live region is always atomic, because non-atomic regions can be treated by screen readers
|
|
50
|
-
* differently and produce unexpected results. To imitate non-atomic announcements simply use
|
|
51
|
-
* multiple live regions:
|
|
52
|
-
* ```
|
|
53
|
-
* <>
|
|
54
|
-
* <LiveRegion>{title}</LiveRegion>
|
|
55
|
-
* <LiveRegion><Details /></LiveRegion>
|
|
56
|
-
* </>
|
|
57
|
-
* ```
|
|
58
|
-
*
|
|
59
|
-
* If you place interactive content inside the LiveRegion, the content will still be
|
|
60
|
-
* interactive (e.g. as a tab stop). Consider using the `source` property instead.
|
|
61
|
-
*/
|
|
62
|
-
declare const _default: React.MemoExoticComponent<typeof LiveRegion>;
|
|
63
|
-
export default _default;
|
|
64
|
-
declare function LiveRegion({ assertive, delay, visible, tagName: TagName, children, id, source, ...restProps }: LiveRegionProps): JSX.Element;
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import { LiveRegionProps } from './interfaces';
|
|
3
|
+
export { LiveRegionProps };
|
|
4
|
+
declare function LiveRegion({ assertive, hidden, tagName, ...restProps }: LiveRegionProps): JSX.Element;
|
|
5
|
+
export default LiveRegion;
|
|
65
6
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/internal/components/live-region/index.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/internal/components/live-region/index.tsx"],"names":[],"mappings":";AAOA,OAAO,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AAG/C,OAAO,EAAE,eAAe,EAAE,CAAC;AAE3B,iBAAS,UAAU,CAAC,EAAE,SAAiB,EAAE,MAAc,EAAE,OAAe,EAAE,GAAG,SAAS,EAAE,EAAE,eAAe,eAcxG;AAID,eAAe,UAAU,CAAC"}
|
|
@@ -1,128 +1,17 @@
|
|
|
1
1
|
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
import { __rest } from "tslib";
|
|
4
|
-
|
|
5
|
-
import
|
|
6
|
-
import
|
|
7
|
-
import
|
|
8
|
-
import styles from './styles.css.js';
|
|
9
|
-
/**
|
|
10
|
-
* The live region is hidden in the layout, but visible for screen readers.
|
|
11
|
-
* It's purpose it to announce changes e.g. when custom navigation logic is used.
|
|
12
|
-
*
|
|
13
|
-
* The way live region works differently in different browsers and screen readers and
|
|
14
|
-
* it is recommended to manually test every new implementation.
|
|
15
|
-
*
|
|
16
|
-
* If you notice there are different words being merged together,
|
|
17
|
-
* check if there are text nodes not being wrapped in elements, like:
|
|
18
|
-
* ```
|
|
19
|
-
* <LiveRegion>
|
|
20
|
-
* {title}
|
|
21
|
-
* <span><Details /></span>
|
|
22
|
-
* </LiveRegion>
|
|
23
|
-
* ```
|
|
24
|
-
*
|
|
25
|
-
* To fix, wrap "title" in an element:
|
|
26
|
-
* ```
|
|
27
|
-
* <LiveRegion>
|
|
28
|
-
* <span>{title}</span>
|
|
29
|
-
* <span><Details /></span>
|
|
30
|
-
* </LiveRegion>
|
|
31
|
-
* ```
|
|
32
|
-
*
|
|
33
|
-
* Or create a single text node if possible:
|
|
34
|
-
* ```
|
|
35
|
-
* <LiveRegion>
|
|
36
|
-
* {`${title} ${details}`}
|
|
37
|
-
* </LiveRegion>
|
|
38
|
-
* ```
|
|
39
|
-
*
|
|
40
|
-
* The live region is always atomic, because non-atomic regions can be treated by screen readers
|
|
41
|
-
* differently and produce unexpected results. To imitate non-atomic announcements simply use
|
|
42
|
-
* multiple live regions:
|
|
43
|
-
* ```
|
|
44
|
-
* <>
|
|
45
|
-
* <LiveRegion>{title}</LiveRegion>
|
|
46
|
-
* <LiveRegion><Details /></LiveRegion>
|
|
47
|
-
* </>
|
|
48
|
-
* ```
|
|
49
|
-
*
|
|
50
|
-
* If you place interactive content inside the LiveRegion, the content will still be
|
|
51
|
-
* interactive (e.g. as a tab stop). Consider using the `source` property instead.
|
|
52
|
-
*/
|
|
53
|
-
export default memo(LiveRegion);
|
|
4
|
+
import React from 'react';
|
|
5
|
+
// import useBaseComponent from '../../hooks/use-base-component';
|
|
6
|
+
import { applyDisplayName } from '../../utils/apply-display-name';
|
|
7
|
+
import InternalLiveRegion from './internal';
|
|
54
8
|
function LiveRegion(_a) {
|
|
55
|
-
var { assertive = false,
|
|
56
|
-
|
|
57
|
-
const
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
issue many announcements for the same logical event (See https://github.com/nvaccess/nvda/issues/7996).
|
|
61
|
-
|
|
62
|
-
The code below imitates a debouncing, scheduling a callback every time new React state
|
|
63
|
-
update is detected. When a callback resolves, it copies content from a muted element
|
|
64
|
-
to the live region, which is recognized by screen readers as an update.
|
|
65
|
-
|
|
66
|
-
If the use case requires no announcement to be ignored, use delay = 0, but ensure it
|
|
67
|
-
does not impact the performance. If it does, prefer using a string as children prop.
|
|
68
|
-
*/
|
|
69
|
-
useEffect(() => {
|
|
70
|
-
function getSourceContent() {
|
|
71
|
-
if (source) {
|
|
72
|
-
return source
|
|
73
|
-
.map(item => {
|
|
74
|
-
if (!item) {
|
|
75
|
-
return undefined;
|
|
76
|
-
}
|
|
77
|
-
if (typeof item === 'string') {
|
|
78
|
-
return item;
|
|
79
|
-
}
|
|
80
|
-
if (item.current) {
|
|
81
|
-
return extractInnerText(item.current);
|
|
82
|
-
}
|
|
83
|
-
})
|
|
84
|
-
.filter(Boolean)
|
|
85
|
-
.join(' ');
|
|
86
|
-
}
|
|
87
|
-
if (sourceRef.current) {
|
|
88
|
-
return extractInnerText(sourceRef.current);
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
function updateLiveRegion() {
|
|
92
|
-
const sourceContent = getSourceContent();
|
|
93
|
-
if (targetRef.current && sourceContent) {
|
|
94
|
-
const targetContent = extractInnerText(targetRef.current);
|
|
95
|
-
if (targetContent !== sourceContent) {
|
|
96
|
-
// The aria-atomic does not work properly in Voice Over, causing
|
|
97
|
-
// certain parts of the content to be ignored. To fix that,
|
|
98
|
-
// we assign the source text content as a single node.
|
|
99
|
-
targetRef.current.innerText = sourceContent;
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
let timeoutId;
|
|
104
|
-
if (delay) {
|
|
105
|
-
timeoutId = setTimeout(updateLiveRegion, delay);
|
|
106
|
-
}
|
|
107
|
-
else {
|
|
108
|
-
updateLiveRegion();
|
|
109
|
-
}
|
|
110
|
-
return () => {
|
|
111
|
-
if (timeoutId) {
|
|
112
|
-
clearTimeout(timeoutId);
|
|
113
|
-
}
|
|
114
|
-
};
|
|
115
|
-
});
|
|
116
|
-
return (React.createElement(React.Fragment, null,
|
|
117
|
-
visible && !source && (React.createElement(TagName, { ref: sourceRef, id: id, className: styles.source }, children)),
|
|
118
|
-
React.createElement(ScreenreaderOnly, Object.assign({}, restProps, { className: clsx(styles.root, restProps.className) }),
|
|
119
|
-
!visible && !source && (React.createElement(TagName, { ref: sourceRef, "aria-hidden": "true", className: styles.source }, children)),
|
|
120
|
-
React.createElement("span", { ref: targetRef, "aria-atomic": "true", "aria-live": assertive ? 'assertive' : 'polite' }))));
|
|
121
|
-
}
|
|
122
|
-
// This only extracts text content from the node including all its children which is enough for now.
|
|
123
|
-
// To make it more powerful, it is possible to create a more sophisticated extractor with respect to
|
|
124
|
-
// ARIA properties to ignore aria-hidden nodes and read ARIA labels from the live content.
|
|
125
|
-
function extractInnerText(node) {
|
|
126
|
-
return (node.innerText || '').replace(/\s+/g, ' ').trim();
|
|
9
|
+
var { assertive = false, hidden = false, tagName = 'div' } = _a, restProps = __rest(_a, ["assertive", "hidden", "tagName"]);
|
|
10
|
+
// TODO: Switch this out when moving this component out of internal
|
|
11
|
+
// const baseComponentProps = useBaseComponent('LiveRegion');
|
|
12
|
+
const baseComponentProps = { __internalRootRef: React.useRef() };
|
|
13
|
+
return (React.createElement(InternalLiveRegion, Object.assign({ assertive: assertive, hidden: hidden, tagName: tagName }, baseComponentProps, restProps)));
|
|
127
14
|
}
|
|
15
|
+
applyDisplayName(LiveRegion, 'LiveRegion');
|
|
16
|
+
export default LiveRegion;
|
|
128
17
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../src/internal/components/live-region/index.tsx"],"names":[],"mappings":"AAAA,qEAAqE;AACrE,sCAAsC;;AAEtC,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../src/internal/components/live-region/index.tsx"],"names":[],"mappings":"AAAA,qEAAqE;AACrE,sCAAsC;;AAEtC,OAAO,KAAK,MAAM,OAAO,CAAC;AAE1B,iEAAiE;AACjE,OAAO,EAAE,gBAAgB,EAAE,MAAM,gCAAgC,CAAC;AAElE,OAAO,kBAAkB,MAAM,YAAY,CAAC;AAI5C,SAAS,UAAU,CAAC,EAAqF;QAArF,EAAE,SAAS,GAAG,KAAK,EAAE,MAAM,GAAG,KAAK,EAAE,OAAO,GAAG,KAAK,OAAiC,EAA5B,SAAS,cAAlE,kCAAoE,CAAF;IACpF,mEAAmE;IACnE,6DAA6D;IAC7D,MAAM,kBAAkB,GAAG,EAAE,iBAAiB,EAAE,KAAK,CAAC,MAAM,EAAE,EAAE,CAAC;IAEjE,OAAO,CACL,oBAAC,kBAAkB,kBACjB,SAAS,EAAE,SAAS,EACpB,MAAM,EAAE,MAAM,EACd,OAAO,EAAE,OAAO,IACZ,kBAAkB,EAClB,SAAS,EACb,CACH,CAAC;AACJ,CAAC;AAED,gBAAgB,CAAC,UAAU,EAAE,YAAY,CAAC,CAAC;AAE3C,eAAe,UAAU,CAAC","sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\n\nimport React from 'react';\n\n// import useBaseComponent from '../../hooks/use-base-component';\nimport { applyDisplayName } from '../../utils/apply-display-name';\nimport { LiveRegionProps } from './interfaces';\nimport InternalLiveRegion from './internal';\n\nexport { LiveRegionProps };\n\nfunction LiveRegion({ assertive = false, hidden = false, tagName = 'div', ...restProps }: LiveRegionProps) {\n // TODO: Switch this out when moving this component out of internal\n // const baseComponentProps = useBaseComponent('LiveRegion');\n const baseComponentProps = { __internalRootRef: React.useRef() };\n\n return (\n <InternalLiveRegion\n assertive={assertive}\n hidden={hidden}\n tagName={tagName}\n {...baseComponentProps}\n {...restProps}\n />\n );\n}\n\napplyDisplayName(LiveRegion, 'LiveRegion');\n\nexport default LiveRegion;\n"]}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import { BaseComponentProps } from '../../base-component';
|
|
3
|
+
export interface LiveRegionProps extends BaseComponentProps {
|
|
4
|
+
/**
|
|
5
|
+
* The string for the aria-live announcement text. When this content
|
|
6
|
+
* changes, the text will be re-announced to assistive technologies. If this
|
|
7
|
+
* property is provided, it will be used for the live announcement instead of
|
|
8
|
+
* the `children` slot.
|
|
9
|
+
*/
|
|
10
|
+
message?: string;
|
|
11
|
+
/**
|
|
12
|
+
* Whether the announcements should be made using assertive aria-live.
|
|
13
|
+
* Assertive announcements interrupt the user's action, so they should only
|
|
14
|
+
* be used when absolutely necessary.
|
|
15
|
+
*/
|
|
16
|
+
assertive?: boolean;
|
|
17
|
+
/**
|
|
18
|
+
* The tag name to use for the wrapper around the `children` slot.
|
|
19
|
+
*/
|
|
20
|
+
tagName?: LiveRegionProps.TagName;
|
|
21
|
+
/**
|
|
22
|
+
* Defines whether to visually hide the contents of the `children` slot.
|
|
23
|
+
*/
|
|
24
|
+
hidden?: boolean;
|
|
25
|
+
/**
|
|
26
|
+
* Use the rendered content as the source for the announcement text.
|
|
27
|
+
* Prefer `message` if announcement text can be provided as a string.
|
|
28
|
+
*/
|
|
29
|
+
children?: React.ReactNode;
|
|
30
|
+
}
|
|
31
|
+
export declare namespace LiveRegionProps {
|
|
32
|
+
type TagName = 'span' | 'div';
|
|
33
|
+
}
|
|
34
|
+
//# sourceMappingURL=interfaces.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"interfaces.d.ts","sourceRoot":"","sources":["../../../../../src/internal/components/live-region/interfaces.ts"],"names":[],"mappings":";AAGA,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAE1D,MAAM,WAAW,eAAgB,SAAQ,kBAAkB;IACzD;;;;;OAKG;IACH,OAAO,CAAC,EAAE,MAAM,CAAC;IAEjB;;;;OAIG;IACH,SAAS,CAAC,EAAE,OAAO,CAAC;IAEpB;;OAEG;IACH,OAAO,CAAC,EAAE,eAAe,CAAC,OAAO,CAAC;IAElC;;OAEG;IACH,MAAM,CAAC,EAAE,OAAO,CAAC;IAEjB;;;OAGG;IACH,QAAQ,CAAC,EAAE,KAAK,CAAC,SAAS,CAAC;CAC5B;AAED,yBAAiB,eAAe,CAAC;IAC/B,KAAY,OAAO,GAAG,MAAM,GAAG,KAAK,CAAC;CACtC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"interfaces.js","sourceRoot":"","sources":["../../../../../src/internal/components/live-region/interfaces.ts"],"names":[],"mappings":"AAAA,qEAAqE;AACrE,sCAAsC","sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\n\nimport { BaseComponentProps } from '../../base-component';\n\nexport interface LiveRegionProps extends BaseComponentProps {\n /**\n * The string for the aria-live announcement text. When this content\n * changes, the text will be re-announced to assistive technologies. If this\n * property is provided, it will be used for the live announcement instead of\n * the `children` slot.\n */\n message?: string;\n\n /**\n * Whether the announcements should be made using assertive aria-live.\n * Assertive announcements interrupt the user's action, so they should only\n * be used when absolutely necessary.\n */\n assertive?: boolean;\n\n /**\n * The tag name to use for the wrapper around the `children` slot.\n */\n tagName?: LiveRegionProps.TagName;\n\n /**\n * Defines whether to visually hide the contents of the `children` slot.\n */\n hidden?: boolean;\n\n /**\n * Use the rendered content as the source for the announcement text.\n * Prefer `message` if announcement text can be provided as a string.\n */\n children?: React.ReactNode;\n}\n\nexport namespace LiveRegionProps {\n export type TagName = 'span' | 'div';\n}\n"]}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { InternalBaseComponentProps } from '../../hooks/use-base-component';
|
|
3
|
+
import { LiveRegionProps } from './interfaces';
|
|
4
|
+
export interface InternalLiveRegionProps extends InternalBaseComponentProps, LiveRegionProps {
|
|
5
|
+
/**
|
|
6
|
+
* The delay between each announcement from this live region. You should
|
|
7
|
+
* leave this set to the default unless this live region is commonly
|
|
8
|
+
* interrupted by other actions (like text entry in text filtering).
|
|
9
|
+
*/
|
|
10
|
+
delay?: number;
|
|
11
|
+
/**
|
|
12
|
+
* Use a list of strings and/or refs to existing elements for building the
|
|
13
|
+
* announcement text. If this property is set, `children` and `message` will
|
|
14
|
+
* be ignored.
|
|
15
|
+
*/
|
|
16
|
+
sources?: ReadonlyArray<string | React.RefObject<HTMLElement> | undefined>;
|
|
17
|
+
}
|
|
18
|
+
export interface InternalLiveRegionRef {
|
|
19
|
+
/**
|
|
20
|
+
* Force the live region to announce the message, even if it's the same as
|
|
21
|
+
* the previously announced message.
|
|
22
|
+
*
|
|
23
|
+
* This is useful when making status updates after a change (e.g. filtering)
|
|
24
|
+
* where the new message might be the same as the old one, but the announcement
|
|
25
|
+
* also serves to tell screen reader users that the action was performed.
|
|
26
|
+
*/
|
|
27
|
+
reannounce(): void;
|
|
28
|
+
}
|
|
29
|
+
declare const _default: React.ForwardRefExoticComponent<InternalLiveRegionProps & React.RefAttributes<InternalLiveRegionRef>>;
|
|
30
|
+
export default _default;
|
|
31
|
+
//# sourceMappingURL=internal.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"internal.d.ts","sourceRoot":"","sources":["../../../../../src/internal/components/live-region/internal.tsx"],"names":[],"mappings":"AAGA,OAAO,KAAiD,MAAM,OAAO,CAAC;AAItE,OAAO,EAAE,0BAA0B,EAAE,MAAM,gCAAgC,CAAC;AAG5E,OAAO,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AAI/C,MAAM,WAAW,uBAAwB,SAAQ,0BAA0B,EAAE,eAAe;IAC1F;;;;OAIG;IACH,KAAK,CAAC,EAAE,MAAM,CAAC;IAEf;;;;OAIG;IACH,OAAO,CAAC,EAAE,aAAa,CAAC,MAAM,GAAG,KAAK,CAAC,SAAS,CAAC,WAAW,CAAC,GAAG,SAAS,CAAC,CAAC;CAC5E;AAED,MAAM,WAAW,qBAAqB;IACpC;;;;;;;OAOG;IACH,UAAU,IAAI,IAAI,CAAC;CACpB;;AAED,wBAsEG"}
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
import { __rest } from "tslib";
|
|
4
|
+
import React, { useEffect, useImperativeHandle, useRef } from 'react';
|
|
5
|
+
import clsx from 'clsx';
|
|
6
|
+
import { getBaseProps } from '../../base-component';
|
|
7
|
+
import { useMergeRefs } from '../../hooks/use-merge-refs';
|
|
8
|
+
import { LiveRegionController } from './controller';
|
|
9
|
+
import styles from './styles.css.js';
|
|
10
|
+
export default React.forwardRef(function InternalLiveRegion(_a, ref) {
|
|
11
|
+
var { assertive = false, hidden = false, tagName: TagName = 'div', delay, sources, message, children, __internalRootRef, className } = _a, restProps = __rest(_a, ["assertive", "hidden", "tagName", "delay", "sources", "message", "children", "__internalRootRef", "className"]);
|
|
12
|
+
const baseProps = getBaseProps(restProps);
|
|
13
|
+
const childrenRef = useRef(null);
|
|
14
|
+
const mergedRef = useMergeRefs(childrenRef, __internalRootRef);
|
|
15
|
+
useEffect(() => {
|
|
16
|
+
// We have to do this because `inert` isn't properly supported until
|
|
17
|
+
// React 19 and this seems much more maintainable than version detection.
|
|
18
|
+
// `inert` is better than `hidden` because it also blocks pointer and
|
|
19
|
+
// focus events as well as hiding the contents from screen readers.
|
|
20
|
+
// https://github.com/facebook/react/issues/17157
|
|
21
|
+
if (childrenRef.current) {
|
|
22
|
+
childrenRef.current.inert = hidden;
|
|
23
|
+
}
|
|
24
|
+
}, [hidden]);
|
|
25
|
+
// Initialize the live region controller inside an effect. We have to do this
|
|
26
|
+
// because the controller depends on DOM elements, which aren't available on the
|
|
27
|
+
// server.
|
|
28
|
+
const liveRegionControllerRef = useRef();
|
|
29
|
+
useEffect(() => {
|
|
30
|
+
const liveRegionController = new LiveRegionController(assertive ? 'assertive' : 'polite');
|
|
31
|
+
liveRegionControllerRef.current = liveRegionController;
|
|
32
|
+
return () => {
|
|
33
|
+
liveRegionController.destroy();
|
|
34
|
+
liveRegionControllerRef.current = undefined;
|
|
35
|
+
};
|
|
36
|
+
}, [assertive]);
|
|
37
|
+
const getContent = () => {
|
|
38
|
+
return sources
|
|
39
|
+
? getSourceContent(sources)
|
|
40
|
+
: message
|
|
41
|
+
? message
|
|
42
|
+
: childrenRef.current
|
|
43
|
+
? extractTextContent(childrenRef.current)
|
|
44
|
+
: undefined;
|
|
45
|
+
};
|
|
46
|
+
// Call the controller on every render. The controller will deduplicate the
|
|
47
|
+
// message against the previous announcement internally.
|
|
48
|
+
useEffect(() => {
|
|
49
|
+
var _a;
|
|
50
|
+
(_a = liveRegionControllerRef.current) === null || _a === void 0 ? void 0 : _a.announce({ message: getContent(), delay });
|
|
51
|
+
});
|
|
52
|
+
useImperativeHandle(ref, () => ({
|
|
53
|
+
reannounce() {
|
|
54
|
+
var _a;
|
|
55
|
+
(_a = liveRegionControllerRef.current) === null || _a === void 0 ? void 0 : _a.announce({ message: getContent(), delay, forceReannounce: true });
|
|
56
|
+
},
|
|
57
|
+
}));
|
|
58
|
+
return (React.createElement(TagName, Object.assign({ ref: mergedRef }, baseProps, { className: clsx(styles.root, className), hidden: hidden }), children));
|
|
59
|
+
});
|
|
60
|
+
function extractTextContent(node) {
|
|
61
|
+
// We use the text content of the node as the announcement text.
|
|
62
|
+
// This only extracts text content from the node including all its children which is enough for now.
|
|
63
|
+
// To make it more powerful, it is possible to create a more sophisticated extractor with respect to
|
|
64
|
+
// ARIA properties to ignore aria-hidden nodes and read ARIA labels from the live content.
|
|
65
|
+
return (node.textContent || '').replace(/\s+/g, ' ').trim();
|
|
66
|
+
}
|
|
67
|
+
function getSourceContent(source) {
|
|
68
|
+
return source
|
|
69
|
+
.map(item => {
|
|
70
|
+
if (!item || typeof item === 'string') {
|
|
71
|
+
return item;
|
|
72
|
+
}
|
|
73
|
+
if (item.current) {
|
|
74
|
+
return extractTextContent(item.current);
|
|
75
|
+
}
|
|
76
|
+
})
|
|
77
|
+
.filter(Boolean)
|
|
78
|
+
.join(' ');
|
|
79
|
+
}
|
|
80
|
+
//# sourceMappingURL=internal.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"internal.js","sourceRoot":"","sources":["../../../../../src/internal/components/live-region/internal.tsx"],"names":[],"mappings":"AAAA,qEAAqE;AACrE,sCAAsC;;AAEtC,OAAO,KAAK,EAAE,EAAE,SAAS,EAAE,mBAAmB,EAAE,MAAM,EAAE,MAAM,OAAO,CAAC;AACtE,OAAO,IAAI,MAAM,MAAM,CAAC;AAExB,OAAO,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AAEpD,OAAO,EAAE,YAAY,EAAE,MAAM,4BAA4B,CAAC;AAC1D,OAAO,EAAE,oBAAoB,EAAE,MAAM,cAAc,CAAC;AAGpD,OAAO,MAAM,MAAM,iBAAiB,CAAC;AA8BrC,eAAe,KAAK,CAAC,UAAU,CAAC,SAAS,kBAAkB,CACzD,EAW0B,EAC1B,GAAqC;QAZrC,EACE,SAAS,GAAG,KAAK,EACjB,MAAM,GAAG,KAAK,EACd,OAAO,EAAE,OAAO,GAAG,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AAC,OAAO,CAAC;SACf,IAAI,CAAC,GAAG,CAAC,CAAC;AACf,CAAC","sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\n\nimport React, { useEffect, useImperativeHandle, useRef } from 'react';\nimport clsx from 'clsx';\n\nimport { getBaseProps } from '../../base-component';\nimport { InternalBaseComponentProps } from '../../hooks/use-base-component';\nimport { useMergeRefs } from '../../hooks/use-merge-refs';\nimport { LiveRegionController } from './controller';\nimport { LiveRegionProps } from './interfaces';\n\nimport styles from './styles.css.js';\n\nexport interface InternalLiveRegionProps extends InternalBaseComponentProps, LiveRegionProps {\n /**\n * The delay between each announcement from this live region. You should\n * leave this set to the default unless this live region is commonly\n * interrupted by other actions (like text entry in text filtering).\n */\n delay?: number;\n\n /**\n * Use a list of strings and/or refs to existing elements for building the\n * announcement text. If this property is set, `children` and `message` will\n * be ignored.\n */\n sources?: ReadonlyArray<string | React.RefObject<HTMLElement> | undefined>;\n}\n\nexport interface InternalLiveRegionRef {\n /**\n * Force the live region to announce the message, even if it's the same as\n * the previously announced message.\n *\n * This is useful when making status updates after a change (e.g. filtering)\n * where the new message might be the same as the old one, but the announcement\n * also serves to tell screen reader users that the action was performed.\n */\n reannounce(): void;\n}\n\nexport default React.forwardRef(function InternalLiveRegion(\n {\n assertive = false,\n hidden = false,\n tagName: TagName = 'div',\n delay,\n sources,\n message,\n children,\n __internalRootRef,\n className,\n ...restProps\n }: InternalLiveRegionProps,\n ref: React.Ref<InternalLiveRegionRef>\n) {\n const baseProps = getBaseProps(restProps);\n const childrenRef = useRef<HTMLSpanElement & HTMLDivElement>(null);\n const mergedRef = useMergeRefs(childrenRef, __internalRootRef);\n\n useEffect(() => {\n // We have to do this because `inert` isn't properly supported until\n // React 19 and this seems much more maintainable than version detection.\n // `inert` is better than `hidden` because it also blocks pointer and\n // focus events as well as hiding the contents from screen readers.\n // https://github.com/facebook/react/issues/17157\n if (childrenRef.current) {\n childrenRef.current.inert = hidden;\n }\n }, [hidden]);\n\n // Initialize the live region controller inside an effect. We have to do this\n // because the controller depends on DOM elements, which aren't available on the\n // server.\n const liveRegionControllerRef = useRef<LiveRegionController | undefined>();\n useEffect(() => {\n const liveRegionController = new LiveRegionController(assertive ? 'assertive' : 'polite');\n liveRegionControllerRef.current = liveRegionController;\n return () => {\n liveRegionController.destroy();\n liveRegionControllerRef.current = undefined;\n };\n }, [assertive]);\n\n const getContent = () => {\n return sources\n ? getSourceContent(sources)\n : message\n ? message\n : childrenRef.current\n ? extractTextContent(childrenRef.current)\n : undefined;\n };\n\n // Call the controller on every render. The controller will deduplicate the\n // message against the previous announcement internally.\n useEffect(() => {\n liveRegionControllerRef.current?.announce({ message: getContent(), delay });\n });\n\n useImperativeHandle(ref, () => ({\n reannounce() {\n liveRegionControllerRef.current?.announce({ message: getContent(), delay, forceReannounce: true });\n },\n }));\n\n return (\n <TagName ref={mergedRef} {...baseProps} className={clsx(styles.root, className)} hidden={hidden}>\n {children}\n </TagName>\n );\n});\n\nfunction extractTextContent(node: HTMLElement): string {\n // We use the text content of the node as the announcement text.\n // This only extracts text content from the node including all its children which is enough for now.\n // To make it more powerful, it is possible to create a more sophisticated extractor with respect to\n // ARIA properties to ignore aria-hidden nodes and read ARIA labels from the live content.\n return (node.textContent || '').replace(/\\s+/g, ' ').trim();\n}\n\nfunction getSourceContent(source: ReadonlyArray<string | React.RefObject<HTMLElement> | undefined>): string {\n return source\n .map(item => {\n if (!item || typeof item === 'string') {\n return item;\n }\n if (item.current) {\n return extractTextContent(item.current);\n }\n })\n .filter(Boolean)\n .join(' ');\n}\n"]}
|