-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Fix button group stacking context #7441
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: develop
Are you sure you want to change the base?
Conversation
Generate changelog in
|
apply same fix as control groupBuild artifact links for this commit: documentation | landing | table | demoThis is an automated comment from the deploy-preview CircleCI job. |
lint?Build artifact links for this commit: documentation | landing | table | demoThis is an automated comment from the deploy-preview CircleCI job. |
@@ -44,6 +44,9 @@ Styleguide button-group | |||
.#{$ns}-button-group { | |||
display: inline-flex; | |||
|
|||
// fresh stacking context for z-indexes applied below | |||
z-index: 0; |
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.
The button group is positioned static
by default, so should we also provide a position: relative
here? Otherwise, in a vacuum, this z-index
won't have an effect:

If the button group is a child element of a flexbox parent, however, it does apply. I'm a little fuzzy on the spec here, but I believe this has something to do with flex item z-ordering.
Here's a quick comparison: https://codesandbox.io/p/sandbox/q4v2ch
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.
oh great catch here!
is the assumption that this is safe to do because consumers that rely on the current static
position should not have set something like left: 100px
since it would not make any impact with the current static
position unless they have already specified an explicit position?
also wondering if somehow BP classes are weaker selectors than user styles - ex could this wipe out a user defined position: absolute
I hadn't heard of it but from looking at the MDN stacking context docs isolation: isolate
seems like exactly what we want - any thoughts on that?
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.
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.
also wondering if somehow BP classes are weaker selectors than user styles - ex could this wipe out a user defined
position: absolute
Hm, I'm not as worried about this since we're fixing an existing buggy behavior in the process, but it is a fair point.
I hadn't heard of it but from looking at the MDN stacking context docs isolation: isolate seems like exactly what we want - any thoughts on that?
I've only ever used isolation
for purposes related to isolating elements from mix-blend-mode
, but I don't see why we couldn't use it for z-index
also. I suppose, as you've said, the benefit here is that there is much less chance of inadvertently overriding user styles. I'm on board with that! Suggest also adding an explainer comment to clarify intent.
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.
I suppose we already do it for control groups but any concerns about suddenly creating a new stacking context (which I believe creates a new render layer) suddenly introducing perf issues if many button groups are used?
I think isolating the stacking context is needed in some way unless BP takes a global approach to z-indexes, but it might be safer to do in a major version with an opt-out available to avoid creating a stacking context. I don't have a gauge on if it could become an issue at 100 or 10k or if this isn't a concern at all really.
Fixes #7440
Checklist
Changes proposed in this pull request:
Reset stacking context of button group component
Reviewers should focus on:
Could this unintentionally override any consumer land styling?
Screenshot
This PR ended up using the
translateZ(0)
method to reset the stacking context like we do for control groups but anything that resets the stacking context should be valid.