Repository navigation
Description
The inert attribute as defined in #4288 changes hit testing and selection behavior in ways that can already be controlled via CSS via pointer-events and user-select, respectively. It also forces cursor to be default, in practice.
It seems to me that, rather than adding a second magic way of controlling this behavior, defining this in terms of either existing or new values for those CSS properties makes more sense. Defining inert in a way that inert nodes (note: not nodes with the inert content attribute) must have a computed value of pointer-events: none and user-select: none is the easiest way to address this.
This would be equivalent to the following pseudo-code in a user-agent stylesheet:
/* matches all inert elements. Could be an internal pseudo-class, or may be useful to expose it for authors? Not sure */
:inert {
user-select: none !important;
pointer-events: none !important;
cursor: default !important;
}Per the discussion in mozilla/standards-positions#174, there's a subtle difference between the behavior of pointer-events: none and the intended behavior of inert, which is that pointer-events: none doesn't prevent boxes behind (but not inside) the inert node from getting hit. If this behavior is both intentional and important, which per that discussion seems to be, then it seems such a behavior should be specifiable via pointer-events as well.
Note that focus behavior used to be controllable via CSS as well, via user-focus, but it seems it's been removed from the latest draft. cc @frivoal as editor of that spec in case he remembers why. Generally focusability already depends on CSS (visibility and overflow and such). But special-casing inert for focus if user-focus doesn't exist might be fine, as that's not something that we expose in other ways.
Also, it seems a bit odd that inert as specified changes the behavior of some selection APIs, like setSelectionRange, but not selectionStart / selectionEnd setters. Why is that needed / desirable?
Generally, I don't think inert should be described in terms of event dispatching / selection magic when we have existing features in the platform to control what inert wants to control.
Activity
dbaron commentedon Jun 18, 2020
It's not clear to me that the
inertbehavior fits well with thepointer-eventsproperty given thatpointer-eventsis an inherited property. The behavior required for inert is something that applies to an entire subtree. While this could be defined in an inherited property, it doesn't fit particularly well, and means that you'd need to look at all ancestors' computedpointer-eventsbefore deciding that an element can be a hit target.alice commentedon Jun 18, 2020
This ignores the critical point that
inertalso addsaria-hidden-like behaviour.Missing this point proves exactly the reason why we want to combine all these behaviours together: authors tend to miss this as well, and it creates a poor experience for users, who come first in the priority of constituencies.
This is probably an oversight in the spec. I'm happy to fix that up.
emilio commentedon Jun 18, 2020
Well so is
cursor(anduser-selectis not technically inherited but behaves almost like it). The comment in the snippet I posted specifically mentions "matches all inert elements" (which is not the same as "all elements with the inert attribute").Sure, I was talking about the selection / hit-testing behavior. But in any case, again, I do agree inert is valuable, I just don't think we should add more switches to tweak things we already have switches for.
Add position for the inert attribute.
emilio commentedon Jun 18, 2020
Though this means that toggling "inert" on a node needs to restyle the whole subtree, which may be slightly unfortunate and one similar concern? Though you need to do work on the whole subtree with or without the CSS, to make it reasonably efficient, I think.
alice commentedon Jun 18, 2020
I don't follow the logic here. Much of the value of inert is that it combines all these behaviours together, and is straightforward to use and understand: it operates on the DOM subtree, and can't be overridden.
What switches are you talking about adding?
emilio commentedon Jun 18, 2020
I'm talking about adding another way to control selection / hit-testing / etc behavior that works regardless of CSS (via
inertmagic), when it's easy to haveinerthave the behavior you want, combining all these things, and allowing authors to use it easily in the same way, while basing its behavior on features that already exist, and that can be queried by authors, etc.My proposal above achieves the "can't be overridden" bit in the same way (by using
!importantin the user-agent stylesheet instead of magic), while it avoids having to introduce switches in hit-testing / selection code that override the existing CSS switches, and it still allows authors to query the computed style and get meaningful results for "can this node be selected", for example.I feel like maybe we're talking past each other a bit? I'd be happy to sync in person real quick if you wanted or what not.
emilio commentedon Jun 18, 2020
Because I feel like either I'm not expressing myself correctly, or we're misunderstanding each other's propositions, or I'm missing something, or maybe something else? Again, I'm very much not against this feature, I just feel like the way it's defined and implemented could be simpler :)
dbaron commentedon Jun 18, 2020
So a few clarifications here:
What @emilio is asking for is not redefining all of
inertin terms of these properties (cursor,user-select, andpointer-events) but redefining part ofinertin terms of them.It seems that in some cases this requires changes to those properties (I think this is needed for
pointer-eventsand foruser-selectand is not needed forcursor).This redefinition would have the advantages that:
a. It simplifies the specification of
inertby deferring parts of it to CSS, and correspondingly simplifies the implementation by avoiding needing to look at the DOM for those things.b. It improves the experience for authors who are trying to examine CSS computed values of these properties to understand what the event / selection / cursor behavior of their elements are.
c. It allows content authors who actually do want part of
inert's behavior but not all of it to be able to get it. (Admittedly this may be both an advantage and a disadvantage, if they find the "part" behavior first when they really wanted "all".)Note that (b) also means that compatibility with then-existing (but not yet existing) content might prevent us from making this redefinition in the future, which is why it's somewhat important to decide one way or another now or at least soon.
I'd also note that the required changes to
user-selectwould I think mean reintroducing a behavior that I think Gecko used to have (although I didn't audit the history closely) where there is anone-like value that inhibits selection on all descendants even if they have a different valueemilio commentedon Jun 18, 2020
Just to clarify, I don't think there's no need to change user-select, if you specify that
user-select: nonemust apply to all inert nodes, rather than just to the root of the inert subtree, which is that my sketched pseudo-class intended to do.alice commentedon Jun 19, 2020
There seem to be several issues conflated here:
inertattribute (it's not clear whether this is also intended for elements which are made inert via an active modal<dialog>) should match CSS properties which have similar behaviour (e.g.user-select).What is the user or author need for this functionality? Is there a specific case in which it would be useful? Is there a precedent for this other than
hidden, which many authors find frustrating because the hidden-ness is so easy to accidentally override?inertis controlling (e.g. a new value forpointer-events, and possibly some iteration ofuser-focus).Each of these additions should be addressing a specific user need, like
inertis.It's also not clear to me that having CSS control behaviour, particularly for things like focus, is actually a good thing. Having something be defined in HTML rather than CSS doesn't make it intrinsically "magic".
Plus, as @dbaron pointed out, giving authors more control can actually harm users, if authors actually want
inertbut, for example, find the relevant CSS properties first.Yes, it is. This is largely because there is no hit testing spec.
alice commentedon Jun 19, 2020
I'll also point out that Maciej Stachowiak left the following feedback on the
inertrepo:dbaron commentedon Jun 19, 2020
I think the precedent for this is in some ways a significant part of CSS1 and CSS2, which were motivated by separating out the "presentational" behaviors that existed in HTML into a separate language and thus allowing HTML to deprecate its presentational attributes for use in new documents and recommend that new documents use CSS instead and explain them in terms of their mapping into CSS.
hiddenis interesting because it was probably the first step in the other direction after that era, that is, the first new HTML presentational attribute in a while that was recommended to developers rather than moving presentation into CSS. But underneath that is the question of what it means to be presentational, and where the line in the separation of content versus presentation should actually be drawn. (Direct CSS control over things like selection and focus has always been one of the unclear areas, although selection and focus do clearly depend on a number of things that are firmly in on the CSS side.)emilio commentedon Jun 20, 2020
I think it would be useful for authors. For users there's no difference of course. Regarding other precedents,
contenteditableaffects the:read-write/:read-onlypseudo-classes, which by default makes thecursorproperty bedefaulton links and so on, at least in Gecko. This is overridable by authors right now though.hiddenbeing easy to accidentally override seems unfortunate, but that's because of howhiddenis defined, not because ofhiddenmapping to the display property itself.We're clear we don't want to allow authors to override
inert, but that's different from makinginertcause the computed styles ofuser-select/ etc be different.I'm pretty sure that if we changed
hiddento not map to thedisplayproperty, then a lot of the code authors write would be bogus in its presence. I've seen tons of loops through the parent chain checking fordisplay: none, andhiddennot being implemented in terms ofdisplaywould make those loops more complicated for authors to get right. This one is one that comes to mind, but I'm sure there's a gazillion examples. It seems reasonable for authors to query selectability or hit-testability in similar ways, andinertnot mapping to the existing CSS facilities for it just makes authors' lifes harder.If modifying the behavior of hit testing is required for
inert, I'd say that it makes sense to make it expresable via the existing switch (pointer-events).CSS already controls focus behavior, via both
display,overflow, andvisibility, right? But sure, I agree theuser-focusthing seems a bit more controversial.user-focusnot existing today unprefixed in any browser means we probably have more leeway here and can punt on deciding whetherinertshould map to it whenever we introduce it, if ever.Yeah, but that is about making
inerta CSS property itself, right? Not about making it affect existing CSS properties. In any case feedback from @othermaciej / @smfr / other WebKit folks on this issue would be greatly appreciated.alice commentedon Jun 21, 2020
Thanks for the examples, and to David for the the explanation of the philosophical precedent.
Fair point.
I strongly disagree.
This is equivalent to exposing part of
inert's behaviour in isolation, which I've already argued against repeatedly. If people wantinert-like hit testing behaviour, they should useinert.(Also,
pointer-eventsis a weird fit for HTML in the first place, in my opinion.pointer-events: none;is very counter-intuitive in what it actually means.)I'm obviously not arguing that we should make breaking changes to
hiddenright now. But the bug you link is interesting - the fact that they are checking style instead of DOM, while walking the DOM tree, is causing a performance slowdown due a bug in style computation. Ifhiddenstrictly meant "not visible" (rather than the more subtle meaning it has), and it wasn't mapped todisplay, (leaving aside that they're also checkingvisibility), they could walk the DOM tree checking for thehiddenattribute instead, with no need to (re)compute style. So I'm not clear on how this is an argument for exposing behaviour via computed style, since they have to walk the DOM tree in any case.For
inert, they could do the same parent chain walk, but just check the.inertIDL attribute.Yes and no.
displayandvisibilityaffect whether an element is perceivable to users, and non-perceivable elements don't take focus because that would be a very confusing and inconsistent user experience.overflowmay make the container element focusable, so that users may use the arrow keys to scroll content.I think our remaining disagreement (other than adding a new
pointer-eventsvalue, discussed above) regarding havinginertaffect the computed style properties is mostly around:getComputedStyle()to detect some, but not all effects ofinert?:inertpseudo-selector, but authors can't (or to begin a debate about whether we should ship an:inertpseudo-selector)?inert? Is it worth delaying getting the value ofinertto users by however long that work would take?getComputedStyle()returning different things depending on implementation. How would this compatibility issue cause problems?Are there any other remaining disagreements I've missed?
emilio commentedon Jun 22, 2020
While I'm sympathetic to that argument, having a hit-testing behavior that you can't achieve via the existing hit-testing switches seems more wrong to me than exposing this particular capability (which is likely to be useful in other ways).
That may be fair, but it's not going anywhere, so I'd rather not introduce yet another out of band way of changing hit-testing behavior.
I'm not sure what you're suggesting, but they'd also need to check the style, on top of
hidden, unless you're also suggesting thatdisplay: noneandvisibility: hiddenshouldn't exist. The bug in the style engine was a typo of mine anyhow :/, but it seems totally unrelated.If you want to answer "is this node inert?" that's the same thing with or without this proposed change. However to answer "is this node selectable?" they'd have to both check
user-selectandinert. Makinginertaffectuser-selectseems worth it.I think there is clear author value, but I'm happy to be convinced otherwise. The use case can be as simple of "checking whether node X is selectable?".
inertwould make it more complex if it didn't affect the existing CSS properties.There's no need to specify internal pseudo-classes that aren't exposed to web content, just their effects. There's no need to implement it using my pseudo-code in the OP, you could write it with three lines of code in Blink's
StyleAdjuster, fwiw :)I think specifying that inert nodes must get a computed
user-selectvalue ofnoneis much simpler than specifying the equivalent ofuser-select: none, etc. in prose in the HTML spec. You can specify it as "behaves us" too, I guess, though that makes authors' lives harder.As I said, I don't think it's a massive task. In fact, I think making this change would end up with a simpler specification.
I'd personally rather get it done before shipping inert, because it's a web observable, but I mean, it's your engine, you can ship whatever you want.
I don't have a super-clear example of how changing this in the future could cause problems, but I don't think that we should make breaking changes if we can avoid them before shipping, and I've seen sufficiently bizarre compat issues before to be wary of any gratuitous breaking change.
I'm happy to punt on this if folks from other browser engines don't agree with me or what not.
No, that was a great summary, thank you.
Add position for the inert attribute. (#371)
smfr commentedon Aug 4, 2021
WebKit is staring to implement
inert, and this discussion raises two questions which might illuminate how an implementation works.First, does
inertalter the behavior ofelementFromPoint?elementFromPointdoes a hit-test, and its behavior is affected by thepointer-eventsproperty.Second, I'm unclear on how the blocked by modal dialog algorithm works if
inertis not overridable in a subtree. It would be nice to spec theinertattribute and the modal dialog behavior in a way that shares the same fundamentals, and not just "act as if every node in the document had theinertattribute applied".nt1m commentedon Sep 20, 2021
@chrishtr Can we move forward on this? I'm trying to merge web-platform-tests/wpt#30866 if possible.
[inert] Track inertness in ComputedStyle
Add the inert attribute and tweak definition of inert subtrees
Add the inert attribute and tweak definition of inert subtrees