@microsoft/omnichannel-chat-components 1.1.17-main.f21df63 → 1.1.17-main.fba10aa
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/lib/cjs/components/chatbutton/ChatButton.blankAnnouncements.a11y.spec.js +162 -0
- package/lib/cjs/components/chatbutton/ChatButton.browseMode.a11y.spec.js +236 -0
- package/lib/cjs/components/chatbutton/ChatButton.browseMode.unfixed.a11y.spec.js +115 -0
- package/lib/cjs/components/chatbutton/ChatButton.js +52 -16
- package/lib/esm/components/chatbutton/ChatButton.blankAnnouncements.a11y.spec.js +159 -0
- package/lib/esm/components/chatbutton/ChatButton.browseMode.a11y.spec.js +233 -0
- package/lib/esm/components/chatbutton/ChatButton.browseMode.unfixed.a11y.spec.js +111 -0
- package/lib/esm/components/chatbutton/ChatButton.js +53 -16
- package/lib/types/components/chatbutton/ChatButton.blankAnnouncements.a11y.spec.d.ts +1 -0
- package/lib/types/components/chatbutton/ChatButton.browseMode.a11y.spec.d.ts +1 -0
- package/lib/types/components/chatbutton/ChatButton.browseMode.unfixed.a11y.spec.d.ts +1 -0
- package/package.json +19 -1
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
require("@testing-library/jest-dom/extend-expect");
|
|
4
|
+
var _react = require("@testing-library/react");
|
|
5
|
+
var _BroadcastService = require("../../services/BroadcastService");
|
|
6
|
+
var _ChatButton = _interopRequireDefault(require("./ChatButton"));
|
|
7
|
+
var _LoadingPane = _interopRequireDefault(require("../loadingpane/LoadingPane"));
|
|
8
|
+
var _react2 = _interopRequireDefault(require("react"));
|
|
9
|
+
var _defaultChatButtonProps = require("./common/defaultProps/defaultChatButtonProps");
|
|
10
|
+
var _defaultLoadingPaneProps = require("../loadingpane/common/defaultProps/defaultLoadingPaneProps");
|
|
11
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
12
|
+
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Repro / catcher for internal tracking — screen reader announces hidden / irrelevant
|
|
16
|
+
* text such as "blank" while navigating the chat surface. NVDA / JAWS announce
|
|
17
|
+
* "blank" when they encounter:
|
|
18
|
+
* - an element with an announceable role (button, link, textbox, listitem,
|
|
19
|
+
* progressbar, etc.) that has an empty accessible name (no aria-label, no
|
|
20
|
+
* aria-labelledby, no associated <label>, and no own text content), OR
|
|
21
|
+
* - a live region (`aria-live="polite"` / `aria-live="assertive"`) that is
|
|
22
|
+
* mounted with empty text content (each tick announces "blank").
|
|
23
|
+
*
|
|
24
|
+
* This catcher walks several rendered LCW surfaces and asserts neither pattern
|
|
25
|
+
* is present. Deterministic DOM contract — no SR needed.
|
|
26
|
+
*
|
|
27
|
+
* Surfaces covered today:
|
|
28
|
+
* - ChatButton (default props) — regression guard; passes today.
|
|
29
|
+
* - ChatButton with notification bubble forced visible at unreadCount=0 —
|
|
30
|
+
* regression guard for the empty-live-region path; passes today.
|
|
31
|
+
* - LoadingPane (default props) — regression guard; passes today.
|
|
32
|
+
*
|
|
33
|
+
* Scope note: the original bug surfaces inside WebChat-rendered chat session
|
|
34
|
+
* content (message bubbles, attachments, agent-supplied HTML), which is not
|
|
35
|
+
* reachable from chat-components unit tests. The Playwright catcher
|
|
36
|
+
* `automation_tests/e2e/areas/accessibility/blankAnnouncements.spec.ts` on
|
|
37
|
+
* `chore/a11y-tooling-foundation` walks the full a11y tree of a built
|
|
38
|
+
* `dist/out.js` and is the right vehicle for enumerating per-offender fixes.
|
|
39
|
+
* Promote additional surfaces here as they are wired into the catcher harness.
|
|
40
|
+
*/
|
|
41
|
+
|
|
42
|
+
beforeAll(() => {
|
|
43
|
+
(0, _BroadcastService.BroadcastServiceInitialize)("testChannel");
|
|
44
|
+
});
|
|
45
|
+
afterEach(() => {
|
|
46
|
+
(0, _react.cleanup)();
|
|
47
|
+
});
|
|
48
|
+
const ANNOUNCEABLE_ROLES = new Set(["button", "link", "textbox", "combobox", "listbox", "listitem", "menu", "menuitem", "checkbox", "radio", "switch", "tab", "treeitem", "option", "searchbox", "progressbar", "alert", "status"]);
|
|
49
|
+
const ANNOUNCEABLE_TAGS = new Set(["button", "a", "input", "select", "textarea"]);
|
|
50
|
+
const isInsideAriaHidden = el => {
|
|
51
|
+
let cursor = el;
|
|
52
|
+
while (cursor) {
|
|
53
|
+
if (cursor.getAttribute("aria-hidden") === "true") return true;
|
|
54
|
+
cursor = cursor.parentElement;
|
|
55
|
+
}
|
|
56
|
+
return false;
|
|
57
|
+
};
|
|
58
|
+
const accessibleNameOf = el => {
|
|
59
|
+
const ariaLabel = (el.getAttribute("aria-label") || "").trim();
|
|
60
|
+
if (ariaLabel) return ariaLabel;
|
|
61
|
+
const labelledBy = (el.getAttribute("aria-labelledby") || "").trim();
|
|
62
|
+
if (labelledBy) {
|
|
63
|
+
const referenced = labelledBy.split(/\s+/).map(id => {
|
|
64
|
+
var _document$getElementB;
|
|
65
|
+
return ((_document$getElementB = document.getElementById(id)) === null || _document$getElementB === void 0 ? void 0 : _document$getElementB.textContent) || "";
|
|
66
|
+
}).join(" ").trim();
|
|
67
|
+
if (referenced) return referenced;
|
|
68
|
+
}
|
|
69
|
+
if (el.tagName.toLowerCase() === "input") {
|
|
70
|
+
const id = el.id;
|
|
71
|
+
if (id) {
|
|
72
|
+
var _label$textContent;
|
|
73
|
+
const label = document.querySelector(`label[for="${CSS.escape(id)}"]`);
|
|
74
|
+
const labelText = label === null || label === void 0 || (_label$textContent = label.textContent) === null || _label$textContent === void 0 ? void 0 : _label$textContent.trim();
|
|
75
|
+
if (labelText) return labelText;
|
|
76
|
+
}
|
|
77
|
+
const placeholder = (el.getAttribute("placeholder") || "").trim();
|
|
78
|
+
if (placeholder) return placeholder;
|
|
79
|
+
}
|
|
80
|
+
if (el.tagName.toLowerCase() === "a") {
|
|
81
|
+
const title = (el.getAttribute("title") || "").trim();
|
|
82
|
+
if (title) return title;
|
|
83
|
+
}
|
|
84
|
+
return (el.textContent || "").trim();
|
|
85
|
+
};
|
|
86
|
+
const isAnnounceable = el => {
|
|
87
|
+
if (isInsideAriaHidden(el)) return false;
|
|
88
|
+
const role = (el.getAttribute("role") || "").toLowerCase();
|
|
89
|
+
if (role === "presentation" || role === "none") return false;
|
|
90
|
+
if (role && ANNOUNCEABLE_ROLES.has(role)) return true;
|
|
91
|
+
if (ANNOUNCEABLE_TAGS.has(el.tagName.toLowerCase())) {
|
|
92
|
+
// <input type="hidden"> is not announceable.
|
|
93
|
+
if (el.tagName.toLowerCase() === "input" && (el.getAttribute("type") || "").toLowerCase() === "hidden") {
|
|
94
|
+
return false;
|
|
95
|
+
}
|
|
96
|
+
return true;
|
|
97
|
+
}
|
|
98
|
+
return false;
|
|
99
|
+
};
|
|
100
|
+
const findEmptyAnnounceable = root => {
|
|
101
|
+
return Array.from(root.querySelectorAll("*")).filter(el => isAnnounceable(el) && accessibleNameOf(el) === "");
|
|
102
|
+
};
|
|
103
|
+
const findEmptyLiveRegions = root => {
|
|
104
|
+
return Array.from(root.querySelectorAll("[aria-live]")).filter(el => {
|
|
105
|
+
if (isInsideAriaHidden(el)) return false;
|
|
106
|
+
const live = (el.getAttribute("aria-live") || "").toLowerCase();
|
|
107
|
+
if (live !== "polite" && live !== "assertive") return false;
|
|
108
|
+
return (el.textContent || "").trim() === "";
|
|
109
|
+
});
|
|
110
|
+
};
|
|
111
|
+
const summarize = offenders => offenders.map(el => ({
|
|
112
|
+
tag: el.tagName.toLowerCase(),
|
|
113
|
+
id: el.id,
|
|
114
|
+
role: el.getAttribute("role"),
|
|
115
|
+
ariaLabel: el.getAttribute("aria-label"),
|
|
116
|
+
ariaLabelledBy: el.getAttribute("aria-labelledby"),
|
|
117
|
+
classes: el.className
|
|
118
|
+
}));
|
|
119
|
+
describe("ChatButton — 'blank' / empty-name announcements (internal tracking regression guard)", () => {
|
|
120
|
+
it("no announceable role/tag in the chat-button subtree may have an empty accessible name", () => {
|
|
121
|
+
const {
|
|
122
|
+
container
|
|
123
|
+
} = (0, _react.render)(/*#__PURE__*/_react2.default.createElement(_ChatButton.default, _defaultChatButtonProps.defaultChatButtonProps));
|
|
124
|
+
const button = container.firstElementChild;
|
|
125
|
+
expect(button).not.toBeNull();
|
|
126
|
+
expect(summarize(findEmptyAnnounceable(button))).toEqual([]);
|
|
127
|
+
});
|
|
128
|
+
it("no live region (aria-live=polite/assertive) in the chat-button subtree may be mounted with empty text", () => {
|
|
129
|
+
const props = {
|
|
130
|
+
..._defaultChatButtonProps.defaultChatButtonProps,
|
|
131
|
+
controlProps: {
|
|
132
|
+
..._defaultChatButtonProps.defaultChatButtonProps.controlProps,
|
|
133
|
+
unreadMessageCount: "0",
|
|
134
|
+
hideNotificationBubble: false
|
|
135
|
+
}
|
|
136
|
+
};
|
|
137
|
+
const {
|
|
138
|
+
container
|
|
139
|
+
} = (0, _react.render)(/*#__PURE__*/_react2.default.createElement(_ChatButton.default, props));
|
|
140
|
+
const button = container.firstElementChild;
|
|
141
|
+
expect(button).not.toBeNull();
|
|
142
|
+
expect(summarize(findEmptyLiveRegions(button))).toEqual([]);
|
|
143
|
+
});
|
|
144
|
+
});
|
|
145
|
+
describe("LoadingPane — 'blank' / empty-name announcements (internal tracking regression guard)", () => {
|
|
146
|
+
it("no announceable role/tag in the loading-pane subtree may have an empty accessible name", () => {
|
|
147
|
+
const {
|
|
148
|
+
container
|
|
149
|
+
} = (0, _react.render)(/*#__PURE__*/_react2.default.createElement(_LoadingPane.default, _defaultLoadingPaneProps.defaultLoadingPaneProps));
|
|
150
|
+
const pane = container.firstElementChild;
|
|
151
|
+
expect(pane).not.toBeNull();
|
|
152
|
+
expect(summarize(findEmptyAnnounceable(pane))).toEqual([]);
|
|
153
|
+
});
|
|
154
|
+
it("no live region (aria-live=polite/assertive) in the loading-pane subtree may be mounted with empty text", () => {
|
|
155
|
+
const {
|
|
156
|
+
container
|
|
157
|
+
} = (0, _react.render)(/*#__PURE__*/_react2.default.createElement(_LoadingPane.default, _defaultLoadingPaneProps.defaultLoadingPaneProps));
|
|
158
|
+
const pane = container.firstElementChild;
|
|
159
|
+
expect(pane).not.toBeNull();
|
|
160
|
+
expect(summarize(findEmptyLiveRegions(pane))).toEqual([]);
|
|
161
|
+
});
|
|
162
|
+
});
|
|
@@ -0,0 +1,236 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
require("@testing-library/jest-dom/extend-expect");
|
|
4
|
+
var _react = require("@testing-library/react");
|
|
5
|
+
var _BroadcastService = require("../../services/BroadcastService");
|
|
6
|
+
var _ChatButton = _interopRequireDefault(require("./ChatButton"));
|
|
7
|
+
var _react2 = _interopRequireDefault(require("react"));
|
|
8
|
+
var _defaultChatButtonProps = require("./common/defaultProps/defaultChatButtonProps");
|
|
9
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
10
|
+
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Repro / catcher for internal tracking — NVDA / JAWS in browse mode (virtual cursor)
|
|
14
|
+
* land on "Let's Chat, We're Online" multiple times when navigating with the
|
|
15
|
+
* down-arrow key.
|
|
16
|
+
*
|
|
17
|
+
* Root cause in code: `ChatButton` renders a Fluent UI `<Stack role="button">`
|
|
18
|
+
* with `tabIndex={0}` whose accessible name is computed from its visible
|
|
19
|
+
* children — a `<Label>` for the title (e.g. "Let's Chat!") and a `<Label>`
|
|
20
|
+
* for the subtitle (e.g. "We're online."). In browse mode, NVDA / JAWS treat
|
|
21
|
+
* the button itself AND each inner text node as separate virtual-cursor stops,
|
|
22
|
+
* each carrying the same announceable name fragments. There is no
|
|
23
|
+
* `aria-label` set by default, and the inner labels are not marked
|
|
24
|
+
* `aria-hidden="true"` (which is what would collapse them into a single
|
|
25
|
+
* announcement under the button container).
|
|
26
|
+
*
|
|
27
|
+
* Catcher contract: in the rendered chat-button subtree, at most ONE element
|
|
28
|
+
* may expose each of the title / subtitle strings as an announceable name
|
|
29
|
+
* source. An "announceable name source" here is:
|
|
30
|
+
* - an `aria-label` attribute on a focusable / role-bearing element, OR
|
|
31
|
+
* - a visible `<Label>` (or other text-bearing element) that is NOT
|
|
32
|
+
* `aria-hidden="true"` and is not nested inside an element that is
|
|
33
|
+
* `aria-hidden="true"`.
|
|
34
|
+
*
|
|
35
|
+
* Regression guard: in the rendered DOM, the parent role=button Stack owns a
|
|
36
|
+
* single consolidated aria-label (synthesized from title + subtitle, plus
|
|
37
|
+
* unread-count fragment when applicable) and the inner Labels live inside an
|
|
38
|
+
* aria-hidden text container so browse-mode lands on the button exactly once.
|
|
39
|
+
* Override paths (componentOverrides.title/subtitle/textContainer or a
|
|
40
|
+
* consumer-supplied controlProps.ariaLabel) are preserved unchanged so
|
|
41
|
+
* customers who manage their own accessible names are not affected.
|
|
42
|
+
*/
|
|
43
|
+
|
|
44
|
+
beforeAll(() => {
|
|
45
|
+
(0, _BroadcastService.BroadcastServiceInitialize)("testChannel");
|
|
46
|
+
});
|
|
47
|
+
afterEach(() => {
|
|
48
|
+
(0, _react.cleanup)();
|
|
49
|
+
});
|
|
50
|
+
const isInsideAriaHidden = el => {
|
|
51
|
+
let cursor = el;
|
|
52
|
+
while (cursor) {
|
|
53
|
+
if (cursor.getAttribute("aria-hidden") === "true") return true;
|
|
54
|
+
cursor = cursor.parentElement;
|
|
55
|
+
}
|
|
56
|
+
return false;
|
|
57
|
+
};
|
|
58
|
+
const visibleTextElementsMatching = (root, text) => {
|
|
59
|
+
return Array.from(root.querySelectorAll("*")).filter(el => {
|
|
60
|
+
if (isInsideAriaHidden(el)) return false;
|
|
61
|
+
// Only count leaf-ish text-bearing elements (don't double-count
|
|
62
|
+
// ancestors whose textContent obviously aggregates children).
|
|
63
|
+
const ownText = Array.from(el.childNodes).filter(n => n.nodeType === Node.TEXT_NODE).map(n => (n.textContent || "").trim()).join(" ").trim();
|
|
64
|
+
return ownText === text;
|
|
65
|
+
});
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* Regression guard for internal tracking — ChatButton must not produce duplicate
|
|
70
|
+
* NVDA / JAWS browse-mode stops. Visible title / subtitle text is excluded
|
|
71
|
+
* from the accessibility tree (aria-hidden) and the button container owns a
|
|
72
|
+
* single consolidated aria-label.
|
|
73
|
+
*/
|
|
74
|
+
describe("ChatButton — browse-mode duplicate stops (internal tracking)", () => {
|
|
75
|
+
it("title text 'Let's Chat!' must NOT appear as a visible (non-aria-hidden) name source in the chat-button subtree", () => {
|
|
76
|
+
const {
|
|
77
|
+
container
|
|
78
|
+
} = (0, _react.render)(/*#__PURE__*/_react2.default.createElement(_ChatButton.default, _defaultChatButtonProps.defaultChatButtonProps));
|
|
79
|
+
const button = container.firstElementChild;
|
|
80
|
+
expect(button).not.toBeNull();
|
|
81
|
+
const titleStops = visibleTextElementsMatching(button, "Let's Chat!");
|
|
82
|
+
// The visible title should be excluded from the accessibility tree
|
|
83
|
+
// (e.g. via aria-hidden on the text container) so the announced name
|
|
84
|
+
// comes solely from the consolidated aria-label on the button. Any
|
|
85
|
+
// exposed text-bearing element with this exact text creates an
|
|
86
|
+
// additional browse-mode stop and reproduces internal tracking.
|
|
87
|
+
expect(titleStops.length).toBe(0);
|
|
88
|
+
});
|
|
89
|
+
it("subtitle text 'We're online.' must NOT appear as a visible (non-aria-hidden) name source in the chat-button subtree", () => {
|
|
90
|
+
const {
|
|
91
|
+
container
|
|
92
|
+
} = (0, _react.render)(/*#__PURE__*/_react2.default.createElement(_ChatButton.default, _defaultChatButtonProps.defaultChatButtonProps));
|
|
93
|
+
const button = container.firstElementChild;
|
|
94
|
+
expect(button).not.toBeNull();
|
|
95
|
+
const subtitleStops = visibleTextElementsMatching(button, "We're online.");
|
|
96
|
+
expect(subtitleStops.length).toBe(0);
|
|
97
|
+
});
|
|
98
|
+
it("the chat-button container must own a single consolidated aria-label so browse mode lands on it once", () => {
|
|
99
|
+
const {
|
|
100
|
+
container
|
|
101
|
+
} = (0, _react.render)(/*#__PURE__*/_react2.default.createElement(_ChatButton.default, _defaultChatButtonProps.defaultChatButtonProps));
|
|
102
|
+
const button = container.firstElementChild;
|
|
103
|
+
expect(button).not.toBeNull();
|
|
104
|
+
// Either the container has a non-empty aria-label, OR every inner
|
|
105
|
+
// text-bearing descendant is aria-hidden so the computed name comes
|
|
106
|
+
// from the inner text exactly once with no extra browse-mode stops.
|
|
107
|
+
const hasAriaLabel = !!(button.getAttribute("aria-label") || "").trim();
|
|
108
|
+
const innerVisibleText = visibleTextElementsMatching(button, "Let's Chat!").length + visibleTextElementsMatching(button, "We're online.").length;
|
|
109
|
+
// Today: hasAriaLabel === false (default ariaLabel is undefined) AND
|
|
110
|
+
// innerVisibleText > 0. The catcher requires at least one of these
|
|
111
|
+
// to flip.
|
|
112
|
+
expect(hasAriaLabel || innerVisibleText === 0).toBe(true);
|
|
113
|
+
});
|
|
114
|
+
it("the synthesized aria-label includes the unread-count fragment when hideNotificationBubble=false and unreadMessageCount > 0", () => {
|
|
115
|
+
const props = {
|
|
116
|
+
..._defaultChatButtonProps.defaultChatButtonProps,
|
|
117
|
+
controlProps: {
|
|
118
|
+
..._defaultChatButtonProps.defaultChatButtonProps.controlProps,
|
|
119
|
+
hideNotificationBubble: false,
|
|
120
|
+
unreadMessageCount: "3",
|
|
121
|
+
ariaLabelUnreadMessageString: "you have new messages",
|
|
122
|
+
titleText: "Let's Chat!",
|
|
123
|
+
subtitleText: "We're online."
|
|
124
|
+
}
|
|
125
|
+
};
|
|
126
|
+
const {
|
|
127
|
+
container
|
|
128
|
+
} = (0, _react.render)(/*#__PURE__*/_react2.default.createElement(_ChatButton.default, props));
|
|
129
|
+
const button = container.firstElementChild;
|
|
130
|
+
const ariaLabel = button.getAttribute("aria-label") || "";
|
|
131
|
+
expect(ariaLabel).toContain("3");
|
|
132
|
+
expect(ariaLabel).toContain("you have new messages");
|
|
133
|
+
expect(ariaLabel).toContain("Let's Chat!");
|
|
134
|
+
expect(ariaLabel).toContain("We're online.");
|
|
135
|
+
});
|
|
136
|
+
it("a consumer-supplied controlProps.ariaLabel wins over the synthesized label", () => {
|
|
137
|
+
const props = {
|
|
138
|
+
..._defaultChatButtonProps.defaultChatButtonProps,
|
|
139
|
+
controlProps: {
|
|
140
|
+
..._defaultChatButtonProps.defaultChatButtonProps.controlProps,
|
|
141
|
+
ariaLabel: "Talk to a live agent"
|
|
142
|
+
}
|
|
143
|
+
};
|
|
144
|
+
const {
|
|
145
|
+
container
|
|
146
|
+
} = (0, _react.render)(/*#__PURE__*/_react2.default.createElement(_ChatButton.default, props));
|
|
147
|
+
const button = container.firstElementChild;
|
|
148
|
+
expect(button.getAttribute("aria-label")).toBe("Talk to a live agent");
|
|
149
|
+
});
|
|
150
|
+
it("componentOverrides.textContainer preserves consumer-rendered visible text (synthesis is skipped)", () => {
|
|
151
|
+
const customText = "My custom chat text";
|
|
152
|
+
const props = {
|
|
153
|
+
..._defaultChatButtonProps.defaultChatButtonProps,
|
|
154
|
+
componentOverrides: {
|
|
155
|
+
textContainer: /*#__PURE__*/_react2.default.createElement("div", {
|
|
156
|
+
id: "my-custom-text"
|
|
157
|
+
}, customText)
|
|
158
|
+
}
|
|
159
|
+
};
|
|
160
|
+
const {
|
|
161
|
+
container
|
|
162
|
+
} = (0, _react.render)(/*#__PURE__*/_react2.default.createElement(_ChatButton.default, props));
|
|
163
|
+
const button = container.firstElementChild;
|
|
164
|
+
// The custom text MUST remain visible in the a11y tree so consumers
|
|
165
|
+
// who replace the text container keep their announced text.
|
|
166
|
+
const customStops = visibleTextElementsMatching(button, customText);
|
|
167
|
+
expect(customStops.length).toBeGreaterThan(0);
|
|
168
|
+
// And the button must NOT carry a synthesized aria-label that would
|
|
169
|
+
// override the consumer's content.
|
|
170
|
+
const ariaLabel = (button.getAttribute("aria-label") || "").trim();
|
|
171
|
+
expect(ariaLabel).toBe("");
|
|
172
|
+
});
|
|
173
|
+
it("componentOverrides.title preserves consumer-rendered visible title (synthesis is skipped)", () => {
|
|
174
|
+
const customTitle = "Custom override title";
|
|
175
|
+
const props = {
|
|
176
|
+
..._defaultChatButtonProps.defaultChatButtonProps,
|
|
177
|
+
componentOverrides: {
|
|
178
|
+
title: /*#__PURE__*/_react2.default.createElement("span", {
|
|
179
|
+
id: "my-custom-title"
|
|
180
|
+
}, customTitle)
|
|
181
|
+
}
|
|
182
|
+
};
|
|
183
|
+
const {
|
|
184
|
+
container
|
|
185
|
+
} = (0, _react.render)(/*#__PURE__*/_react2.default.createElement(_ChatButton.default, props));
|
|
186
|
+
const button = container.firstElementChild;
|
|
187
|
+
const customStops = visibleTextElementsMatching(button, customTitle);
|
|
188
|
+
expect(customStops.length).toBeGreaterThan(0);
|
|
189
|
+
const ariaLabel = (button.getAttribute("aria-label") || "").trim();
|
|
190
|
+
expect(ariaLabel).toBe("");
|
|
191
|
+
});
|
|
192
|
+
|
|
193
|
+
// Regression guard for the strict string-equality slip-throughs that
|
|
194
|
+
// brittle `unreadMessageCount !== "0"` allowed: values that coerce to
|
|
195
|
+
// numeric 0 (or non-numeric noise) must NOT render the bubble nor pollute
|
|
196
|
+
// the synthesized aria-label with a "0 you have new messages" fragment.
|
|
197
|
+
describe.each([["padded zero (' 0 ')", " 0 "], ["decimal zero ('0.0')", "0.0"], ["empty string ('')", ""], ["non-numeric ('abc')", "abc"]])("zero-equivalent unreadMessageCount: %s", (_label, value) => {
|
|
198
|
+
it("does NOT render the notification bubble", () => {
|
|
199
|
+
const props = {
|
|
200
|
+
..._defaultChatButtonProps.defaultChatButtonProps,
|
|
201
|
+
controlProps: {
|
|
202
|
+
..._defaultChatButtonProps.defaultChatButtonProps.controlProps,
|
|
203
|
+
hideNotificationBubble: false,
|
|
204
|
+
unreadMessageCount: value,
|
|
205
|
+
ariaLabelUnreadMessageString: "you have new messages"
|
|
206
|
+
}
|
|
207
|
+
};
|
|
208
|
+
const {
|
|
209
|
+
container
|
|
210
|
+
} = (0, _react.render)(/*#__PURE__*/_react2.default.createElement(_ChatButton.default, props));
|
|
211
|
+
const bubble = container.querySelector("[id$='-notification-bubble']");
|
|
212
|
+
expect(bubble).toBeNull();
|
|
213
|
+
});
|
|
214
|
+
it("does NOT inject the unread-count fragment into the synthesized aria-label", () => {
|
|
215
|
+
const props = {
|
|
216
|
+
..._defaultChatButtonProps.defaultChatButtonProps,
|
|
217
|
+
controlProps: {
|
|
218
|
+
..._defaultChatButtonProps.defaultChatButtonProps.controlProps,
|
|
219
|
+
hideNotificationBubble: false,
|
|
220
|
+
unreadMessageCount: value,
|
|
221
|
+
ariaLabelUnreadMessageString: "you have new messages"
|
|
222
|
+
}
|
|
223
|
+
};
|
|
224
|
+
const {
|
|
225
|
+
container
|
|
226
|
+
} = (0, _react.render)(/*#__PURE__*/_react2.default.createElement(_ChatButton.default, props));
|
|
227
|
+
const button = container.firstElementChild;
|
|
228
|
+
const ariaLabel = button.getAttribute("aria-label") || "";
|
|
229
|
+
expect(ariaLabel).not.toContain("you have new messages");
|
|
230
|
+
// and the raw zero-equivalent must not leak into the label
|
|
231
|
+
if (value.trim().length > 0) {
|
|
232
|
+
expect(ariaLabel).not.toContain(value.trim());
|
|
233
|
+
}
|
|
234
|
+
});
|
|
235
|
+
});
|
|
236
|
+
});
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
require("@testing-library/jest-dom/extend-expect");
|
|
4
|
+
var _react = require("@testing-library/react");
|
|
5
|
+
var _BroadcastService = require("../../services/BroadcastService");
|
|
6
|
+
var _ChatButton = _interopRequireDefault(require("./ChatButton"));
|
|
7
|
+
var _react2 = _interopRequireDefault(require("react"));
|
|
8
|
+
var _defaultChatButtonControlProps = require("./common/defaultProps/defaultChatButtonControlProps");
|
|
9
|
+
var _defaultChatButtonProps = require("./common/defaultProps/defaultChatButtonProps");
|
|
10
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
11
|
+
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
12
|
+
|
|
13
|
+
const expectedTitle = _defaultChatButtonControlProps.defaultChatButtonControlProps.titleText;
|
|
14
|
+
const expectedSubtitle = _defaultChatButtonControlProps.defaultChatButtonControlProps.subtitleText;
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Repro / catcher for internal tracking — NVDA / JAWS in browse mode (virtual cursor)
|
|
18
|
+
* land on "Let's Chat, We're Online" multiple times when navigating with the
|
|
19
|
+
* down-arrow key.
|
|
20
|
+
*
|
|
21
|
+
* Root cause in code: `ChatButton` renders a Fluent UI `<Stack role="button">`
|
|
22
|
+
* with `tabIndex={0}` whose accessible name is computed from its visible
|
|
23
|
+
* children — a `<Label>` for the title (e.g. "Let's Chat!") and a `<Label>`
|
|
24
|
+
* for the subtitle (e.g. "We're online."). In browse mode, NVDA / JAWS treat
|
|
25
|
+
* the button itself AND each inner text node as separate virtual-cursor stops,
|
|
26
|
+
* each carrying the same announceable name fragments. There is no
|
|
27
|
+
* `aria-label` set by default, and the inner labels are not marked
|
|
28
|
+
* `aria-hidden="true"` (which is what would collapse them into a single
|
|
29
|
+
* announcement under the button container).
|
|
30
|
+
*
|
|
31
|
+
* Catcher contract: the title / subtitle strings must NOT appear as
|
|
32
|
+
* additional announceable name sources in the chat-button subtree (only the
|
|
33
|
+
* single consolidated aria-label on the role=button container should name the
|
|
34
|
+
* button). An "announceable name source" here is:
|
|
35
|
+
* - an `aria-label` attribute on a focusable / role-bearing element, OR
|
|
36
|
+
* - a visible `<Label>` (or other text-bearing element) that is NOT
|
|
37
|
+
* `aria-hidden="true"` and is not nested inside an element that is
|
|
38
|
+
* `aria-hidden="true"`.
|
|
39
|
+
*
|
|
40
|
+
* Expected to FAIL today: the rendered DOM contains BOTH the title text node
|
|
41
|
+
* AND the subtitle text node as bare visible text, and the parent Stack has
|
|
42
|
+
* no `aria-label` to consolidate them. Browse-mode therefore sees three
|
|
43
|
+
* stops (button, title, subtitle) all carrying the same combined name.
|
|
44
|
+
*/
|
|
45
|
+
|
|
46
|
+
beforeAll(() => {
|
|
47
|
+
(0, _BroadcastService.BroadcastServiceInitialize)("testChannel");
|
|
48
|
+
});
|
|
49
|
+
afterEach(() => {
|
|
50
|
+
(0, _react.cleanup)();
|
|
51
|
+
});
|
|
52
|
+
const isInsideAriaHidden = el => {
|
|
53
|
+
let cursor = el;
|
|
54
|
+
while (cursor) {
|
|
55
|
+
if (cursor.getAttribute("aria-hidden") === "true") return true;
|
|
56
|
+
cursor = cursor.parentElement;
|
|
57
|
+
}
|
|
58
|
+
return false;
|
|
59
|
+
};
|
|
60
|
+
const visibleTextElementsMatching = (root, text) => {
|
|
61
|
+
return Array.from(root.querySelectorAll("*")).filter(el => {
|
|
62
|
+
if (isInsideAriaHidden(el)) return false;
|
|
63
|
+
// Only count leaf-ish text-bearing elements (don't double-count
|
|
64
|
+
// ancestors whose textContent obviously aggregates children).
|
|
65
|
+
const ownText = Array.from(el.childNodes).filter(n => n.nodeType === Node.TEXT_NODE).map(n => (n.textContent || "").trim()).join(" ").trim();
|
|
66
|
+
return ownText === text;
|
|
67
|
+
});
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* SKIPPED until the source fix lands. Un-skip the describe below to validate
|
|
72
|
+
* the fix to internal tracking; the suite is expected to FAIL today against unfixed
|
|
73
|
+
* source. Mirrors the chat-widget `*.unfixed.a11y.spec.tsx` convention.
|
|
74
|
+
*/
|
|
75
|
+
describe.skip("ChatButton — browse-mode duplicate stops (internal tracking)", () => {
|
|
76
|
+
it(`title text '${expectedTitle}' must NOT appear as a visible (non-aria-hidden) name source in the chat-button subtree`, () => {
|
|
77
|
+
const {
|
|
78
|
+
container
|
|
79
|
+
} = (0, _react.render)(/*#__PURE__*/_react2.default.createElement(_ChatButton.default, _defaultChatButtonProps.defaultChatButtonProps));
|
|
80
|
+
const button = container.firstElementChild;
|
|
81
|
+
expect(button).not.toBeNull();
|
|
82
|
+
const titleStops = visibleTextElementsMatching(button, expectedTitle);
|
|
83
|
+
// The visible title should be excluded from the accessibility tree
|
|
84
|
+
// (e.g. via aria-hidden on the text container) so the announced name
|
|
85
|
+
// comes solely from the consolidated aria-label on the button. Any
|
|
86
|
+
// exposed text-bearing element with this exact text creates an
|
|
87
|
+
// additional browse-mode stop and reproduces internal tracking.
|
|
88
|
+
expect(titleStops.length).toBe(0);
|
|
89
|
+
});
|
|
90
|
+
it(`subtitle text '${expectedSubtitle}' must NOT appear as a visible (non-aria-hidden) name source in the chat-button subtree`, () => {
|
|
91
|
+
const {
|
|
92
|
+
container
|
|
93
|
+
} = (0, _react.render)(/*#__PURE__*/_react2.default.createElement(_ChatButton.default, _defaultChatButtonProps.defaultChatButtonProps));
|
|
94
|
+
const button = container.firstElementChild;
|
|
95
|
+
expect(button).not.toBeNull();
|
|
96
|
+
const subtitleStops = visibleTextElementsMatching(button, expectedSubtitle);
|
|
97
|
+
expect(subtitleStops.length).toBe(0);
|
|
98
|
+
});
|
|
99
|
+
it("the chat-button container must own a single consolidated aria-label so browse mode lands on it once", () => {
|
|
100
|
+
const {
|
|
101
|
+
container
|
|
102
|
+
} = (0, _react.render)(/*#__PURE__*/_react2.default.createElement(_ChatButton.default, _defaultChatButtonProps.defaultChatButtonProps));
|
|
103
|
+
const button = container.firstElementChild;
|
|
104
|
+
expect(button).not.toBeNull();
|
|
105
|
+
// Either the container has a non-empty aria-label, OR every inner
|
|
106
|
+
// text-bearing descendant is aria-hidden so the computed name comes
|
|
107
|
+
// from the inner text exactly once with no extra browse-mode stops.
|
|
108
|
+
const hasAriaLabel = !!(button.getAttribute("aria-label") || "").trim();
|
|
109
|
+
const innerVisibleText = visibleTextElementsMatching(button, expectedTitle).length + visibleTextElementsMatching(button, expectedSubtitle).length;
|
|
110
|
+
// Today: hasAriaLabel === false (default ariaLabel is undefined) AND
|
|
111
|
+
// innerVisibleText > 0. The catcher requires at least one of these
|
|
112
|
+
// to flip.
|
|
113
|
+
expect(hasAriaLabel || innerVisibleText === 0).toBe(true);
|
|
114
|
+
});
|
|
115
|
+
});
|
|
@@ -17,13 +17,24 @@ var _defaultChatButtonSubTitleStyles = require("./common/defaultStyles/defaultCh
|
|
|
17
17
|
var _defaultChatButtonTextContainerStyles = require("./common/defaultStyles/defaultChatButtonTextContainerStyles");
|
|
18
18
|
var _defaultChatButtonTitleStyles = require("./common/defaultStyles/defaultChatButtonTitleStyles");
|
|
19
19
|
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function (e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (const t in e) "default" !== t && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]); return f; })(e, t); }
|
|
20
|
+
// Returns true when the unread-message count represents a positive number.
|
|
21
|
+
// Defensive against non-strict callers that may pass " 0 ", "0.0", "" or a
|
|
22
|
+
// stringified numeric 0; only a finite count strictly greater than zero counts
|
|
23
|
+
// as "unread" for both the notification bubble and the synthesized aria-label.
|
|
24
|
+
function hasUnreadMessages(unreadMessageCount) {
|
|
25
|
+
if (unreadMessageCount === undefined || unreadMessageCount === null) {
|
|
26
|
+
return false;
|
|
27
|
+
}
|
|
28
|
+
const parsed = Number(unreadMessageCount);
|
|
29
|
+
return Number.isFinite(parsed) && parsed > 0;
|
|
30
|
+
}
|
|
20
31
|
function NotificationBubble(props, parentId) {
|
|
21
32
|
var _props$styleProps, _props$controlProps;
|
|
22
33
|
const notificationBubbleStyles = {
|
|
23
34
|
root: Object.assign({}, _defaultChatButtonNotificationBubbleStyles.defaultChatButtonNotificationBubbleStyles, (_props$styleProps = props.styleProps) === null || _props$styleProps === void 0 ? void 0 : _props$styleProps.notificationBubbleStyleProps)
|
|
24
35
|
};
|
|
25
36
|
const unreadMessageCount = ((_props$controlProps = props.controlProps) === null || _props$controlProps === void 0 ? void 0 : _props$controlProps.unreadMessageCount) ?? (_defaultChatButtonControlProps.defaultChatButtonControlProps === null || _defaultChatButtonControlProps.defaultChatButtonControlProps === void 0 ? void 0 : _defaultChatButtonControlProps.defaultChatButtonControlProps.unreadMessageCount);
|
|
26
|
-
if (unreadMessageCount
|
|
37
|
+
if (hasUnreadMessages(unreadMessageCount)) {
|
|
27
38
|
var _props$componentOverr, _props$controlProps2, _props$controlProps3, _props$styleProps2, _props$controlProps4, _props$controlProps5;
|
|
28
39
|
return (0, _decodeComponentString.decodeComponentString)((_props$componentOverr = props.componentOverrides) === null || _props$componentOverr === void 0 ? void 0 : _props$componentOverr.notificationBubble) || /*#__PURE__*/_react2.default.createElement(_react.Stack, {
|
|
29
40
|
"aria-live": "polite",
|
|
@@ -49,7 +60,7 @@ function IconContainer(props, parentId) {
|
|
|
49
60
|
});
|
|
50
61
|
}
|
|
51
62
|
function TextContainer(props, parentId) {
|
|
52
|
-
var _props$styleProps5, _props$styleProps6, _props$styleProps7, _props$controlProps6, _props$controlProps7, _props$controlProps8, _props$controlProps9, _props$controlProps0, _props$controlProps1, _props$componentOverr3, _props$styleProps8, _props$
|
|
63
|
+
var _props$styleProps5, _props$styleProps6, _props$styleProps7, _props$controlProps6, _props$controlProps7, _props$controlProps8, _props$controlProps9, _props$controlProps0, _props$controlProps1, _props$componentOverr3, _props$componentOverr4, _props$componentOverr5, _props$styleProps8, _props$componentOverr6, _props$styleProps9, _props$componentOverr7, _props$styleProps0;
|
|
53
64
|
const textContainerStyles = {
|
|
54
65
|
root: Object.assign({}, _defaultChatButtonTextContainerStyles.defaultChatButtonTextContainerStyles, (_props$styleProps5 = props.styleProps) === null || _props$styleProps5 === void 0 ? void 0 : _props$styleProps5.textContainerStyleProps)
|
|
55
66
|
};
|
|
@@ -65,16 +76,26 @@ function TextContainer(props, parentId) {
|
|
|
65
76
|
const titleText = ((_props$controlProps9 = props.controlProps) === null || _props$controlProps9 === void 0 ? void 0 : _props$controlProps9.titleText) ?? (_defaultChatButtonControlProps.defaultChatButtonControlProps === null || _defaultChatButtonControlProps.defaultChatButtonControlProps === void 0 ? void 0 : _defaultChatButtonControlProps.defaultChatButtonControlProps.titleText);
|
|
66
77
|
const subtitleDir = ((_props$controlProps0 = props.controlProps) === null || _props$controlProps0 === void 0 ? void 0 : _props$controlProps0.dir) ?? (_defaultChatButtonControlProps.defaultChatButtonControlProps === null || _defaultChatButtonControlProps.defaultChatButtonControlProps === void 0 ? void 0 : _defaultChatButtonControlProps.defaultChatButtonControlProps.dir);
|
|
67
78
|
const subtitleText = ((_props$controlProps1 = props.controlProps) === null || _props$controlProps1 === void 0 ? void 0 : _props$controlProps1.subtitleText) ?? (_defaultChatButtonControlProps.defaultChatButtonControlProps === null || _defaultChatButtonControlProps.defaultChatButtonControlProps === void 0 ? void 0 : _defaultChatButtonControlProps.defaultChatButtonControlProps.subtitleText);
|
|
68
|
-
|
|
79
|
+
|
|
80
|
+
// internal tracking: when the default title / subtitle Labels are used, hide the
|
|
81
|
+
// text container subtree from the accessibility tree. The button container
|
|
82
|
+
// owns a consolidated aria-label that already announces the same text, so
|
|
83
|
+
// exposing the inner Labels causes NVDA / JAWS browse-mode to land on the
|
|
84
|
+
// same announcement multiple times. Customer overrides for title /
|
|
85
|
+
// subtitle keep their default a11y behavior so they can manage their own
|
|
86
|
+
// accessible names.
|
|
87
|
+
const hideTextFromA11yTree = !((_props$componentOverr3 = props.componentOverrides) !== null && _props$componentOverr3 !== void 0 && _props$componentOverr3.title) && !((_props$componentOverr4 = props.componentOverrides) !== null && _props$componentOverr4 !== void 0 && _props$componentOverr4.subtitle);
|
|
88
|
+
return (0, _decodeComponentString.decodeComponentString)((_props$componentOverr5 = props.componentOverrides) === null || _props$componentOverr5 === void 0 ? void 0 : _props$componentOverr5.textContainer) || /*#__PURE__*/_react2.default.createElement(_react.Stack, {
|
|
69
89
|
styles: textContainerStyles,
|
|
70
90
|
className: (_props$styleProps8 = props.styleProps) === null || _props$styleProps8 === void 0 || (_props$styleProps8 = _props$styleProps8.classNames) === null || _props$styleProps8 === void 0 ? void 0 : _props$styleProps8.textContainerClassName,
|
|
71
|
-
id: parentId + "-text-container"
|
|
72
|
-
|
|
91
|
+
id: parentId + "-text-container",
|
|
92
|
+
"aria-hidden": hideTextFromA11yTree || undefined
|
|
93
|
+
}, !hideChatTitle && ((0, _decodeComponentString.decodeComponentString)((_props$componentOverr6 = props.componentOverrides) === null || _props$componentOverr6 === void 0 ? void 0 : _props$componentOverr6.title) || /*#__PURE__*/_react2.default.createElement(_react.Label, {
|
|
73
94
|
styles: titleStyles,
|
|
74
95
|
dir: titleDir,
|
|
75
96
|
className: (_props$styleProps9 = props.styleProps) === null || _props$styleProps9 === void 0 || (_props$styleProps9 = _props$styleProps9.classNames) === null || _props$styleProps9 === void 0 ? void 0 : _props$styleProps9.titleClassName,
|
|
76
97
|
id: parentId + "-title"
|
|
77
|
-
}, titleText)), !hideChatSubtitle && ((0, _decodeComponentString.decodeComponentString)((_props$
|
|
98
|
+
}, titleText)), !hideChatSubtitle && ((0, _decodeComponentString.decodeComponentString)((_props$componentOverr7 = props.componentOverrides) === null || _props$componentOverr7 === void 0 ? void 0 : _props$componentOverr7.subtitle) || /*#__PURE__*/_react2.default.createElement(_react.Label, {
|
|
78
99
|
styles: subtitleStyles,
|
|
79
100
|
dir: subtitleDir,
|
|
80
101
|
className: (_props$styleProps0 = props.styleProps) === null || _props$styleProps0 === void 0 || (_props$styleProps0 = _props$styleProps0.classNames) === null || _props$styleProps0 === void 0 ? void 0 : _props$styleProps0.subtitleClassName,
|
|
@@ -82,21 +103,36 @@ function TextContainer(props, parentId) {
|
|
|
82
103
|
}, subtitleText)));
|
|
83
104
|
}
|
|
84
105
|
function ChatButton(props) {
|
|
85
|
-
var _props$controlProps10, _props$controlProps11, _props$controlProps12, _props$controlProps13, _props$controlProps14, _props$controlProps15, _props$controlProps16, _props$controlProps17, _props$styleProps1;
|
|
106
|
+
var _props$controlProps10, _props$controlProps11, _props$controlProps12, _props$controlProps13, _props$controlProps14, _props$controlProps15, _props$controlProps16, _props$controlProps17, _props$controlProps18, _props$controlProps19, _props$controlProps20, _props$controlProps21, _props$controlProps22, _props$componentOverr8, _props$componentOverr9, _props$componentOverr0, _props$controlProps23, _props$styleProps1;
|
|
86
107
|
const elementId = ((_props$controlProps10 = props.controlProps) === null || _props$controlProps10 === void 0 ? void 0 : _props$controlProps10.id) ?? _Constants.Ids.DefaultChatButtonId;
|
|
87
|
-
const
|
|
88
|
-
const
|
|
89
|
-
const
|
|
90
|
-
const
|
|
91
|
-
const
|
|
92
|
-
const
|
|
93
|
-
|
|
108
|
+
const defaultRole = ((_props$controlProps11 = props.controlProps) === null || _props$controlProps11 === void 0 ? void 0 : _props$controlProps11.role) ?? (_defaultChatButtonControlProps.defaultChatButtonControlProps === null || _defaultChatButtonControlProps.defaultChatButtonControlProps === void 0 ? void 0 : _defaultChatButtonControlProps.defaultChatButtonControlProps.role);
|
|
109
|
+
const containersDir = ((_props$controlProps12 = props.controlProps) === null || _props$controlProps12 === void 0 ? void 0 : _props$controlProps12.dir) ?? (_defaultChatButtonControlProps.defaultChatButtonControlProps === null || _defaultChatButtonControlProps.defaultChatButtonControlProps === void 0 ? void 0 : _defaultChatButtonControlProps.defaultChatButtonControlProps.dir);
|
|
110
|
+
const hideChatButton = ((_props$controlProps13 = props.controlProps) === null || _props$controlProps13 === void 0 ? void 0 : _props$controlProps13.hideChatButton) ?? (_defaultChatButtonControlProps.defaultChatButtonControlProps === null || _defaultChatButtonControlProps.defaultChatButtonControlProps === void 0 ? void 0 : _defaultChatButtonControlProps.defaultChatButtonControlProps.hideChatButton);
|
|
111
|
+
const hideChatIcon = ((_props$controlProps14 = props.controlProps) === null || _props$controlProps14 === void 0 ? void 0 : _props$controlProps14.hideChatIcon) ?? (_defaultChatButtonControlProps.defaultChatButtonControlProps === null || _defaultChatButtonControlProps.defaultChatButtonControlProps === void 0 ? void 0 : _defaultChatButtonControlProps.defaultChatButtonControlProps.hideChatIcon);
|
|
112
|
+
const hideChatTextContainer = ((_props$controlProps15 = props.controlProps) === null || _props$controlProps15 === void 0 ? void 0 : _props$controlProps15.hideChatTextContainer) ?? (_defaultChatButtonControlProps.defaultChatButtonControlProps === null || _defaultChatButtonControlProps.defaultChatButtonControlProps === void 0 ? void 0 : _defaultChatButtonControlProps.defaultChatButtonControlProps.hideChatTextContainer);
|
|
113
|
+
const hideNotificationBubble = ((_props$controlProps16 = props.controlProps) === null || _props$controlProps16 === void 0 ? void 0 : _props$controlProps16.hideNotificationBubble) ?? (_defaultChatButtonControlProps.defaultChatButtonControlProps === null || _defaultChatButtonControlProps.defaultChatButtonControlProps === void 0 ? void 0 : _defaultChatButtonControlProps.defaultChatButtonControlProps.hideNotificationBubble);
|
|
114
|
+
|
|
115
|
+
// internal tracking: when the consumer has not supplied a custom aria-label and
|
|
116
|
+
// the default title / subtitle Labels are in play, synthesize a single
|
|
117
|
+
// consolidated aria-label from the visible text so NVDA / JAWS browse
|
|
118
|
+
// mode lands on the role=button container exactly once. The text
|
|
119
|
+
// container is also marked aria-hidden in TextContainer so the inner
|
|
120
|
+
// labels do not produce additional virtual-cursor stops.
|
|
121
|
+
const titleText = ((_props$controlProps17 = props.controlProps) === null || _props$controlProps17 === void 0 ? void 0 : _props$controlProps17.titleText) ?? (_defaultChatButtonControlProps.defaultChatButtonControlProps === null || _defaultChatButtonControlProps.defaultChatButtonControlProps === void 0 ? void 0 : _defaultChatButtonControlProps.defaultChatButtonControlProps.titleText);
|
|
122
|
+
const subtitleText = ((_props$controlProps18 = props.controlProps) === null || _props$controlProps18 === void 0 ? void 0 : _props$controlProps18.subtitleText) ?? (_defaultChatButtonControlProps.defaultChatButtonControlProps === null || _defaultChatButtonControlProps.defaultChatButtonControlProps === void 0 ? void 0 : _defaultChatButtonControlProps.defaultChatButtonControlProps.subtitleText);
|
|
123
|
+
const hideChatTitle = ((_props$controlProps19 = props.controlProps) === null || _props$controlProps19 === void 0 ? void 0 : _props$controlProps19.hideChatTitle) ?? (_defaultChatButtonControlProps.defaultChatButtonControlProps === null || _defaultChatButtonControlProps.defaultChatButtonControlProps === void 0 ? void 0 : _defaultChatButtonControlProps.defaultChatButtonControlProps.hideChatTitle);
|
|
124
|
+
const hideChatSubtitle = ((_props$controlProps20 = props.controlProps) === null || _props$controlProps20 === void 0 ? void 0 : _props$controlProps20.hideChatSubtitle) ?? (_defaultChatButtonControlProps.defaultChatButtonControlProps === null || _defaultChatButtonControlProps.defaultChatButtonControlProps === void 0 ? void 0 : _defaultChatButtonControlProps.defaultChatButtonControlProps.hideChatSubtitle);
|
|
125
|
+
const unreadMessageCount = ((_props$controlProps21 = props.controlProps) === null || _props$controlProps21 === void 0 ? void 0 : _props$controlProps21.unreadMessageCount) ?? (_defaultChatButtonControlProps.defaultChatButtonControlProps === null || _defaultChatButtonControlProps.defaultChatButtonControlProps === void 0 ? void 0 : _defaultChatButtonControlProps.defaultChatButtonControlProps.unreadMessageCount);
|
|
126
|
+
const ariaLabelUnreadMessageString = ((_props$controlProps22 = props.controlProps) === null || _props$controlProps22 === void 0 ? void 0 : _props$controlProps22.ariaLabelUnreadMessageString) ?? (_defaultChatButtonControlProps.defaultChatButtonControlProps === null || _defaultChatButtonControlProps.defaultChatButtonControlProps === void 0 ? void 0 : _defaultChatButtonControlProps.defaultChatButtonControlProps.ariaLabelUnreadMessageString);
|
|
127
|
+
const canSynthesizeAriaLabel = !hideChatTextContainer && !((_props$componentOverr8 = props.componentOverrides) !== null && _props$componentOverr8 !== void 0 && _props$componentOverr8.textContainer) && !((_props$componentOverr9 = props.componentOverrides) !== null && _props$componentOverr9 !== void 0 && _props$componentOverr9.title) && !((_props$componentOverr0 = props.componentOverrides) !== null && _props$componentOverr0 !== void 0 && _props$componentOverr0.subtitle);
|
|
128
|
+
const synthesizedAriaLabel = canSynthesizeAriaLabel ? [!hideNotificationBubble && hasUnreadMessages(unreadMessageCount) ? `${unreadMessageCount} ${ariaLabelUnreadMessageString ?? ""}`.trim() : "", !hideChatTitle ? titleText : "", !hideChatSubtitle ? subtitleText : ""].filter(Boolean).join(" ").trim() : "";
|
|
129
|
+
const defaultAriaLabel = ((_props$controlProps23 = props.controlProps) === null || _props$controlProps23 === void 0 ? void 0 : _props$controlProps23.ariaLabel) ?? _defaultChatButtonControlProps.defaultChatButtonControlProps.ariaLabel ?? (synthesizedAriaLabel || undefined);
|
|
94
130
|
const chatButtonGroupStyles = {
|
|
95
131
|
root: Object.assign({}, _defaultChatButtonGeneralStyles.defaultChatButtonGeneralStyles, (_props$styleProps1 = props.styleProps) === null || _props$styleProps1 === void 0 ? void 0 : _props$styleProps1.generalStyleProps)
|
|
96
132
|
};
|
|
97
133
|
const handleInitiateChatClick = (0, _react2.useCallback)(() => {
|
|
98
|
-
var _props$
|
|
99
|
-
if ((_props$
|
|
134
|
+
var _props$controlProps24;
|
|
135
|
+
if ((_props$controlProps24 = props.controlProps) !== null && _props$controlProps24 !== void 0 && _props$controlProps24.onClick) {
|
|
100
136
|
const customEvent = {
|
|
101
137
|
elementType: _Constants.ElementType.ChatButton,
|
|
102
138
|
elementId: elementId,
|