-
Notifications
You must be signed in to change notification settings - Fork 814
Fix stacking with Stack component, StackingContext and React 16.3 #187
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
Closed
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Rowno
suggested changes
Apr 24, 2018
| position="absolute" | ||
| top="50%" | ||
| zIndex={3} | ||
| zIndex={StackingOrder.FOCUSED + 1} |
Contributor
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.
Why +1?
| /** | ||
| * Set the value of the stack. This will increment for children. | ||
| */ | ||
| value: PropTypes.number |
Contributor
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.
Shouldn't value be required?
const currentValue = Math.max(undefined, previousValue)
const nextValue = currentValue + 1
nextValue === NaN
Rowno
approved these changes
Apr 24, 2018
Merged
Contributor
Author
|
This is in v4. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
This PR makes use of the
createContextAPI in React 16.3.0 to allow automatic stacking of components.This is a breaking change and will have to be released as v4.
Changes
createContextAPIStackingContextfromevergreen-uiStackcomponent fromevergreen-uiStackingOrderobject with z-index presets fromevergreen-ui.zIndexprops from Popover, Combobox and Positioner.StackingContext
The StackingContext is a React context with a default value (z-index) of
10. The StackingContext is currently only used within theStackcomponent within Evergreen.Stack component
The Stack component uses the StackingContext which accepts a function as children. That function takes in the zIndex and should return a React node:
Inside of the render function the Stack component first looks for the current value. Passing a value to the component will make sure the highest of the two are used. This is useful because Overlays start at a
z-indexof 20. See more info below aboutStackingOrder. The Stack component will pass the current value to the current children, and increment the value for the next consumer.Stack component usage
In most cases Stack will be an internal component, we are exposing it if you want to build custom components on top of this logic.
StackingOrder
The values here are somewhat random, the reason why POSITIONER and OVERLAY are 10 apart is that in between the Stack component can increment the z-index — giving a head room of 10 z-indexes.
See Example
I tweeted about this with a video attached. Click the link below to see.
Stuff that came up
When I was doing this PR, I realized there is an issue with the
getPositionfor thePositionerthat creates an infinite loop when there is not enough space on the top or the bottom of the screen. I will fix this outside of the scope of this PR so it will be included inv3as well.Another issue that arose from creating examples is when a Popover contains a Combobox — which means another Popover. The Popover closes when trying to select an item from the Combobox. This is because the Popover inside the Popover does not live within the same tree. This should be fixed in a different PR as well.