8000 Support aria-hidden · github/relative-time-element@f1c6b2e · GitHub
[go: up one dir, main page]

Skip to content

Commit 8000 f1c6b2e

Browse files
committed
Support aria-hidden
1 parent 8e59fda commit f1c6b2e

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

examples/index.html

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,12 @@ <h2>Localised Dates</h2>
200200
</relative-time>
201201
</p>
202202

203+
<p>
204+
With aria-hidden
205+
<relative-time aria-hidden="true" datetime="1970-01-01T00:00:00.000Z" format="datetime">
206+
Jan 1 1970
207+
</relative-time>
208+
</p>
203209
<!-- <script type="module" src="../dist/index.js"></script> -->
204210
<script type="module" src="https://unpkg.com/@github/relative-time-element@latest/dist/bundle.js"></script>
205211
<script>

src/relative-time-element.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -459,10 +459,14 @@ export class RelativeTimeElement extends HTMLElement implements Intl.DateTimeFor
459459
}
460460

461461
if (newText) {
462-
this.#renderRoot.textContent = newText
462+
if (this.hasAttribute('aria-hidden') && this.getAttribute('aria-hidden') === 'true') {
463+
(this.#renderRoot as Element).innerHTML = `<span aria-hidden="true">${newText}</span>`;
464+
} else {
465+
this.#renderRoot.textContent = newText;
466+
}
463467
} else if (this.shadowRoot === this.#renderRoot && this.textContent) {
464468
// Ensure invalid dates fall back to lightDOM text content
465-
this.#renderRoot.textContent = this.textContent
469+
this.#renderRoot.textContent = this.textContent;
466470
}
467471

468472
if (newText !== oldText || newTitle !== oldTitle) {

0 commit comments

Comments
 (0)
0