@meetelise/chat 1.63.0 → 1.63.1
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/src/WebComponent/actions/call-us-window.d.ts +0 -2
- package/dist/src/WebComponent/actions/email-us-window.d.ts +1 -2
- package/dist/src/WebComponent/pubnub-chat.d.ts +5 -0
- package/package.json +1 -1
- package/public/dist/index.js +167 -167
- package/src/WebComponent/Scheduler/tour-scheduler.ts +2 -2
- package/src/WebComponent/actions/call-us-window.ts +12 -8
- package/src/WebComponent/actions/email-us-window.ts +12 -6
- package/src/WebComponent/pubnub-chat.ts +14 -0
- package/src/overlayFocus.test.ts +102 -0
|
@@ -78,7 +78,7 @@ import { readGoogleReserveReferral } from "../../googleReserve";
|
|
|
78
78
|
import fetchBuildingUnitsSummary, {
|
|
79
79
|
UnitSummary,
|
|
80
80
|
} from "../../fetchBuildingUnitsSummary";
|
|
81
|
-
import {
|
|
81
|
+
import { placeFocusInside, trapTabInside } from "../pubnub-chat";
|
|
82
82
|
|
|
83
83
|
@customElement("tour-scheduler")
|
|
84
84
|
export class TourScheduler extends LitElement {
|
|
@@ -167,7 +167,7 @@ export class TourScheduler extends LitElement {
|
|
|
167
167
|
|
|
168
168
|
updated(): void {
|
|
169
169
|
if (this.movedFocusInside) return;
|
|
170
|
-
if (
|
|
170
|
+
if (placeFocusInside(this)) {
|
|
171
171
|
this.movedFocusInside = true;
|
|
172
172
|
return;
|
|
173
173
|
}
|
|
@@ -17,7 +17,7 @@ import {
|
|
|
17
17
|
} from "../LeadSourceMultitouchClient";
|
|
18
18
|
|
|
19
19
|
import { getOfficeHourText } from "../OfficeHours";
|
|
20
|
-
import {
|
|
20
|
+
import { placeFocusInside, trapTabInside } from "../pubnub-chat";
|
|
21
21
|
import {
|
|
22
22
|
formatToUsPhoneInput,
|
|
23
23
|
isModifierKey,
|
|
@@ -47,13 +47,6 @@ export class CallUsWindow extends LitElement {
|
|
|
47
47
|
trapTabInside(event, this);
|
|
48
48
|
};
|
|
49
49
|
|
|
50
|
-
private movedFocusInside = false;
|
|
51
|
-
|
|
52
|
-
updated(): void {
|
|
53
|
-
if (this.movedFocusInside) return;
|
|
54
|
-
if (focusFirstTabStop(this)) this.movedFocusInside = true;
|
|
55
|
-
}
|
|
56
|
-
|
|
57
50
|
static styles = [
|
|
58
51
|
InputStyles,
|
|
59
52
|
css`
|
|
@@ -225,7 +218,18 @@ export class CallUsWindow extends LitElement {
|
|
|
225
218
|
| { dayOfWeek: string; startTime: string; endTime: string }
|
|
226
219
|
)[] = [];
|
|
227
220
|
|
|
221
|
+
// Focus moves in once, on open, after details-window has drawn the controls.
|
|
228
222
|
firstUpdated = async (): Promise<void> => {
|
|
223
|
+
await this.renderRoot.querySelector<LitElement>("details-window")
|
|
224
|
+
?.updateComplete;
|
|
225
|
+
if (this.isConnected) {
|
|
226
|
+
placeFocusInside(
|
|
227
|
+
this,
|
|
228
|
+
this.renderRoot.querySelector<HTMLElement>(
|
|
229
|
+
"#call-us-window__content-wrapper"
|
|
230
|
+
)
|
|
231
|
+
);
|
|
232
|
+
}
|
|
229
233
|
if (!this.buildingId || !this.hasCallUsEnabled) return;
|
|
230
234
|
this.officeHoursTextInfo = await getOfficeHourText(this.buildingId);
|
|
231
235
|
};
|
|
@@ -14,7 +14,7 @@ import axios from "axios";
|
|
|
14
14
|
import { FeatureFlagsShowDropdown } from "../../fetchFeatureFlag";
|
|
15
15
|
import { pushGtmEvent } from "../../gtm";
|
|
16
16
|
import formDisclaimer from "../../disclaimers";
|
|
17
|
-
import {
|
|
17
|
+
import { placeFocusInside, trapTabInside } from "../pubnub-chat";
|
|
18
18
|
import { isMobile, isValidEmail, snakify } from "../../utils";
|
|
19
19
|
import LeadSourceClient, {
|
|
20
20
|
getDefaultLeadSourceAttribution,
|
|
@@ -47,11 +47,17 @@ export class EmailUsWindow extends LitElement {
|
|
|
47
47
|
trapTabInside(event, this);
|
|
48
48
|
};
|
|
49
49
|
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
50
|
+
// Focus moves in once, on open. The fields render inside details-window, which draws
|
|
51
|
+
// after this element's first update, so wait for it. Later renders (every keystroke)
|
|
52
|
+
// never move focus.
|
|
53
|
+
async firstUpdated(): Promise<void> {
|
|
54
|
+
await this.renderRoot.querySelector<LitElement>("details-window")
|
|
55
|
+
?.updateComplete;
|
|
56
|
+
if (!this.isConnected) return;
|
|
57
|
+
placeFocusInside(
|
|
58
|
+
this,
|
|
59
|
+
this.renderRoot.querySelector<HTMLElement>("#email-us-form")
|
|
60
|
+
);
|
|
55
61
|
}
|
|
56
62
|
|
|
57
63
|
static styles = [
|
|
@@ -1079,6 +1079,20 @@ export function focusFirstTabStop(container: HTMLElement): boolean {
|
|
|
1079
1079
|
return true;
|
|
1080
1080
|
}
|
|
1081
1081
|
|
|
1082
|
+
/**
|
|
1083
|
+
* Move focus into an overlay, to the first control in `preferred` when it has one.
|
|
1084
|
+
* Leaves focus alone when the person is already on a control inside the overlay.
|
|
1085
|
+
*/
|
|
1086
|
+
export function placeFocusInside(
|
|
1087
|
+
container: HTMLElement,
|
|
1088
|
+
preferred?: HTMLElement | null
|
|
1089
|
+
): boolean {
|
|
1090
|
+
const active = activeElementInside(container);
|
|
1091
|
+
if (active && active !== container) return true;
|
|
1092
|
+
if (preferred && focusFirstTabStop(preferred)) return true;
|
|
1093
|
+
return focusFirstTabStop(container);
|
|
1094
|
+
}
|
|
1095
|
+
|
|
1082
1096
|
/** Wrap Tab inside container when focus is already in it. No effect otherwise. */
|
|
1083
1097
|
export function trapTabInside(
|
|
1084
1098
|
event: KeyboardEvent,
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import { expect } from "@esm-bundle/chai";
|
|
2
|
+
import { sendKeys, sendMouse } from "@web/test-runner-commands";
|
|
3
|
+
import "../public/dist/index";
|
|
4
|
+
import type { EmailUsWindow } from "./WebComponent/actions/email-us-window";
|
|
5
|
+
import type { Launcher } from "./WebComponent/launcher/Launcher";
|
|
6
|
+
|
|
7
|
+
declare const afterEach: (callback: () => void) => void;
|
|
8
|
+
|
|
9
|
+
const deepestActive = (): Element | null => {
|
|
10
|
+
let active: Element | null = document.activeElement;
|
|
11
|
+
while (active?.shadowRoot?.activeElement) {
|
|
12
|
+
active = active.shadowRoot.activeElement;
|
|
13
|
+
}
|
|
14
|
+
return active;
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
// Compare labels, not elements: a failed equal on DOM nodes stalls chai's output.
|
|
18
|
+
const label = (el: Node | null): string =>
|
|
19
|
+
el instanceof Element
|
|
20
|
+
? `${el.tagName.toLowerCase()} ${
|
|
21
|
+
el.getAttribute("placeholder") ?? el.getAttribute("aria-label") ?? ""
|
|
22
|
+
}`.trim()
|
|
23
|
+
: String(el);
|
|
24
|
+
|
|
25
|
+
const settle = (): Promise<void> =>
|
|
26
|
+
new Promise((resolve) => setTimeout(resolve, 50));
|
|
27
|
+
|
|
28
|
+
// Open the overlay the way a visitor does, through the launcher, which also wires
|
|
29
|
+
// the window's Close button.
|
|
30
|
+
const openFromLauncher = async (
|
|
31
|
+
open: (launcher: Launcher) => void,
|
|
32
|
+
tag: string
|
|
33
|
+
): Promise<HTMLElement> => {
|
|
34
|
+
const eliseWindow = window as unknown as {
|
|
35
|
+
eliseAi?: Record<string, unknown>;
|
|
36
|
+
};
|
|
37
|
+
eliseWindow.eliseAi = eliseWindow.eliseAi ?? {};
|
|
38
|
+
const launcher = document.createElement("meetelise-launcher") as Launcher;
|
|
39
|
+
document.body.appendChild(launcher);
|
|
40
|
+
await launcher.updateComplete;
|
|
41
|
+
open(launcher);
|
|
42
|
+
await launcher.updateComplete;
|
|
43
|
+
await settle();
|
|
44
|
+
const overlay = launcher.shadowRoot?.querySelector<HTMLElement>(tag);
|
|
45
|
+
if (!overlay) throw new Error(`no ${tag}`);
|
|
46
|
+
return overlay;
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
const openEmailWindow = (): Promise<EmailUsWindow> =>
|
|
50
|
+
openFromLauncher(
|
|
51
|
+
(launcher) => launcher.onClickEmailOption(new MouseEvent("click")),
|
|
52
|
+
"email-us-window"
|
|
53
|
+
) as Promise<EmailUsWindow>;
|
|
54
|
+
|
|
55
|
+
const field = (emailUs: EmailUsWindow, selector: string): HTMLInputElement => {
|
|
56
|
+
const input = emailUs.shadowRoot?.querySelector<HTMLInputElement>(selector);
|
|
57
|
+
if (!input) throw new Error(`no ${selector}`);
|
|
58
|
+
return input;
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
afterEach(() => {
|
|
62
|
+
document.querySelectorAll("meetelise-launcher").forEach((el) => el.remove());
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
it("puts focus on the first name field when the email window opens", async () => {
|
|
66
|
+
const emailUs = await openEmailWindow();
|
|
67
|
+
|
|
68
|
+
expect(label(deepestActive())).to.equal(
|
|
69
|
+
label(field(emailUs, 'input[placeholder="First name"]'))
|
|
70
|
+
);
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
it("keeps focus in the field the person clicked and is typing in", async () => {
|
|
74
|
+
const emailUs = await openEmailWindow();
|
|
75
|
+
const email = field(emailUs, 'input[type="email"]');
|
|
76
|
+
const box = email.getBoundingClientRect();
|
|
77
|
+
|
|
78
|
+
await sendMouse({
|
|
79
|
+
type: "click",
|
|
80
|
+
position: [Math.round(box.x + 10), Math.round(box.y + box.height / 2)],
|
|
81
|
+
});
|
|
82
|
+
await sendKeys({ type: "jo@example.com" });
|
|
83
|
+
await settle();
|
|
84
|
+
|
|
85
|
+
expect(label(deepestActive())).to.equal(label(email));
|
|
86
|
+
expect(email.value).to.equal("jo@example.com");
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
it("moves focus into the call window when it opens", async () => {
|
|
90
|
+
const callUs = await openFromLauncher(
|
|
91
|
+
(launcher) => launcher.onClickPhoneOption(new MouseEvent("click")),
|
|
92
|
+
"call-us-window"
|
|
93
|
+
);
|
|
94
|
+
|
|
95
|
+
let node: Node | null = deepestActive();
|
|
96
|
+
while (node && node !== callUs) {
|
|
97
|
+
node = node instanceof ShadowRoot ? node.host : node.parentNode;
|
|
98
|
+
}
|
|
99
|
+
expect(node === callUs, `focus is on ${label(deepestActive())}`).to.equal(
|
|
100
|
+
true
|
|
101
|
+
);
|
|
102
|
+
});
|