igniteui-angular icon indicating copy to clipboard operation
igniteui-angular copied to clipboard

A better way to handle z-index

Open desig9stein opened this issue 7 years ago • 5 comments

I think that if we use the technique I am showing in the sample we are going to have fewer problems with the z-index values.

The technique is simple. We have a sass list, the index position for each list item in that list represents the z-index value for a component(list item). We can have a different list for different execution contexts. For example, we can have a card component that has z-index: 4 in one list and a card that has z-index: 10 in list dedicated to the grid. We also can have two list items with the same z-index value using a nested list.

Play with the sample, move list values in the list to change their z-index and see how it work.

Some of the benefits:

  1. We will no longer have to think what will happen if I change the z-index of that element, which other I have to change accordingly.
  2. Everything is managed in one file
  3. We will no longer have values like 99999.
  4. Easy to use from everybody.

I think this will reduce the number of bugs according to z-index values.

Please share your concerns, ideas and add more people if necessary.

desig9stein avatar Dec 10 '18 08:12 desig9stein

@desig9stein you say we will no longer have values like 99999, but this is not true. Some z-index values are set using javascript.

It is evident from the sample you are showing that this is a great approach for application scenarios, where you want to manage the vertical stacking order of elements in a more readable way. However, when you use the same approach at a component level, you end up with a list of elements for each component, not taking into account any inline styles set via javascript. Additionally, this approach doesn't take into account the position property of each element in the list, which can alter the stacking context.

I agree, it would be beneficial to have something that controls the global z-index values when it comes applications, this, however, can only be achieved when we have something like an app-host component.

simeonoff avatar Dec 10 '18 11:12 simeonoff

Is there a particular place where we have z-index added by JS if there is, is it really necessary to handle it with JS?. @simeonoff I am not sure why this approach should consider position property in any way, I don't see a problem if it doesn't. What's your concern for that?.

desig9stein avatar Dec 10 '18 13:12 desig9stein

@desig9stein for the time being - yes, it is necessary. As to why position is important have a read on understanding z-index.

simeonoff avatar Jan 15 '19 14:01 simeonoff

I know how z-index works ;) Still, don't know why we should include the position, this is just a better way to handle z-index values, it has nothing to do with the position of the elements. If an element has a z-index value it has some kind of position different from static otherwise it won't work. I mean we know what is the position of that element because we add it.

desig9stein avatar Jan 16 '19 09:01 desig9stein

@desig9stein and @simeonoff are we going to do anything with this issue or should we close it ?

SlavUI avatar Feb 18 '19 13:02 SlavUI