Popup: zIndex is not applied in v2
Bug Report
Steps
Originally we have a Popup inside a Modal. On hover the Popup will not show up.
Expected Result
Should behave as in 1.3.1.
Actual Result
Popup is behind the Modal.
Version
2.0.0
Testcase => Reason
The

The class is set one level below the outer div and the z-Index (1900) is no longer able to move the Popop contents above the modal.
👋 Thanks for opening your first issue here! If you're reporting a 🐞 bug, please make sure you've completed all the fields in the issue template so we can best help.
We get a lot of issues on this repo, so please be patient and we will get back to you as soon as we can.
@JMS-1 thanks for reporting this, this is a definitely valid issue. This change is a part of #3947:
https://github.com/Semantic-Org/Semantic-UI-React/blob/1fbeed912c80037b07201f37973f2d96fcd933b9/src/modules/Popup/Popup.js#L178-L182
It was done to avoid positioning issues with Popper.js as margins on containers are not handled anymore. As we don't control styles on our side we cannot simply remove margins (it also related to arrow positioning) 💥
Sorry for this unobvious change, I didn't take that it can affect apps... However, I tried different options before and I don't have a better solution there.
- I will upgrade the migration guide and PR description to mention this issue.
- I will added a shorthand prop (probably
unstable_container) to allow customize classes and styles on that top leveldiv:
<Popup unstable_container={{ className: 'foo', data-id: 'container', style: { zIndex: 10000 } }} />
Will it work for you?
Actually on first thought using Popup in Modal seems not be so rare - Modal for some Input Form, Popup for errors therein - so the solution seems to be a bit strange.
But indeed I think we have only few places and could live with it. I would have done something like this in CSS IF the container div hat at lease ANY class attached to ist but it hasn't. In F12 developer mode z-index: 1000 did the job.
So to summarize: yes, this will work for us. But it feels wrong (sorry) and personally I would prefer to have some class on the container IF this is possible (even data- would do) but as I understand this isn't.
Thanks
Jochen
PS: Thought by the side: why not putting an ADDITIONAL own div (absolute/0/0) around the container?
Any way to supply a class/style for parent will do. But don't give it a name of unstable as I'm not supposed to know about it's real nature.
The issue reproduces in many examples in my app which are not related to Modals.
Tooltip in a menu dropdown

Page inside a Pusher (part of SideBar component) which has z-index by default.
Looks like in previous popup version, the popup (it has a large z-index, 1900) class was the root of the popup portal, and not it is a child of some container.

Simple solution is to add the z-index to the wrapper it self.
I've patched locally my semantic-ui with
popperStyle = _extends({zIndex: 1900}, popperStyle);
In here: https://github.com/Semantic-Org/Semantic-UI-React/blob/1fbeed912c80037b07201f37973f2d96fcd933b9/src/modules/Popup/Popup.js#L177
And it solved the issue.
Do you think it's a good idea to have the z-Index in code? Wouldn't it be better to add some (new?) class and style the z-Index in?
It may be good enough to add .ui.popup to this div, it will definitely solve the problem
Do you think it's a good idea to have the z-Index in code? Wouldn't it be better to add some (new?) class and style the z-Index in?
The problem is that the this lib (React version of SUI) can't make changes in the CSS... it just relays on the original styles.
It may be good enough to add .ui.popup to this div, it will definitely solve the problem
I think that the comment here https://github.com/Semantic-Org/Semantic-UI-React/blob/1fbeed912c80037b07201f37973f2d96fcd933b9/src/modules/Popup/Popup.js#L178-L182 is the reason why this won't work.
Popup has properties popperDependencies and popperModifiers. Maybe there is some way to add popperStyle?
and popperClassName
Just to clarify, this change is a part of 2.0.0 and there is no any bugfixes or features that can force you to upgrade.
Why additional div is required?
Popper.js v2 requires to not have margins, but SUI defines them on .popup and they are also used to position a pointing beak:

I tried few options that came to my mind, but all of them were overcomplicated. Having an additional wrapping div is the most simple solution and it's used for positioning now.
Popuphas propertiespopperDependenciesandpopperModifiers. Maybe there is some way to addpopperStyle?
This will now scale as at some point it may be useful to add a data attribute, for example. Having a slot seems more reasonable for me and it's aligned with our API.
<Popup unstable_container={{ className: 'foo', data-id: 'container', style: { zIndex: 10000 } }} />
<Popup container={{ className: 'foo', data-id: 'container', style: { zIndex: 10000 } }} />
<Popup popper={{ className: 'foo', data-id: 'container', style: { zIndex: 10000 } }} />
@felixmosh I am thinking about syncing zIndex value between a container and .popup element:
componentDidMount() {
this.syncZIndex()
}
componentDidUpdate() {
this.syncZIndex()
}
syncZIndex() {
// if it's defined in <Popup popper={{ style: {} }} /> there is no sense to override it
if (_.isUndefined(this.props.popper.style.zIndex)) {
this.popperRef.style.zIndex = window.getComputedStyle(this.popupRef).zIndex
}
}
Since the value is hard coded in the css, there is no need to sync it. Just add it to the proper styles as I suggested in my PR.
@felixmosh it can be the first iteration, however the issue that zIndex is not hardcoded, it's a variable in LESS so technically someone can have a different value:
z-index: @zIndex;
https://github.com/Semantic-Org/Semantic-UI/blob/master/src/definitions/modules/popup.less#L34
IMO, at least we should sync the initial value in componentDidMount().
Agree with syncing it in componentDidMount
Hello everyone. Have workaround?
Hello everyone. Have workaround?
https://github.com/Semantic-Org/Semantic-UI-React/issues/4083#issuecomment-703237102
@felixmosh Can we without fork?. Because i don't want to do fork
@sergeu90 I'm using patch-package in order to make a patch for the lib.
It allows you to modify the files in node_modules and save a patch file of this modification. At the end it will apply the patch each time you install dependency.