You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[Custom Elements]: Custom elements should be display: block by default #224
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.
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).
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.
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.
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
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.
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.
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.
The problem here is that it would mean we have to do either:
display value changes when an unresolved custom element becomes upgraded
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.
Hmm, that is a pretty good argument. Just to clarify for everyone:
means that <x-foo> goes from display: inline to display:block when you register x-foo.
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.)
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.
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.
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.
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.
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.
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. @domenicasked for feedback/experience on Twitter and I think that's what we're getting :)
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?
@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.
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.
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.
Activity
rniwa commentedon Mar 1, 2016
I don't think we should change the default display type (i.e. we should use
display: inlineby default). Regardless, we need to make a decision for v1.@travisleithead @annevk
annevk commentedon Mar 1, 2016
I tend to agree. Paging @esprehn.
[-][Custom Elements]: Custom elements should be display: block by default (bugzilla: 24876)[/-][+][Custom Elements]: Custom elements should be display: block by default[/+]domenic commentedon Mar 7, 2016
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: inlinewould 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.justinfagnani commentedon Mar 7, 2016
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.silenceisgolden commentedon Mar 7, 2016
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.
Robdel12 commentedon Mar 7, 2016
I think I'd rather have then act as
display: blockrather than inline. It's usually a special case for me to change a component/custom element to inline and even then its inline-block.rniwa commentedon Mar 7, 2016
The problem here is that it would mean we have to do either:
displayvalue changes when an unresolved custom element becomes upgradeddisplayvalue for all existing unknown elements with-in its nameI 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: blockfor:unresolvedpseudo class or would see FOC. If they had already specifieddisplay: block, then it would be mysterious thatdisplay: blockis not needed for the actual custom elements.domenic commentedon Mar 8, 2016
Hmm, that is a pretty good argument. Just to clarify for everyone:
<x-foo>goes fromdisplay: inlinetodisplay:blockwhen you registerx-foo.<x-foo>is alwaysdisplay: block, even if you never registerx-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
:potentiallycustomthat matches any tag name with-in it, so they can add a one-line:potentiallycustom { display: block; }to their stylesheets. (This is different from:unresolvedsince it would still work after upgrading.)bkardell commentedon Mar 8, 2016
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.
robdodson commentedon Mar 8, 2016
Yeah being able to just do this once would be much nicer than having to auto-include it in all of my hosts
16 remaining items
ebidel commentedon Mar 8, 2016
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: inlineby default is a gotcha. It's not what people expect or typically want. I'd love to see us change todisplay: blockordisplay: inline-blockto make life easier. From personal experience building apps, the first thing I do when authoring new elements is adddisplay: block(visual elements) ordisplay: 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.bicknellr commentedon Mar 8, 2016
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?sjmiles commentedon Mar 8, 2016
Fwiw, I have the same experience as @ebidel. The
display:inlinedefault 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:
bicknellr commentedon Mar 8, 2016
Why is block preferable to inline-block?
domenic commentedon Mar 8, 2016
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.
sjmiles commentedon Mar 8, 2016
The technical constraint in #224 (comment) was described as problematic due to being
So what is on balance most confusing for authors would seem to be relevant.
domenic commentedon Mar 8, 2016
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.
ebidel commentedon Mar 8, 2016
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 :)
domenic commentedon Mar 8, 2016
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.
robdodson commentedon Mar 8, 2016
@rniwa suggested:
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 requiredisplay: blockand those coincidentally also all have Shadow DOM. Would this be a decent compromise?domenic commentedon Mar 8, 2016
@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.
rniwa commentedon Mar 8, 2016
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
displayvalue atdefineElementtime or at the time of attaching shadow root is worse than letting developer specifydisplayvalue themselves.Furthermore, we're unsure that
display: blockwould be the most popular type. For example,img,canvas, andinputare alldisplay: inline. Hence, we don't support the proposal to change the defaultdisplayvalue for custom elements or shadow DOM at this point.domenic commentedon Mar 8, 2016
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.