-
Notifications
You must be signed in to change notification settings - Fork 641
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
[css-positioning] position: popover proposal #5699
Comments
I remember wanting a solution for use cases like this at least a few times. But is it really a new positioning scheme? I'd prefer something that works orthogonally to
Of course this also needs working out the details. Probably |
I think it makes sense and will be easier to implement as a positioning scheme. The way I see its behavior working is almost identical to I'm interested to get some feedback from others in the community. |
This would introduce the same issues that making Should |
Ideally, they wouldn't be affected. Opting in to this positioning scheme will effectively "hoist" an element visually for the purpose of breaking it out of overflows and avoiding all transforms/filters. Perhaps it makes sense to think of it as a new stacking context that gets drawn above everything else. While this mostly makes sense in the context of an element living in a shadow DOM, it's not exclusive to that use case. The same behavior can benefit any sort of utility that needs to hoist elements programmatically for the purpose of breaking out of overflows. Thinking about this more, an alternative might be a property that allows an element to "escape" any overflow that affects it. .my-modal-thing {
escape-overflow: x | y | all | none;
} With this, we could rely on existing positioning schemes and achieve a similar effect. But personally, a positioning scheme feels more appropriate here. Either way, I wanted to start the discussion and gather some feedback. I'm very open to alternative ideas that solve the same problem. 😄 |
I second that some things should not be escapable, such as I'm worried that a feature that says "i escape all of my ancestors clips" can break some optimizations that we may have. For e.g. strict containment essentially says that the elements bounds contain all of the pixels of its contents, which means that if the element is off-screen then you don't need to paint any of its subtree. If something can escape it though, this is no longer true. Did you have a specific set of things in mind that you think this property should ignore / escape? |
I'm not sure it would break optimizations, but it's a fair point to consider. In the case of
I'm debating with myself whether However, it should break out of overflows and clips. Overflows are the most common cause of frustration, but I've seen clips used cleverly to achieve similar results and it would be difficult to guarantee the popover element is visible if they didn't break out. |
The main reason why I don't consider it a positioning scheme is that you provided no description of how any positioning properties would be interpreted differently for We considered requirements for interactions and for lack thereof with different, as yet quite vague sets of properties. Let me take a stab at a simple spec taking into consideration only the most important ones: Name: If the value is not Open issues
|
I stumbled over the same problem just now while thinking about converting our angular combobox to a web component. I think that dropdowns/tooltips and dialogs are different scenarios:
So in my opinion it shouldn't be a new css position value. It would be more flexible for the developer to have a new css property which can be combined with position absolute/fixed. About the transform question: At least for dropdown/tooltip implementations it would probably make sense if the transforms are applied. For my usecase (dropdown of a combobox) it would be best, if it would behave the same as the dropdown of the native |
Perhaps this issue should be renamed to reflect the use case, not my proposed solution. I'm happy it's got the discussion going, but I'm definitely open to alternative ideas whether it be a new property or an extension of an existing one. 😄 |
I have stumbled on this problem many times as well. However, in my use cases, the positioning scheme I needed was closer to absolute positioning than fixed. I would argue solving this is also an accessibility matter, since currently a lot of these solutions break accessibility (tabbing order), with the developer not always making up for it with script. |
This sounds like it would indeed allow us to use the fixed positioning technique more reliably. For this use case, I don't see a need to support arbitrary containing blocks aside from the initial one. 😄 |
A new HTML element called It seems to address most of my concerns for dropdowns and tooltips, so I thought I'd post it here for others to review and comment on. |
I know that in the times of HTML5 the tenet of separation between content and presentation isn't held very strongly, but the existence of such element, possibly with presentational hints, should not be an excuse to forgo it in CSS. If both are standardized, the HTML element should just have its presentation defined in the default stylesheet. And modifiable by authors if they wish (including the flexibility you wish for, @claviska). Of course, there's also the benefit of orthogonal specifications, enabling such styling in documents using something other than HTML. |
After thinking about it a bit more, I wonder if the best way to go isn't necessarily to override the containing block, but to be able to declare an element as something that can "spill out" of an Something like One issue with that is that now |
One way to resolve this without introducing new keywords is to have popups respect things like |
What worries me is that if popups cannot be guaranteed to display, authors would still resort to the existing techniques (described in the first post). |
There are less extreme ways to make this work though. For example, if the popups are clipped by
|
Just make "dialog" attribute, using .show() method break out of overflow like it does for .showDialog(). |
Stumbled upon this issue when researching stuff for anchor positioning. Now that we have a spec for it in progress — https://drafts.csswg.org/css-anchor-position-1/ (allowing attaching things to other elements, and escaping some containers via fixed anchor positioning), HTML Popover API (allowing moving the popover into the topmost layer), and there are separate issues about having a way to escape/reparent elements (#8588, #9107, for cases that Popover does not cover) — should this issue be closed in favor of these, or is there something else that could be salvaged from it? |
@vmpstr So we also need properties like |
This issue is worth revisiting now that the Today, you can put pretty much anything in the top layer using code similar to below: <div id="p" popover="manual">
<script>
p.showPopover();
</script> This requires HTML and worse, it requires JavaScript. Note: I'm talking about Why shouldn't it be possible to arbitrarily put things in top-layer declaratively using CSS (There was some discussion about this in #6965) It would be immensely useful, and CSS feels like the correct place to do this. When migrating some of my old code over to There is even a UA-restricted #p {
overlay: manual;
} One of the issues I can foresee is loops. There might be a selector that only matches elements that are in the top-layer (#7319), and authors could use that selector to unset the declaration that placed the element in the top-layer in the first place. But this issue can be avoided by restricting this pseudo-class to non-CSS triggered top-layer elements. |
As a custom element author, it's not uncommon to create an element that utilizes some sort of dynamic "popover." There are many examples of this, but a few common ones include:
In most cases, such components require a "panel" element that "pops over" the page content. The problem is the panel is subject to containment by its ancestors. For example, a containing
<div>
withoverflow: hidden
will [correctly] cause unwanted clipping.Traditional workarounds for this problem include:
</body>
)Neither of these solutions are elegant, nor do they guarantee the panel will be positioned as intended. The former relies on DOM modifications and arbitrary z-indexes while the latter requires that no ancestors have
transform
,perspective
, orfilter
properties:In the world of web components, particularly when a shadow root is attached, the panel is commonly contained in the shadow root. As a result, it cannot be "hoisted" to another location in the DOM because its styles are encapsulated and slotted content will no longer work. Hoisting also makes accessibility difficult since
id
attributes can no longer be referenced once they're removed from the shadow root (not to mention potential conflicts with ids in the global scope). This leaves us with only one option — the fixed position strategy.With the fixed position strategy, there's no way to guarantee a panel's position. You can try to identify its containing block by traversing the DOM and checking for relevant properties, but that's arduous. And if the containing block isn't viewport, "fixing it" will involve altering properties that may cause visible changes to unrelated ancestors.
The Proposal
I suspect this use case will become more and more common as web components become ubiquitous. After many weeks of experimentation, I've come to the conclusion that this could better be solved at the CSS level. Therefore, I would like to propose a new position property:
Just like
position: fixed
, an element withposition: popover
will be removed from the normal document flow, and no space is created for the element in the page layout. Unlikefixed
, the element will be positioned relative to the viewport, not its containing block. This makes sense since popovers are pseudo-modal and seldom appear off-screen.And since naming is hard, a few alternatives might be
position: overlay
,position: anchored
, orposition: viewport
.The text was updated successfully, but these errors were encountered: