Cascade position-area with :where:not
#307
Closed
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.
Description
This is an alternate method of ensuring the correct value cascades in instances where multiple values for
position-areaapply to the same element.This should resolve to
enddue to specificity.In other parts of the polyfill, we can simply add properties to the same declaration blocks to ensure they cascade as expected. However,
position-arearequires us to add properties to a generated parent element of the selected element. This PR uses:where([parent]):not([original selector])to properly handle the cascade.The
:where()selects the specific element, and the:not()applies that rule with the same specificity of the original selector. The example above creates the following selectors-The alternate method, as implemented in #296, checks for a cascade winner each time the polyfill is updated. This requires an extra read and write of the DOM on each cycle, per target/position area combo. It also requires that we add an additional property to track the cascade. My initial impression is that this is a small impact relative to what the polyfill is already doing, but it would be convenient to simply rely on the cascade directly.
Related Issue(s)
#181
Steps to test/reproduce
In the demo, go to the Cascade example.
https://deploy-preview-307--anchor-polyfill.netlify.app/position-area#cascade
If you apply the polyfill, it will be positioned at
top right. If you reload the page, click the "Switch cascade button", and apply the polyfill, it will be positioned atbottom right.Caveats
position-area, though..cascade-overrideclass is no longer present in the document, but the:where([parent]):not(.cascade-override #cascade-target)selector still applies. Essentially this method picks the cascade winner of all the declarations that apply to elements that exist when the polyfill is initially applied.~ target,+ target,> targetor uses:nthselctors. (This applies to either approach due to the wrapping element)Note that the current diff doesn't include some cleanup that could happen to remove the other method.
Comparison with the original approach