-
-
Notifications
You must be signed in to change notification settings - Fork 13
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Patch qsa matches closest to accept :popover-open
#84
Conversation
patchSelectorFn(Element.prototype, 'matches', rewriteSelector); | ||
patchSelectorFn(Element.prototype, 'closest', rewriteSelector); | ||
patchSelectorFn( | ||
DocumentFragment.prototype, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ShadowRoot
inherits DocumentFragment
, and so patching DocumentFragment
also patches ShadowRoot
.
patchSelectorFn(Element.prototype, 'matches', rewriteSelector); | ||
patchSelectorFn(Element.prototype, 'closest', rewriteSelector); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
HTMLDocument
nor DocumentFragment
have matches
nor closest
. I think I have all functions that take CSS selectors here. Let me know if I missed one!
/cc @yinonov who did a lot of work on shadowroots here. What do you think of this change? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks fine to me, though happy for @yinonov to review if they have a chance.
Pausing this one for now as w3c/csswg-drafts#8637 may mean we need to change the pseudo selector to |
b7536c8
to
2e476df
Compare
:open
/:closed
:popover
✅ Deploy Preview for popover-polyfill ready!
To edit notification comments on pull requests, go to your Netlify site settings. |
2e476df
to
5a54158
Compare
Looks like w3c/csswg-drafts#8637 is moving forward with Chrome implementation for this is here: https://chromium-review.googlesource.com/c/chromium/src/+/4373888. We should also wait for this to land IMO. |
cf28b60
to
6289342
Compare
:popover
:popover-open
6289342
to
3a2446e
Compare
Upstream PRs have landed. |
This comment was marked as resolved.
This comment was marked as resolved.
* main: chore(deps): Automated dependency upgrades changelog return null if targetElement is present but disconnected refactor if statement Update popover.ts
A potentially controversial change.
By default running something like
el.matches(':open')
on a browser without native Popover will result in an exception:Chrome:
Firefox:
This means users of this polyfill need to work around this; either by using a
try
/catch
, or by doing feature detection up front, e.g.:This is a little cumbersome and has to be done for every selector you intend to use, and given we're patching prototype methods anyway, perhaps it could be useful for us to patch the CSS selector functions (I believe I have them all,
querySelector
,querySelectorAll
,matches
,closest
).This change patches all of those functions taking the selector string given and replacing instances of
:open
with.\\:open
and:closed
with:not(.\\:open)
. This allows us to use the:open
/:closed
selector and have it work with the polyfill.Steps to test/reproduce
Please explain how to best reproduce the issue and/or test the changes locally (including the pages/URLs/views/states to review).
Tests have been added to ensure qsa/matches/closed work but it doesn't do anything close to exhaustive input testing. I've manually tested the replacer function with various inputs. We could add some unit tests to ensure its robustness, but here's how I validated it:
Show me
Provide screenshots/animated gifs/videos if necessary.
REMEMBER: Attach this PR to the Trello card