inert icon indicating copy to clipboard operation
inert copied to clipboard

Relation to content-visibility: hidden

Open chrishtr opened this issue 5 years ago • 6 comments

One of the use cases listed in the explainer is Temporarily offscreen/hidden content. Is this use case already handled by content-visibility: hidden? content-visibility: hidden disables hit testing, focus, tab order, etc and also likely has better performance than any existing mechanism, or the proposed inert attribute.

chrishtr avatar Feb 16 '21 23:02 chrishtr

Doesn't that cause the layout objects to be destroyed?

alice avatar Feb 17 '21 01:02 alice

No. content-visibility: hidden preserves the layout objects (or more precisely, defines the elements to still have layout boxes. It's technically up to the UA whether to cache the layout objects). In this respect it's like visibility: hidden.

For this reason, content-visibility: hidden is my recommended best practice for hiding DOM that is not part of the current view but might be in the future, for use cases such as caching SPA navigation routes and temporarily hidden drawer widgets. I also recommend it for layout measurement of offscreen content.

chrishtr avatar Feb 17 '21 02:02 chrishtr

Ok, what does this mean for inert?

alice avatar Feb 17 '21 03:02 alice

I think the other use case - On-screen but non-interactive content is still unmet, and would be a use case of the inert keyword.

chrishtr avatar Feb 17 '21 06:02 chrishtr

For this reason, content-visibility: hidden is my recommended best practice for hiding DOM that is not part of the current view but might be in the future, for use cases such as caching SPA navigation routes and temporarily hidden drawer widgets

I'm having trouble imagining solving some of the desires in the explainer like this, but that's probably just failure of imagination on my part since you specifically even mention drawers here... Any chance you could share implementations of some of these so that we could look/compare?

bkardell avatar Feb 17 '21 15:02 bkardell

Any chance you could share implementations of some of these so that we could look/compare?

I don't have a specific implementation fo a drawer using content-visibility:hidden on hand to point to. But the implementation would be something like:

drawer[closed] {
  width: 0;
  height: 0;
  content-visibility: hidden;
}
<drawer closed>
 contents
</drawer>

chrishtr avatar Feb 17 '21 16:02 chrishtr