Skip to content

Commit d58c364

Browse files
committed
feat: Remove 'interrupt' and update 'priority'’s values to align with latest spec
1 parent 23003e9 commit d58c364

File tree

3 files changed

+19
-68
lines changed

3 files changed

+19
-68
lines changed

ariaNotify-polyfill.js

Lines changed: 13 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -31,42 +31,19 @@ if (!("ariaNotify" in Element.prototype)) {
3131
/** @type {string} */
3232
message;
3333

34-
/** @type {"important" | "none"} */
35-
priority = "none";
36-
37-
/** @type {"all" | "pending" | "none"} */
38-
interrupt = "none";
39-
40-
/** @type {boolean} */
41-
get #shouldFlushOthers() {
42-
return this.interrupt === "all" || this.interrupt === "pending";
43-
}
34+
/** @type {"high" | "normal"} */
35+
priority = "normal";
4436

4537
/**
4638
* @param {object} message
4739
* @param {Element} message.element
4840
* @param {string} message.message
49-
* @param {"important" | "none"} message.priority
50-
* @param {"all" | "pending" | "none"} message.interrupt
41+
* @param {"high" | "normal"} message.priority
5142
*/
52-
constructor({ element, message, priority = "none", interrupt = "none" }) {
43+
constructor({ element, message, priority = "normal" }) {
5344
this.element = element;
5445
this.message = message;
5546
this.priority = priority;
56-
this.interrupt = interrupt;
57-
}
58-
59-
/**
60-
* Whether this message and the given message are equivalent.
61-
* @param {Message} message
62-
* @returns {boolean}
63-
*/
64-
matches(message) {
65-
return (
66-
this.element === message.element &&
67-
this.priority === message.priority &&
68-
this.interrupt === message.interrupt
69-
);
7047
}
7148

7249
/**
@@ -104,12 +81,6 @@ if (!("ariaNotify" in Element.prototype)) {
10481
/** @type {LiveRegionCustomElement | null} */
10582
let liveRegion = root.querySelector(liveRegionCustomElementName);
10683

107-
// Destroy 'live-region', if it exists and should be flushed
108-
if (this.#shouldFlushOthers && liveRegion) {
109-
liveRegion.remove();
110-
liveRegion = null;
111-
}
112-
11384
// Create (or recreate) 'live-region', if it doesn’t exist
11485
if (!liveRegion) {
11586
liveRegion = /** @type {LiveRegionCustomElement} */ (
@@ -136,22 +107,15 @@ if (!("ariaNotify" in Element.prototype)) {
136107
* @returns {void}
137108
*/
138109
enqueue(message) {
139-
const { priority, interrupt } = message;
140-
141-
if (interrupt === "all" || interrupt === "pending") {
142-
// Remove other messages with the same element, priority, and interrupt
143-
this.#queue = this.#queue.filter(
144-
(message) => !message.matches(message)
145-
);
146-
}
110+
const { priority } = message;
147111

148-
if (priority === "important") {
149-
// Insert after the last important message, or at the beginning
112+
if (priority === "high") {
113+
// Insert after the last high-priority message, or at the beginning
150114
// @ts-ignore: ts(2550)
151-
const lastImportantMessage = this.#queue.findLastIndex(
152-
(message) => message.priority === "important"
115+
const lastHighPriorityMessage = this.#queue.findLastIndex(
116+
(message) => message.priority === "high"
153117
);
154-
this.#queue.splice(lastImportantMessage + 1, 0, message);
118+
this.#queue.splice(lastHighPriorityMessage + 1, 0, message);
155119
} else {
156120
// Insert at the end
157121
this.#queue.push(message);
@@ -205,13 +169,12 @@ if (!("ariaNotify" in Element.prototype)) {
205169
/**
206170
* @param {string} message
207171
* @param {object} options
208-
* @param {"important" | "none"} [options.priority]
209-
* @param {"all" | "pending" | "none" } [options.interrupt]
172+
* @param {"high" | "normal"} [options.priority]
210173
*/
211174
Element.prototype["ariaNotify"] = function (
212175
message,
213-
{ priority = "none", interrupt = "none" } = {}
176+
{ priority = "normal" } = {}
214177
) {
215-
queue.enqueue(new Message({ element: this, message, priority, interrupt }));
178+
queue.enqueue(new Message({ element: this, message, priority }));
216179
};
217180
}

examples/index.html

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ <h2>Example components</h2>
5151
<h2>Playground</h2>
5252
<p>
5353
This playground allows you to queue a set of messages of different types, and then dispatch them all at once to see
54-
how priority and interrupt values effect the queue order.
54+
how priority effects the queue order.
5555
</p>
5656

5757
<template id="form">
@@ -61,19 +61,11 @@ <h2>Playground</h2>
6161
<span>Message:</span>
6262
<input type="text" name="message">
6363
</label>
64-
<label>
65-
<span>Interrupt:</span>
66-
<select name="interrupt">
67-
<option value="all">all</option>
68-
<option value="pending">pending</option>
69-
<option value="none" selected>none</option>
70-
</select>
71-
</label>
7264
<label>
7365
<span>Priority:</span>
7466
<select name="priority">
75-
<option value="important">important</option>
76-
<option value="none" selected>none</option>
67+
<option value="high">high</option>
68+
<option value="normal" selected>normal</option>
7769
</select>
7870
</label>
7971
<button type=button class="delete">Delete</button>
@@ -115,7 +107,6 @@ <h2>Playground</h2>
115107
const message = data.get('message')
116108
const opts = {
117109
priority: data.get('priority'),
118-
interrupt: data.get('interrupt'),
119110
};
120111
dispatch.ariaNotify(message, opts);
121112
}

examples/suggested-text/index.html

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -91,15 +91,13 @@
9191
*/
9292
suggester.addEventListener("MakeSuggestion", (event) => {
9393
suggester.ariaNotify(`Suggestion: ${event.word}`, {
94-
priority: "important",
95-
interrupt: "all",
94+
priority: "high"
9695
});
9796
clearTimeout(timer);
9897
timer = setTimeout(() => {
9998
suggester.ariaNotify("Press right arrow to commit suggestion", {
10099
notificationId: "application-keyboard-hint",
101-
priority: "none",
102-
interrupt: "all",
100+
priority: "normal"
103101
});
104102
}, 2000);
105103
suggester.addEventListener("keyup", () => clearTimeout(timer), {
@@ -109,8 +107,7 @@
109107
});
110108
suggester.addEventListener("Committed", (event) => {
111109
suggester.ariaNotify(event.word, {
112-
priority: "important",
113-
interrupt: "all",
110+
priority: "high"
114111
});
115112
});
116113
</script>

0 commit comments

Comments
 (0)