Skip to content

Commit

Permalink
Update countdown text via Text#nodeValue
Browse files Browse the repository at this point in the history
**Why**: To restore previous behavior of screen reader atomic announcement including time remaining.
  • Loading branch information
aduth committed Mar 15, 2022
1 parent 4258680 commit 0c4c4e9
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion app/javascript/packages/countdown-element/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,14 @@ export class CountdownElement extends HTMLElement {
return this.getAttribute('data-start-immediately') === 'true';
}

get #textNode(): Text {
if (!this.firstChild) {
this.appendChild(this.ownerDocument.createTextNode(''));
}

return this.firstChild as Text;
}

start(): void {
this.stop();
this.setTimeRemaining();
Expand All @@ -54,7 +62,7 @@ export class CountdownElement extends HTMLElement {
setTimeRemaining(): void {
const { timeRemaining } = this;

this.textContent = [
this.#textNode.nodeValue = [
t('datetime.dotiw.minutes', { count: Math.floor(timeRemaining / 60000) }),
t('datetime.dotiw.seconds', { count: Math.floor(timeRemaining / 1000) % 60 }),
].join(t('datetime.dotiw.two_words_connector'));
Expand Down

0 comments on commit 0c4c4e9

Please sign in to comment.