-
Notifications
You must be signed in to change notification settings - Fork 26.2k
Components should create a display:block
style by default
#25856
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
This issue root is in how Angular keeps the component custom elements with their custom tag names in the rendered DOM, unlike other frameworks that omit these tags from output like React. The design decision might not be bad overall, and is probably here to stay, but a problematic effect of this design is that these component elements get the It's an instance where lack of action (no Since it's not even This is where a documentation addition might help, also maybe using the Angular CLI default component schematic to add |
@Meligy I'm aware of the history of this issue. I agree with the design choices. Still, Angular is in a position where we can change this browser default. The browsers can't do this, but Angular can. Angular is in a unique position, that can make the The cognitive load of Angular is already pretty high. Changing this would lower it a bit. |
@SanderElias I don't think this is about component, but only for custom element. A directive could also have element selector, like |
I agree. I do this so many times that it feels a little bit cumbersome.
That way I can override it where ever I need to. Maybe something like this (using the prefixes defined in the angular.json) would be an option. |
Thoughts: I agree with the stated problem (I forget this myself all the time!) but I'm not convinced that changing the default is a good idea. RE: cognitive overhead - my argument would be that any time that Angular diverges from the default browser behavior, that in itself increases the cognitive overhead (and load on docs team, etc). It would likely break a number of apps as well - at least if we were to change something in the internals of Angular/Renderer, and (sorry) I'd argue again there's an increase in cognitive load here, because now something "invisible" (not in your component.css file) is changing behavior (and now you have to go look at the docs! How do I override it? etc ) If we want to avoid invisible / non-local problems (that is, I generally shouldn't have to look elsewhere to understand how a component works), I think that means that defaults like this have to exist in your We could use schematics or similar to augment the default css template, so :host {
display: block;
} One nice thing here is that many new developers have no idea that the One drawback here is that you then have to keep things "in sync" - if you change those default later, they won't affect already generated components. We could provide a :host {
display: block;
} @Component({
styleUrls: [
'app/defaults.css',
'./foo.component.css'
]
}) There's an argument to be made for CSS Variables (Custom Properties) here as well, because in a modern browser, rather than duplicating the :root {
--default-component-display: block;
} Then the generated :host {
display: var(--default-component-display);
} This one feels the best to me:
This requires CSS Custom Property support - the good news is this is every browser BUT IE nowadays: https://caniuse.com/#feat=css-variables Since Angular does require a compiler pass, we could potentially make a best effort to "downlevel" those properties - at compile time, rewrite the dynamic CSS is forgiving, so if we were to generate something like this - on IE, the 2nd line doesn't parse (and so the 1st line is used) - on browsers that support CSS Variables, the :host {
display: block;
display: var(--default-component-display, block);
} This is broadly useful for theming as well, and potentially Material. |
@robwormald I would even prefer this over changing the default. I don't agree that changing the default would raise the cognitive load. But let us not go there, as we agree on the solution path. I prefer your solution because as you said, it exposes new devs to Also exposes it them to CSS custom properties. which is another plus. It is about time that this will get some more exposure and broader pick-up. I could live with the fall-back for IE, but I would like to see a setting to turn that off. Ie support should be a thing of the past. It is for me already (for a long time), but aside from that, I don't think we should carry this forward. Having a setting means that in a couple of years, we can switch the default of the setting, to not generate the IE fallback anymore(but still be available for devs that still need to support Ie). |
I really like the idea to solve this via schematics. About resolving css variables at build time. |
This issue was moved to angular/angular-cli#12244 |
This issue has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |
I'm submitting a...
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:
display:block
most of the time (for me, its 99+%)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.
The text was updated successfully, but these errors were encountered: