Skip to content

Commit c82932a

Browse files
silverwindclaude
andcommitted
feat: rename part="text" to part="root"
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 08cd402 commit c82932a

3 files changed

Lines changed: 8 additions & 8 deletions

File tree

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -286,14 +286,14 @@ Adding the `no-title` attribute will remove the `title` attribute from the `<rel
286286

287287
## Styling
288288

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:
289+
The element renders its text inside a Shadow DOM `<span>` with a [`part="root"`](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:
290290

291291
```css
292-
relative-time::part(text) {
292+
relative-time::part(root) {
293293
color: rebeccapurple;
294294
font-weight: bold;
295295
}
296-
relative-time::part(text)::selection {
296+
relative-time::part(root)::selection {
297297
background: lightgreen;
298298
}
299299
```

src/relative-time-element.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,7 @@ export class RelativeTimeElement extends HTMLElement implements Intl.DateTimeFor
273273

274274
#updateRenderRootContent(content: string | null): void {
275275
const span = document.createElement('span')
276-
span.setAttribute('part', 'text')
276+
span.setAttribute('part', 'root')
277277
if (this.hasAttribute('aria-hidden') && this.getAttribute('aria-hidden') === 'true') {
278278
span.setAttribute('aria-hidden', 'true')
279279
}

test/relative-time.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2134,25 +2134,25 @@ suite('relative-time', function () {
21342134
})
21352135

21362136
suite('[part]', () => {
2137-
test('shadow root span has part="text"', async () => {
2137+
test('shadow root span has part="root"', async () => {
21382138
const now = new Date().toISOString()
21392139
const time = document.createElement('relative-time')
21402140
time.setAttribute('datetime', now)
21412141
await Promise.resolve()
21422142

21432143
const span = time.shadowRoot.querySelector('span')
2144-
assert.equal(span.getAttribute('part'), 'text')
2144+
assert.equal(span.getAttribute('part'), 'root')
21452145
})
21462146

2147-
test('shadow root span has part="text" alongside aria-hidden="true"', async () => {
2147+
test('shadow root span has part="root" alongside aria-hidden="true"', async () => {
21482148
const now = new Date().toISOString()
21492149
const time = document.createElement('relative-time')
21502150
time.setAttribute('datetime', now)
21512151
time.setAttribute('aria-hidden', 'true')
21522152
await Promise.resolve()
21532153

21542154
const span = time.shadowRoot.querySelector('span')
2155-
assert.equal(span.getAttribute('part'), 'text')
2155+
assert.equal(span.getAttribute('part'), 'root')
21562156
assert.equal(span.getAttribute('aria-hidden'), 'true')
21572157
})
21582158
})

0 commit comments

Comments
 (0)