perf(SegmentedControl): replace :has(+ [data-selected]) divider rule with adjacent-sibling selector#7903
Draft
mattcosta7 wants to merge 2 commits into
Draft
perf(SegmentedControl): replace :has(+ [data-selected]) divider rule with adjacent-sibling selector#7903mattcosta7 wants to merge 2 commits into
:has(+ [data-selected]) divider rule with adjacent-sibling selector#7903mattcosta7 wants to merge 2 commits into
Conversation
…with adjacent-sibling selector
🦋 Changeset detectedLatest commit: 83d8e52 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
Contributor
|
13 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #
Replaces the
&:has(+ [data-selected])::afterselector that hid the inter-item divider sitting just before the selected item. Previously the engine had to re-test a sibling-direction:has()against every.Itemon every selection change.Approach: flip the divider's side.
Drawing the divider on the leading edge of each non-first item (rather than the trailing edge of each non-last item) makes "the divider next to the selected item" expressible as adjacent-sibling combinators only:
The same 1px line lives in the same gap between any two adjacent items — visually identical. The hide rules become two plain combinator selectors that the engine resolves in constant time per-element on a selection change, with no
:has()walk.The companion
.Button:focus:focus-visible:not(:last-child)::afterrule a few lines below is a pre-existing no-op on.Button::after(which has nocontent) and is left alone; it never targeted.Item::after.Changelog
Changed
SegmentedControlinter-item divider is drawn on.Item::beforeof each non-first item instead of.Item::afterof each non-last item.Removed
&:has(+ [data-selected])::afterselector fromSegmentedControl.module.css.Rollout strategy
Testing & Reviewing
packages/react/src/SegmentedControl/**unit tests pass.tsc --noEmitonpackages/reactis clean.VRT expectations: None. The divider's geometry is unchanged — same 1px line at the same horizontal position, just attached to the item on its right rather than the item on its left. Hide-on-selection behavior is bit-identical (selected item and its trailing neighbour both lose their leading divider, mirroring the previous "item before selected + selected both lose their trailing divider").
Part of the
:has()-reduction series: see also #7901 (PageHeader) and #7902 (ActionList SubGroup active indicator).Merge checklist