-
-
Notifications
You must be signed in to change notification settings - Fork 9
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
Set positions via CSS custom properties instead of directly on target elements. #51
Conversation
✅ Deploy Preview for anchor-polyfill ready!
To edit notification comments on pull requests, go to your Netlify site settings. |
@mirisuzanne @jerivas Since Sana and Olu are out, would the two of you be willing to review this PR sometime? Not urgent, of course. |
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.
This looks really hard but works really well 👍 Glad the polyfill now leverages the cascade
❌ Deploy Preview for anchor-position-wpt failed.
|
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.
Love this approach, and the functionality looks great. Nice work! I remember some discussion about shorter UUIDs in the custom props? That's not urgent, but it would look nicer.
Yep! That's coming in the next PR... #52 |
* main: do not warn on TS version chore(deps): Automated dependency upgrades
Description
Before, we were calculating positions and then setting them directly via
targetElement.style.setProperty(...)
. This isn't ideal for two reasons:anchor()
call from the stylesheet is overridden by a different set of styles?anchor
function, e.g.top: calc(anchor(--my-anchor 100%) - 50px);
.With the changes in this PR, we are now replacing uses of
anchor()
with a unique generated CSS custom property directly in the stylesheet, and then after we calculate the position value we simply assign that pixel value to the relevant CSS custom property. This way we can allow CSS itself to handle the cascade, and any relevant math.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).
View the demo and confirm that the examples still work (including the new "used in math function" example).