feat: expose part=root for external CSS targeting#341
feat: expose part=root for external CSS targeting#341siddharthkp merged 6 commits intogithub:mainfrom
part=root for external CSS targeting#341Conversation
Wrap shadow root content in a <span part="text"> so consumers can style the inner element via ::part(text), enabling ::selection and other non-inheritable CSS properties to work across shadow boundaries. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
There was a problem hiding this comment.
Pull request overview
This PR addresses Firefox-specific issues with text selection styling in shadow DOM by exposing a CSS part="text" attribute on the element's internal span. Firefox does not propagate custom ::selection styling into shadow DOM, so this change enables external CSS to target the element's text content using relative-time::part(text)::selection.
Changes:
- Modified the element to always render a root
<span>withpart="text"attribute in the shadow DOM - Updated tests to reflect that a span element is now always present
- Added test coverage to verify the
part="text"attribute exists
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| src/relative-time-element.ts | Refactored #updateRenderRootContent to always create a span element with part="text", rather than conditionally creating it only when aria-hidden is true |
| test/relative-time.js | Removed assertions checking for absence of span element, and added test suite for the new part attribute |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
…den 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>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
part=text for external CSS targetingpart=root for external CSS targeting
|
Thanks. I still think it's worth to pursue this change because as we know, Browser bugs can take years to be fixed. |
|
Sure, just closing the loop. |
|
@silverwind There's a failing test for you :) |
|
@siddharthkp it's a pre-existing flakyness on main branch, #342 will fix it. |
|
@silverwind Great! I've merged that in main and backmerged main here |
|
Thanks, branch should go green after latest main merge now. |
|
@siddharthkp for next merge, I suggest you merge with "squash" because you got some of the intermediate commits now on main. |
Resolves #259.
Firefox does not propagate custom
::selectionstyling into shadow DOM. To enable styling the selection color inside<relative-time>, expose arootpart which refers to the root<span>of the element which can then be targeted by CSS.The root
<span>now always renders, even in the absence ofaria-hidden, but that shouldn't cause any issues because Shadow DOM still encapsulates the content.Example before and after with this CSS: