Skip to content
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

Merged

Conversation

devversion
Copy link
Member

@devversion devversion commented Aug 27, 2017

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

<md-toolbar>
  First Tow
</md-toolbar>

Multiple rows toolbar

<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

<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 #6004. Fixes #1718.

@googlebot googlebot added the cla: yes PR author has agreed to Google's Contributor License Agreement label Aug 27, 2017
@jelbourn
Copy link
Member

Did were ever discuss just not having any md-toolbar-row at all when they're not specified? What was the downside there?

super(renderer, elementRef);
}

ngAfterViewInit() {
// Do nothing if we're not on the browser platform.
if (!this._platform.isBrowser) {
Copy link
Member

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

// 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()) {
Copy link
Member

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)

Copy link
Member Author

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.

@willshowell
Copy link
Contributor

What about only projecting md-toolbar-row?

<div class="mat-toolbar-layout">
  <ng-content select="md-toolbar-row, mat-toolbar-row"></ng-content>
</div>

I guess it adds a little fluff to the api, but the behavior would be straightforward and expected.

@devversion
Copy link
Member Author

devversion commented Aug 31, 2017

@willshowell I chatted with @jelbourn today about an alternative API design. Should have the PR ready tomorrow.

@devversion
Copy link
Member Author

@jelbourn Applied the changes we discussed per Chat. Please have another look.

@devversion devversion changed the title fix(toolbar): don't auto-generate first row if first row would be empty fix(toolbar): no longer auto-generate toolbar rows Aug 31, 2017
</md-toolbar-row>
</md-toolbar>
```

**Note**: Placing content outside of a `<md-toolbar-row>` when multiple rows are specified, is not
supported.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Superfluous comma

@@ -39,15 +42,43 @@ export const _MdToolbarMixinBase = mixinColor(MdToolbarBase);
inputs: ['color'],
host: {
'class': 'mat-toolbar',
'role': 'toolbar'
'role': 'toolbar',
Copy link
Member

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)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point

export class MdToolbar extends _MdToolbarMixinBase implements CanColor, AfterViewInit {

/** Reference to all toolbar row elements that have been projected. */
@ContentChildren(MdToolbarRow) _toolbarRows: QueryList<MdToolbarRow>;
Copy link
Member

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

Copy link
Member Author

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.

Copy link
Member

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

Copy link
Member Author

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)

Copy link
Member

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.

Copy link
Member

@jelbourn jelbourn left a 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

@jelbourn jelbourn added merge: caretaker note Alert the caretaker performing the merge to check the PR for an out of normal action needed or note pr: lgtm and removed pr: needs review labels Sep 6, 2017
@jelbourn
Copy link
Member

jelbourn commented Sep 6, 2017

Caretaker note: this is a breaking change. For anyone that has custom styling on md-toolbar-row but isn't explicitly putting md-toolbar-row in their template, we'll need to add it to their template.

@devversion devversion added the action: merge The PR is ready for merge by the caretaker label Sep 6, 2017
@devversion
Copy link
Member Author

@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)

@devversion devversion added the P1 Impacts a large percentage of users; if a workaround exists it is partial or overly painful label Sep 15, 2017
@mmalerba
Copy link
Contributor

please rebase

@mmalerba mmalerba removed the action: merge The PR is ready for merge by the caretaker label Sep 15, 2017
@devversion
Copy link
Member Author

@mmalerba Done. e2e screenshot uploading seems to timeout (unrelated)

@devversion devversion added the action: merge The PR is ready for merge by the caretaker label Sep 16, 2017
@devversion devversion force-pushed the fix/toolbar-auto-generated-row branch 2 times, most recently from af61632 to caee86a Compare September 22, 2017 14:34
@kara kara added the presubmit failures This PR has failures in Google's internal presubmit process and cannot be immediately merged label Oct 5, 2017
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.
@devversion devversion force-pushed the fix/toolbar-auto-generated-row branch from ccc2608 to aeb3bd0 Compare October 5, 2017 15:07
@andrewseguin andrewseguin merged commit c3405aa into angular:master Oct 31, 2017
@angular-automatic-lock-bot
Copy link

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Sep 7, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
action: merge The PR is ready for merge by the caretaker cla: yes PR author has agreed to Google's Contributor License Agreement merge: caretaker note Alert the caretaker performing the merge to check the PR for an out of normal action needed or note P1 Impacts a large percentage of users; if a workaround exists it is partial or overly painful presubmit failures This PR has failures in Google's internal presubmit process and cannot be immediately merged
Projects
None yet
7 participants