-
Notifications
You must be signed in to change notification settings - Fork 6.8k
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
fix(toolbar): no longer auto-generate toolbar rows #6661
fix(toolbar): no longer auto-generate toolbar rows #6661
Conversation
Did were ever discuss just not having any |
src/lib/toolbar/toolbar.ts
Outdated
super(renderer, elementRef); | ||
} | ||
|
||
ngAfterViewInit() { | ||
// Do nothing if we're not on the browser platform. | ||
if (!this._platform.isBrowser) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you abort here on the server, the prerendered toolbar probably won't look right
src/lib/toolbar/toolbar.ts
Outdated
// If the first toolbar row, which will be auto-generated, does not have any projected content, | ||
// then the auto-generated first toolbar row should be removed. This gives developers | ||
// full control over the first toolbar row (e.g. for use with flex-layout). | ||
if (!firstRowElement.innerHTML.trim()) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of innerHTML
, check !firstRow.textContent.trim() && !firstRow.childNodes.length
?
(I don't even like looking at innerHTML
if it can be avoided)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah pretty sure that works too. Let's see if we actually still need that check with the discussed changes on Slack.
What about only projecting
I guess it adds a little fluff to the api, but the behavior would be straightforward and expected. |
@willshowell I chatted with @jelbourn today about an alternative API design. Should have the PR ready tomorrow. |
6520e9b
to
89e9243
Compare
@jelbourn Applied the changes we discussed per Chat. Please have another look. |
src/lib/toolbar/toolbar.md
Outdated
</md-toolbar-row> | ||
</md-toolbar> | ||
``` | ||
|
||
**Note**: Placing content outside of a `<md-toolbar-row>` when multiple rows are specified, is not | ||
supported. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Superfluous comma
src/lib/toolbar/toolbar.ts
Outdated
@@ -39,15 +42,43 @@ export const _MdToolbarMixinBase = mixinColor(MdToolbarBase); | |||
inputs: ['color'], | |||
host: { | |||
'class': 'mat-toolbar', | |||
'role': 'toolbar' | |||
'role': 'toolbar', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This role
should be removed; I never noticed it being added. It's not appropriate for most uses of the md-toolbar.
(see the docs)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point
src/lib/toolbar/toolbar.ts
Outdated
export class MdToolbar extends _MdToolbarMixinBase implements CanColor, AfterViewInit { | ||
|
||
/** Reference to all toolbar row elements that have been projected. */ | ||
@ContentChildren(MdToolbarRow) _toolbarRows: QueryList<MdToolbarRow>; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We need to subscribe to the changes on _toolbarRows
and update accordingly, since ngIf
and ngFor
etc. will affect the content children
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Doesn't Angular automatically update the _toolbarRows.length
property? I tried it locally and it seemed to work.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It does, but ngAfterViewInit
is only run once
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That makes sense then. Although it doesn't really handle every case. e.g.
<md-toolbar>
<ng-container *ngIf="test">First Row Overwrite</ng-container>
<md-toolbar-row>First Row</md-toolbar-row>
</md-toolbar>
I'm not sure if we should care about that case as well? It may involve using the ngDoCheck
lifecycle hook (which may not be that good for performance)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, there's not much we can do about that. I think it's fine.
89e9243
to
9927677
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM for code. Can you amend your commit to include a BREAKING CHANGE message? Add merge-ready when ready
Caretaker note: this is a breaking change. For anyone that has custom styling on |
8857fbf
to
8e8aa4b
Compare
@jelbourn Done. Added merge-ready, but would be still happy if you briefly look at the breaking change message (I assume for the changelog it will be updated anyway again) |
please rebase |
8e8aa4b
to
aead062
Compare
@mmalerba Done. e2e screenshot uploading seems to timeout (unrelated) |
af61632
to
caee86a
Compare
caee86a
to
ccc2608
Compare
Currently the toolbar always generates the first `<md-toolbar-row>`. This means that developers have no opportunity to set directives/attributes/classes on the first toolbar row (e.g with flex-layout). With this change, the toolbar won't auto-generate any `<md-toolbar-row>` element. The toolbar will have two different row modes: _Single row toolbar_ ```html <md-toolbar> First Tow </md-toolbar> ``` _Multiple rows toolbar_ ```html <md-toolbar> <md-toolbar-row>First Row</md-toolbar-row> <md-toolbar-row>Second Row</md-toolbar-row> </md-toolbar> ``` This means that mixing those two row modes is no longer possible and allowed ```html <md-toolbar> <span>First Row</span> <md-toolbar-row>Second Row</md-toolbar-row> </md-toolbar> ``` BREAKING CHANGE: `<md-toolbar-row>` elements will be no longer auto-generated for the first row. Meaning that custom styling for the first `<md-toolbar-row>` is no longer working as before. Since no toolbar-row is auto-generated anymore, there are two different modes for the toolbar now. Either place content directly inside of the `<md-toolbar>` or place multiple `<md-toolbar-row>` elements. Fixes angular#6004. Fixes angular#1718.
ccc2608
to
aeb3bd0
Compare
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. |
Currently the toolbar always generates the first
<md-toolbar-row>
. This means that developers have no opportunity to set directives/attributes/classes on the first toolbar row (e.g with flex-layout).With this change, the toolbar won't auto-generate any
<md-toolbar-row>
element.The toolbar will have two different row modes:
Single row toolbar
Multiple rows toolbar
This means that mixing those two row modes is no longer possible and allowed
BREAKING CHANGE:
<md-toolbar-row>
elements will be no longer auto-generated for the first row. Meaning that custom styling for the first<md-toolbar-row>
is no longer working as before. Since no toolbar-row is auto-generated anymore, there are two different modes for the toolbar now. Either place content directly inside of the<md-toolbar>
or place multiple<md-toolbar-row>
elements.Fixes #6004. Fixes #1718.