Skip to content

Commit 441b46f

Browse files
silverwindclaude
andcommitted
docs: add part="text" styling section to README and test for aria-hidden coexistence
Document the shadow DOM `part="text"` attribute in a new Styling section with a CSS `::part()` usage example. Add test coverage verifying `part="text"` is preserved when `aria-hidden="true"` is also set. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent f14f195 commit 441b46f

2 files changed

Lines changed: 23 additions & 0 deletions

File tree

README.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,17 @@ Lang is a [built-in global attribute](https://developer.mozilla.org/en-US/docs/W
284284

285285
Adding the `no-title` attribute will remove the `title` attribute from the `<relative-time>` element. The `title` attribute is inaccessible to screen reader and keyboard users, so not adding a title attribute allows a user to create a custom, accessible tooltip if one is desired.
286286

287+
## Styling
288+
289+
The element renders its text inside a Shadow DOM `<span>` with a [`part="text"`](https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/part) attribute. This allows you to style the displayed text from outside the shadow root using the `::part()` CSS pseudo-element:
290+
291+
```css
292+
relative-time::part(text) {
293+
color: rebeccapurple;
294+
font-weight: bold;
295+
}
296+
```
297+
287298
## Browser Support
288299

289300
Browsers without native [custom element support][support] require a [polyfill][ce-polyfill].

test/relative-time.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2143,6 +2143,18 @@ suite('relative-time', function () {
21432143
const span = time.shadowRoot.querySelector('span')
21442144
assert.equal(span.getAttribute('part'), 'text')
21452145
})
2146+
2147+
test('shadow root span has part="text" alongside aria-hidden="true"', async () => {
2148+
const now = new Date().toISOString()
2149+
const time = document.createElement('relative-time')
2150+
time.setAttribute('datetime', now)
2151+
time.setAttribute('aria-hidden', 'true')
2152+
await Promise.resolve()
2153+
2154+
const span = time.shadowRoot.querySelector('span')
2155+
assert.equal(span.getAttribute('part'), 'text')
2156+
assert.equal(span.getAttribute('aria-hidden'), 'true')
2157+
})
21462158
})
21472159

21482160
suite('legacy formats', function () {

0 commit comments

Comments
 (0)