Skip to content

[Custom Elements]: Custom elements should be display: block by default #224

Closed

Description

@hayatoito

Title: [Custom Elements]: Custom elements should be display: block by default (bugzilla: 24876)

Migrated from: https://www.w3.org/Bugs/Public/show_bug.cgi?id=24876


comment: 0
comment_url: https://www.w3.org/Bugs/Public/show_bug.cgi?id=24876#c0
Elliott Sprehn wrote on 2014-03-01 08:38:13 +0000.

Almost every custom element I've seen so far has:

<style> :host { display: block } </style>

inside the ShadowRoot, or a rule in the owning page that makes it into display: block since the default of display: inline for unknown elements is really never want you want. I've also seen lots of authors stumble trying to figure out why their custom elements look busted when they first start before they realize they all need this rule.

I think we should consider add some kind of pseudo like :custom and then say the UA sheet has :custom { display: block } to make this simpler.


comment: 1
comment_url: https://www.w3.org/Bugs/Public/show_bug.cgi?id=24876#c1
Boris Zbarsky wrote on 2014-03-01 20:15:58 +0000.

Custom form controls presumably wouldn't be display:block...


comment: 2
comment_url: https://www.w3.org/Bugs/Public/show_bug.cgi?id=24876#c2
Elliott Sprehn wrote on 2014-03-03 21:35:39 +0000.

(In reply to Boris Zbarsky from comment #1)

Custom form controls presumably wouldn't be display:block...

Indeed, they probably want to be display: inline-block. What I've observed is that in many modern applications custom elements are placed inside flex boxes so display: block is fine since they end up flexed anyway (if they were inline they end up inside anonymous blocks instead).


comment: 3
comment_url: https://www.w3.org/Bugs/Public/show_bug.cgi?id=24876#c3
Boris Zbarsky wrote on 2014-03-03 22:15:19 +0000.

Inlines in a flex container don't create anonymous blocks; they just end up with a computed display of "block". The only anonymous anything that happens with flexbox is that text that's a direct child of a flexbox is wrapped in an anonymous flex item.

Activity

  1. rniwa commented on Mar 1, 2016

    @rniwa
    Collaborator

    I don't think we should change the default display type (i.e. we should use display: inline by default). Regardless, we need to make a decision for v1.

    @travisleithead @annevk

  2. annevk commented on Mar 1, 2016

    @annevk
    Collaborator

    I tend to agree. Paging @esprehn.

  3. changed the title [-][Custom Elements]: Custom elements should be display: block by default (bugzilla: 24876)[/-] [+][Custom Elements]: Custom elements should be display: block by default[/+] on Mar 1, 2016
  4. domenic commented on Mar 7, 2016

    @domenic
    Collaborator

    I've asked for developers to comment on this thread with their experiences in the hopes that we can meet their needs better. I agree that leaving it display: inline would be simpler and nicer from a spec and implementer point of view, but it seems like we should try to listen to developers on this.

  5. justinfagnani commented on Mar 7, 2016

    @justinfagnani
    Contributor

    I'm with @esprehn, nearly every element I've ever authored has :host { display: block }. I've made maybe one or two inline custom elements ever.

  6. silenceisgolden commented on Mar 7, 2016

    @silenceisgolden

    Pardon my ignorance, but does this spec cover the ability to extend elements that are already registered? I would think that it would be block by default unless it extends an element that has a default of inline.

  7. Robdel12 commented on Mar 7, 2016

    @Robdel12

    I think I'd rather have then act as display: block rather than inline. It's usually a special case for me to change a component/custom element to inline and even then its inline-block.

  8. rniwa commented on Mar 7, 2016

    @rniwa
    Collaborator

    The problem here is that it would mean we have to do either:

    1. display value changes when an unresolved custom element becomes upgraded
    2. We change display value for all existing unknown elements with - in its name

    I don't think we can do 2 due to backwards compatibility and 1 is very confusing for authors. For starters, authors have to have display: block for :unresolved pseudo class or would see FOC. If they had already specified display: block, then it would be mysterious that display: block is not needed for the actual custom elements.

  9. domenic commented on Mar 8, 2016

    @domenic
    Collaborator

    Hmm, that is a pretty good argument. Just to clarify for everyone:

    1. means that <x-foo> goes from display: inline to display:block when you register x-foo.
    2. means that <x-foo> is always display: block, even if you never register x-foo.

    I agree that (2) is backward incompatible and (1) is pretty horrible. I can't see any way to make this work.

    Maybe the best solution we can offer authors is some kind of selector like :potentiallycustom that matches any tag name with - in it, so they can add a one-line :potentiallycustom { display: block; } to their stylesheets. (This is different from :unresolved since it would still work after upgrading.)

  10. bkardell commented on Mar 8, 2016

    @bkardell

    oh yeah, +1 for a pseudo, I made this case several years ago now :dashedTag or something would be super useful/fairly straightforward I think. fwiw, at my company we use a custom import mechanism and that puts all of the in visibility: hidden until they are upgraded - this way they reserve space but don't draw some potential horribleness... seems p good.

  11. robdodson commented on Mar 8, 2016

    @robdodson

    Yeah being able to just do this once would be much nicer than having to auto-include it in all of my hosts

  12. 16 remaining items

  13. ebidel commented on Mar 8, 2016

    @ebidel

    There are some good points in this thread. Just want to add my $0.02.

    I've spoken with many developers over the years, and custom elements being display: inline by default is a gotcha. It's not what people expect or typically want. I'd love to see us change to display: block or display: inline-block to make life easier. From personal experience building apps, the first thing I do when authoring new elements is add display: block (visual elements) or display: none (non-visual elements) :)

    Mindful developers are already dealing with style changes, layout FOUC, and visual FOUC from unupgraded -> upgraded. So IMO, it would be nice for us to optimize for the most common case (display: block). If you throw in @ojanvafai's points on performance, we can optimize both the dev ergonomics and performance.

  14. bicknellr commented on Mar 8, 2016

    @bicknellr

    As long as we're adding :host {display: block;}, why don't we add :host, :host * {box-sizing: border-box;} too? That's what everybody wants, right?

  15. sjmiles commented on Mar 8, 2016

    @sjmiles

    Fwiw, I have the same experience as @ebidel. The display:inline default is just not what people expect. Often they put block-level elements inside a host and don't even realize there is a problem until the host reports 0 height, or exhibits strange (to them) rendering behavior.

    With respect to #224 (comment), I agree with @esprehn:

    I think having registerElement make it become block is fine, you should already be managing FOUC using :unresolved.

  16. bicknellr commented on Mar 8, 2016

    @bicknellr

    Why is block preferable to inline-block?

  17. domenic commented on Mar 8, 2016

    @domenic
    Collaborator

    Why are people still coming into this thread thinking this is opinion-based? There are technical constraints, discussed in #224 (comment). Listing your favorite sites' percentage of display: block elements is not at all helpful.

  18. sjmiles commented on Mar 8, 2016

    @sjmiles

    The technical constraint in #224 (comment) was described as problematic due to being

    very confusing for authors

    So what is on balance most confusing for authors would seem to be relevant.

  19. domenic commented on Mar 8, 2016

    @domenic
    Collaborator

    Yes, but it's completely irrelevant how many display: blocks you have. Tell us about how you are not confused by FOUCs on upgrade, but don't tell us about how you use display: block a lot.

  20. ebidel commented on Mar 8, 2016

    @ebidel

    Custom elements fall under the extensible web. Luckily, we have a lot of folks with real world experience that can offer actual data points.

    The title of this bug is "Custom elements should be display: block by default", so it makes sense that we're still discussing that. @domenic asked for feedback/experience on Twitter and I think that's what we're getting :)

  21. domenic commented on Mar 8, 2016

    @domenic
    Collaborator

    I'm going to have to lock this issue if people keep failing to read the thread and commenting on something we've already moved past.

  22. robdodson commented on Mar 8, 2016

    @robdodson

    @rniwa suggested:

    Do most of those custom elements have a shadow DOM? I think I would be okay with making an element with a shadow DOM use display: block by default as that would be backwards compatible.

    In Polymer land we do make a lot of non-visual elements like iron-ajax, iron-selector, etc. and those don't need to be display: block, nor do they have Shadow DOM. Only our UI elements require display: block and those coincidentally also all have Shadow DOM. Would this be a decent compromise?

  23. locked and limited conversation to collaborators on Mar 8, 2016
  24. domenic commented on Mar 8, 2016

    @domenic
    Collaborator

    @robdodson that sounds like a decent compromise. Unfortunately this thread has become an unproductive environment, and it sounds like it's moving toward shadow DOM anyway, so it would be best to open a new thread to suggest that for the shadow DOM spec.

  25. rniwa commented on Mar 8, 2016

    @rniwa
    Collaborator

    We (Apple) had more internal discussions about this, and while we're sympathetic to the developer ergonomics argument made here, we feel that the magical behavior of changing display value at defineElement time or at the time of attaching shadow root is worse than letting developer specify display value themselves.

    Furthermore, we're unsure that display: block would be the most popular type. For example, img, canvas, and input are all display: inline. Hence, we don't support the proposal to change the default display value for custom elements or shadow DOM at this point.

  26. domenic commented on Mar 8, 2016

    @domenic
    Collaborator

    Thanks @rniwa. In the end I think a shadow DOM based solution would end up serving everyone's needs better, and align more with the developer experience based on Polymer and such. It makes intuitive sense to me: the "app-like" non-simple custom elements that want to be laid out in a block-ey fashion are more likely to be the ones that need shadow DOM.

    Let's continue discussion of that in #426. I'll close this, although it can be reopened if Mozilla or Microsoft show up with strong support for changing the default here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions