-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Use CSS instead of JavaScript for floating warning #2408
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
base: main
Are you sure you want to change the base?
Conversation
Some of the functionality of the floating warning on unsupported and in-development documentation versions was implemented using JavaScript. This is longer necessary if we use the following approach with modern CSS: Attach the warning element the top of the page with `position: sticky`. This almost solves the problem, but we still have to scroll past header elements when an internal page link is clicked. This is achieved with a combination of the `:has` pseudo-class and the `scroll-margin-top` property. We apply `scroll-margin-top` to elements that can be scrolled to by their `id` attribute. This is done with responsive breakpoints to get appropriate spacing when the floating warning has one, two, or three lines of text. Thanks to `:has`, this only happens when a warning element is on the page. The modern CSS features used are widely-supported: - https://caniuse.com/css-has - https://caniuse.com/css-sticky - https://caniuse.com/mdn-css_properties_scroll-margin-top Other than making the primary CSS changes and removing the related JavaScript, this patch does the following: - Simplify the CSS so that the class on all floating warning elements implements the common rules and the CSS for the IDs on the elements implements the colors - Add a `z-index` to warning elements so that they always display in front of the header element - Move the floating warning element to the top of the page in the HTML - Remove the `body_extra` block that was only being used by the floating warning element - Add a new `before_header` block for the floating warning element Thank you to Baptiste Mispelon and Thibaud Colas for helping me arrive at this solution.
| #outdated-warning { | ||
| position: absolute; | ||
| @include respond-max(674px) { | ||
| body:has(.doc-floating-warning) [id] { |
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.
[id] feels too generic here, but I can't think of a downside. I think we'd want any element that can be scrolled to to be affected.
pauloxnet
left a comment
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.
LGTM
This change restores the previous behavior.
|
@sarahboyce Thank you! I overlooked the behavior change at mobile width. It should be addressed in 33ba68d. |
sarahboyce
left a comment
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.
Thank you! This looks great ⭐

This PR fixes #1988 and is a second attempt at #1799. This comment by @thibaudcolas was especially helpful in arriving at this implementation.
Some of the functionality of the floating warning on unsupported and in-development documentation versions was implemented using JavaScript. This is longer necessary if we use the following approach with modern CSS:
Attach the warning element the top of the page with
position: sticky. This almost solves the problem, but we still have to scroll past header elements when an internal page link is clicked. This is achieved with a combination of the:haspseudo-class and thescroll-margin-topproperty.We apply
scroll-margin-topto elements that can be scrolled to by theiridattribute. This is done with responsive breakpoints to get appropriate spacing when the floating warning has one, two, or three lines of text. Thanks to:has, this only happens when a warning element is on the page.The modern CSS features used are widely-supported:
Other than making the primary CSS changes and removing the related JavaScript, this patch does the following:
z-indexto warning elements so that they always display in front of the header elementbody_extrablock that was only being used by the floating warning elementbefore_headerblock for the floating warning elementThank you to @bmispelon and @thibaudcolas for helping me arrive at this solution.
To test this PR: