question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Components should create a `display:block` style by default

See original GitHub issue

From @SanderElias on September 7, 2018 11:19

I’m submitting a…


[ X ] Feature request
[ X ] Documentation issue or request

Current behaviour

When you create a new component, by default it gets no setting for css display.

Expected behavior

it should have display:block by default.

What is the motivation/use case for changing the behavior?

I know this has been discussed before (#5960), and pops up in (#12340) too. Still, I’m putitng this back on the roll. For the following reasons:

  1. Current behaviour is confusing for new devs
  2. Devs need display:block most of the time (for me, its 99+%)
  3. The web doesn’t break if we put this in place.
  4. The expected impact of this “breaking” change is minimal
  5. Saves a few bits from the app’s payload
  6. Less questions. no more, why does my css….
  7. One more thing less to remember when creating a component.

I want to elaborate on point 3 a bit. The same discussion has been held in by standarts committee, If you follow along that discussion you will see that the general consensus is that it is actually a good idea, but it can’t be changed because that would break the web. Angular does not have that issue. Angular can change this, and the impact of the change would be minimal. probably something that has less impact as for example rxjs 5 to 6.

Others: If we don’t do this change, at least there should be more emphasis on this in the documentation.

Copied from original issue: angular/angular#25856

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:17
  • Comments:17 (9 by maintainers)

github_iconTop GitHub Comments

5reactions
dgp1130commented, Dec 5, 2019

After discussion in the CLI meeting, I just wanted to add that Google has a web components doc which recommends setting :host { display: block; } as a best practice because custom elements use display: inline; by default (though I’m told Angular components are not custom elements).

There is also an interesting foot gun, in that if a user manually adds :host { display: block; }, it will break the hidden attribute. The user actually wants:

:host {
  display: block;
}

:host([hidden]) {
  display: none;
}

Somewhat unrelated, but another mistake a user might run into is using :host[hidden], which doesn’t work due to custom element styles weirdness. If we do decide to make display: block the default, we should also include the extra style for hidden and possibly reference this doc as some justification.

3reactions
dgp1130commented, Mar 10, 2020

The PR was merged on Thursday so it just missed the last release, however it should be included in 9.1.0-next.3 which should be published later today.

Considering I don’t think there’s any more work to do here, I think we can close this issue. Just waiting for it to roll out.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Components should create a `display:block` style by default
Let's say I create a new component in Angular2 and I attempt to style it: // hello_world_cmp.ts @Component({ selector: 'hello-world', ...
Read more >
Angular component default style css display block
It feels logical to me that all angular elements should be block displayed by default, because for the majority, it makes sense. As...
Read more >
Angular CLI: Generating block components, by default.
There is a problem with Angular components out of the box: Components have the CSS display property set to inline implicitly by default....
Read more >
How do you create displayBlock components? - JS IQ
But it is possible to create components with display: block style using ... (OR) the option can be turned on by default in...
Read more >
display - CSS: Cascading Style Sheets - MDN Web Docs
The display CSS property sets whether an element is treated as a block or inline element and the layout used for its children, ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found