perf(SelectPanel v2): replace :has(input:placeholder-shown) with data-empty attribute#7904
Draft
mattcosta7 wants to merge 2 commits into
Draft
perf(SelectPanel v2): replace :has(input:placeholder-shown) with data-empty attribute#7904mattcosta7 wants to merge 2 commits into
:has(input:placeholder-shown) with data-empty attribute#7904mattcosta7 wants to merge 2 commits into
Conversation
🦋 Changeset detectedLatest commit: edbd214 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
|
TextInput spreads unknown props onto the inner <input> rather than the .TextInput wrapper, so the data attribute landed on the input element. Use a general-sibling combinator from the input to the clear-action span (which sits later in the wrapper).
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(input:placeholder-shown) :global(.TextInput-action)selector that hid the clear-action button when the search input is empty. The previous selector forced a descendant:has()evaluation on every keystroke (placeholder-shown toggles with each character typed/deleted), and the inner:global(.TextInput-action)selector required descendant matching across the whole TextInput subtree.Approach: track the empty state in React state on the
SelectPanelSearchInputcomponent, derive anisEmptyvalue, and pass it through asdata-emptyon the renderedTextInputwrapper. The CSS now matches a plain attribute on the same.TextInputelement.The controlled/uncontrolled cases are both handled:
valueprop provided),isEmptyis derived from the prop directly so it stays in sync without an effect.uncontrolledEmptystate.Changelog
New
data-emptyattribute onSelectPanel.SearchInputwhen the search input is empty.Changed
SelectPanel.module.cssclear-action visibility no longer uses:has(input:placeholder-shown).Removed
&:has(input:placeholder-shown)selector fromSelectPanel.module.css.Rollout strategy
Testing & Reviewing
packages/react/src/experimental/SelectPanel2/**unit tests pass.tsc --noEmitonpackages/reactis clean.content-visibilitybrowser-compat warning at line 87, unrelated).VRT expectations: None. The clear-action button is shown/hidden under identical conditions as before — when the input is empty, it's hidden; otherwise, it's shown. The only behavioral difference is timing: the previous
:has(input:placeholder-shown)updated on the browser's:placeholder-shownflip (which happens on the same frame as the input event), while the newdata-emptyflips on the React commit that follows the change event. In practice both update in the same animation frame and the user can't observe the difference.Part of the
:has()-reduction series: #7901 (PageHeader), #7902 (ActionList SubGroup), #7903 (SegmentedControl divider).Merge checklist