WebKit Bugzilla
New
Browse
Log In
×
Sign in with GitHub
or
Remember my login
Create Account
·
Forgot Password
Forgotten password account recovery
NEW
234556
[:has() pseudo-class] Support for style invalidation with missing interactive pseudo-classes
https://bugs.webkit.org/show_bug.cgi?id=234556
Summary
[:has() pseudo-class] Support for style invalidation with missing interactive...
Lea Verou
Reported
2021-12-21 03:18:44 PST
:has() does not seem to match when the argument is an interactive pseudo-class (:focus, :checked, :target). I’m not sure it's an invalidation issue, because it doesn't apply even when the pseudo-class applies on startup (e.g. a pre-checked checkbox). Testcase:
https://codepen.io/leaverou/pen/KKXvqjG?editors=1100
(Huge thanks to everyone who made :has() happen — what an exciting time!)
Attachments
screenshot of has pseudo class bug
(227.10 KB, image/jpeg)
2021-12-28 07:45 PST
,
Brandon McConnell
no flags
Details
screenshot of has pseudo class bug #2
(205.36 KB, image/png)
2021-12-28 08:04 PST
,
Brandon McConnell
no flags
Details
View All
Add attachment
proposed patch, testcase, etc.
Antti Koivisto
Comment 1
2021-12-21 03:43:27 PST
Thanks for the report. Of these :focus should be working at least in basic cases. Changing .has.focus:has(:checked) to .has.focus:has(:focus) makes that subtest work as expected. The others are broken though.
Lea Verou
Comment 2
2021-12-21 03:46:28 PST
Oops! Fixed the testcase, thanks!
Lea Verou
Comment 3
2021-12-21 03:57:22 PST
Also updated the tests to include :valid, which behaves very oddly: :has(:valid) seems to match *regardless* of whether a valid control is actually contained within, and said matching doesn't change as descendant controls go from valid to invalid and vice versa.
Radar WebKit Bug Importer
Comment 4
2021-12-21 04:13:32 PST
<
rdar://problem/86763225
>
Antti Koivisto
Comment 5
2021-12-21 04:22:23 PST
Basically we need to use Style::PseudoClassChangeInvalidation around pseudo-class changes for them to invalidate correctly within :has().
Bill Criswell
Comment 6
2021-12-21 17:48:00 PST
I observed some interesting behavior too. This Sandbox helps explain the situation:
https://codesandbox.io/s/silly-gagarin-y0cub
Antti Koivisto
Comment 7
2021-12-23 04:25:11 PST
(In reply to Bill Criswell from
comment #6
)
> I observed some interesting behavior too. This Sandbox helps explain the > situation:
https://codesandbox.io/s/silly-gagarin-y0cub
That seems to work fine now after the latest fixes.
Brandon McConnell
Comment 8
2021-12-28 07:45:53 PST
Created
attachment 448043
[details]
screenshot of has pseudo class bug
Brandon McConnell
Comment 9
2021-12-28 07:46:47 PST
One unexpected side effect I'm seeing so far— it appears that :has sometimes matches for unmatching elements. The inspector doesn't show the styles but they appear on-page. Example URL:
https://codepen.io/brandonmcconnell/pen/45b67ffa16dc41614efdd140bef1f439
Example screenshot attached
Brandon McConnell
Comment 10
2021-12-28 08:00:06 PST
I have altered my example URL that I linked above to expand on the side effect I noticed. It appears that all three div's, even those that should not be matching are receiving the "has" styles for their own background-color, however, only the correct one receives styles once an additional pseudo-element is specified after the :has pseudo-selector.
Brandon McConnell
Comment 11
2021-12-28 08:04:42 PST
Created
attachment 448044
[details]
screenshot of has pseudo class bug #2 This new screenshot demonstrates the bug, where the "has" styles are visually inherited by elements that do not match the selector, but not their pseudo elements.
Brandon McConnell
Comment 12
2021-12-28 08:18:44 PST
Upon further investigation, this bug appears to occur during rendering, and if I comment the styles using the inspector and then un-comment then, the styles auto-correct themselves. I have recorded a Loom video demonstrating this:
https://www.loom.com/share/0cf9c18a99a8421f9957ff04c34f64de
This bug is critical to the use of :has() so this should be resolved before the :has() pseudo-class is released into the production browser.
Lea Verou
Comment 13
2021-12-28 10:18:10 PST
Brandon, could you please file a new bug so its status can be tracked separately?
Brandon McConnell
Comment 14
2021-12-28 14:25:30 PST
Bill / Lea / Antti — I will open a separate ticket for the concerns I raised.
Brandon McConnell
Comment 15
2021-12-28 14:43:50 PST
I opened two new tickets to account for the bugs I found:
Bug 234732
- [:has() pseudo-class] Styles matching non-matching elements on load
https://bugs.webkit.org/show_bug.cgi?id=234732
Bug 234733
- [:has() pseudo-class] Not matching elements it should
https://bugs.webkit.org/show_bug.cgi?id=234733
Adrian
Comment 16
2024-06-19 03:28:18 PDT
There's a similar issue with style invalidation when using interactive pseudo-classes (:checked, :focus, :invalid, :user-invalid) with :has within shadow DOM (both imperative and declarative). The styles apply on startup, but are not reapplied on subsequent state changes (e.g. checking and unchecking a checkbox). Test case at
https://codepen.io/adini/pen/qBGxydG
Note
You need to
log in
before you can comment on or make changes to this bug.
Top of Page
Format For Printing
XML
Clone This Bug