Semantic-UI-React icon indicating copy to clipboard operation
Semantic-UI-React copied to clipboard

Popup: zIndex is not applied in v2

Open JMS-1 opened this issue 6 years ago • 30 comments

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

created as a popup container no longer has ANY classes, esp. not .ui.popup. Especially the z-index is not set.

popup1 popup2

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.

JMS-1 avatar Oct 02 '20 18:10 JMS-1

👋 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.

welcome[bot] avatar Oct 02 '20 18:10 welcome[bot]

@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.

  1. I will upgrade the migration guide and PR description to mention this issue.
  2. I will added a shorthand prop (probably unstable_container) to allow customize classes and styles on that top level div:
<Popup unstable_container={{ className: 'foo', data-id: 'container', style: { zIndex: 10000 } }} />

Will it work for you?

layershifter avatar Oct 03 '20 09:10 layershifter

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?

JMS-1 avatar Oct 03 '20 09:10 JMS-1

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.

gshilin avatar Oct 04 '20 01:10 gshilin

The issue reproduces in many examples in my app which are not related to Modals.

Tooltip in a menu dropdown image

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. image

Simple solution is to add the z-index to the wrapper it self.

felixmosh avatar Oct 04 '20 07:10 felixmosh

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.

felixmosh avatar Oct 04 '20 10:10 felixmosh

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?

JMS-1 avatar Oct 04 '20 13:10 JMS-1

It may be good enough to add .ui.popup to this div, it will definitely solve the problem

gshilin-sdb avatar Oct 04 '20 13:10 gshilin-sdb

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.

felixmosh avatar Oct 04 '20 13:10 felixmosh

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.

felixmosh avatar Oct 04 '20 13:10 felixmosh

Popup has properties popperDependencies and popperModifiers. Maybe there is some way to add popperStyle?

gshilin-sdb avatar Oct 04 '20 13:10 gshilin-sdb

and popperClassName

gshilin-sdb avatar Oct 04 '20 13:10 gshilin-sdb

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:

image

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.


Popup has properties popperDependencies and popperModifiers. Maybe there is some way to add popperStyle?

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
  }
}

layershifter avatar Oct 05 '20 07:10 layershifter

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 avatar Oct 05 '20 08:10 felixmosh

@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().

layershifter avatar Oct 05 '20 08:10 layershifter

Agree with syncing it in componentDidMount

felixmosh avatar Oct 05 '20 09:10 felixmosh

Hello everyone. Have workaround?

sergeushenecz avatar Oct 08 '20 16:10 sergeushenecz

Hello everyone. Have workaround?

https://github.com/Semantic-Org/Semantic-UI-React/issues/4083#issuecomment-703237102

felixmosh avatar Oct 08 '20 16:10 felixmosh

@felixmosh Can we without fork?. Because i don't want to do fork

sergeushenecz avatar Oct 08 '20 16:10 sergeushenecz

@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.

felixmosh avatar Oct 08 '20 16:10 felixmosh