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

feat(list): add new '<mat-action-list>' #12415

Merged
merged 5 commits into from
Sep 11, 2018
Merged

Conversation

vivian-hu-zz
Copy link
Contributor

simple list only in this check in

@googlebot googlebot added the cla: yes PR author has agreed to Google's Contributor License Agreement label Jul 27, 2018
@jelbourn jelbourn added the target: major This PR is targeted for the next major release label Jul 27, 2018
.gitignore Outdated
@@ -41,4 +42,4 @@ testem.log

# schematics
/src/lib/schematics/**/*.js
/src/lib/schematics/**/*.map
/src/lib/schematics/**/*.map
Copy link
Member

Choose a reason for hiding this comment

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

Can you configure your IDE to always add a newline at the end of files? Looks like it removed the newline here.

@@ -104,6 +104,15 @@ <h2>Nav lists</h2>
</mat-nav-list>
</div>

<div>
<h2>Button lists</h2>
Copy link
Member

Choose a reason for hiding this comment

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

This should be "Action list"

<h2>Button lists</h2>
<mat-button-list>
<button mat-list-item *ngFor="let link of links" (click)="onButtonClick(link.name)">
{{ link.name }}
Copy link
Member

Choose a reason for hiding this comment

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

Omit space in braces

{{link.name}}

@@ -69,4 +69,8 @@ export class ListDemo {
this.selectedOptions = values;
this.modelChangeEventCount++;
}

onButtonClick(msg: string) {
Copy link
Member

Choose a reason for hiding this comment

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

Prefer to name methods for what they do rather than how they're called, e.g. alertItem(...)

(this doesn't really matter for demos, but I mention it just as an FYI)

encapsulation: ViewEncapsulation.None,
changeDetection: ChangeDetectionStrategy.OnPush,
})
export class MatButtonList extends _MatListMixinBase implements CanDisableRipple {}
Copy link
Member

Choose a reason for hiding this comment

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

Since it looks like .mat-button-list doesn't differ from .mat-list for any styles or behavior, you should be able to just add mat-action-list to the existing selector for MatList without creating a new component

selector: 'mat-button-list',
exportAs: 'matButtonList',
host: {
'role': 'button list',
Copy link
Member

Choose a reason for hiding this comment

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

role corresponds to single value that defines the interaction pattern for an element:
https://www.w3.org/WAI/PF/HTML/wiki/RoleAttribute

There isn't any role that corresponds to a list of actions, so this isn't necessary here.


@Component({
moduleId: module.id,
selector: 'mat-button-list',
Copy link
Member

Choose a reason for hiding this comment

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

The selector for the new variant should be mat-action-list

@@ -262,6 +262,22 @@ $mat-list-item-inset-divider-offset: 72px;
}
}

.mat-button-list {
//remove the native button look and make is look like a list item
button {
Copy link
Member

Choose a reason for hiding this comment

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

Rather than using two levels of selector (.mat-button-list button), it would be slightly better to use a single css class (.mat-action-list-item) for this style. This will have a lower specificity and make it easier for users to customize the css.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We discussed and decided to go with the current nav list pattern.

@@ -92,7 +109,7 @@ export class MatListSubheaderCssMatStyler {}
/** An item within a Material Design list. */
@Component({
moduleId: module.id,
selector: 'mat-list-item, a[mat-list-item]',
selector: 'mat-list-item, a[mat-list-item], button[mat-list-item]',
Copy link
Member

Choose a reason for hiding this comment

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

We'll need to add documentation for the new list variant to list.md

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

@@ -27,7 +27,7 @@
}

.mat-list-option,
.mat-nav-list .mat-list-item {
.mat-nav-list .mat-button-list .mat-list-item {
Copy link
Member

Choose a reason for hiding this comment

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

This selector doesn't look correct. It'll target items inside a button list that is inside a nav list.

@@ -46,7 +46,7 @@
}

// Default list
.mat-list, .mat-nav-list, .mat-selection-list {
.mat-list, .mat-nav-list, .mat-button-list, .mat-selection-list {
Copy link
Member

Choose a reason for hiding this comment

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

Not something necessarily for this PR, but at some point we should add a class like mat-list-base and use it for cases like this one. Since this selector has a few nested under it, the amount of CSS is going to increase a lot as we add more list types.

Copy link
Member

Choose a reason for hiding this comment

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

Agreed, we should do that in a follow-up PR.

@vivian-hu-zz vivian-hu-zz force-pushed the firstbug branch 2 times, most recently from 224eb2d to 0f5d2ee Compare July 30, 2018 23:26
Copy link
Contributor Author

@vivian-hu-zz vivian-hu-zz left a comment

Choose a reason for hiding this comment

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

Please take a look again.

@@ -144,6 +145,14 @@ describe('MatList', () => {
items.forEach(item => expect(item._isRippleDisabled()).toBe(true));
});

it('action list should be created successfully', () => {
Copy link
Contributor

@EdricChan03 EdricChan03 Jul 31, 2018

Choose a reason for hiding this comment

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

Looks like the grammar wouldn't make sense here when testing with Karma.

This would make more sense:

it('should create an action list', () => {})

@Component({template: `
<mat-action-list>
<button mat-list-item>
Paprika
Copy link
Contributor

@EdricChan03 EdricChan03 Jul 31, 2018

Choose a reason for hiding this comment

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

Indenting here should be 2 spaces instead of 4

.gitignore Outdated
@@ -27,6 +27,7 @@ node_modules
# IDEs
/.idea
/.vscode
*.iml
Copy link
Contributor

Choose a reason for hiding this comment

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

Where did this additional line come from?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is the ide file

<div>
<h2>Action list</h2>
<mat-action-list>
<button mat-list-item *ngFor="let link of links" (click)="alertItem(link.name)">
Copy link
Contributor

Choose a reason for hiding this comment

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

Extra whitespace character after mat-list-item

@@ -69,4 +69,8 @@ export class ListDemo {
this.selectedOptions = values;
this.modelChangeEventCount++;
}

alertItem(msg: string) {
alert(msg);
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe use a snack bar instead?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

A snack bar will look nicer. It can be done later in my opinion. I am new to angular, so try to do small check in without taking too long to deal with merge conflict etc.

Copy link
Member

Choose a reason for hiding this comment

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

This app is only for our own development, so it doesn't really matter what the action does.

@@ -42,6 +42,20 @@ element in an `<mat-list-item>`.
</mat-nav-list>
```

### Action lists

Use `mat-action-list` tags for action lists (i.e. lists that have button tags).
Copy link
Contributor

@EdricChan03 EdricChan03 Jul 31, 2018

Choose a reason for hiding this comment

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

Maybe rephrase this sentence to this?

A <mat-action-list> element is used for action lists (i.e. lists that have button tags.)

(This is based on the earlier section about navigation lists.)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The navigation list is actually doing the same as what I have put in originally. And I feel "use xxx" is more clear than "xxx is used" here.

Copy link
Member

Choose a reason for hiding this comment

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

I would word this as

Use the `<mat-action-list>` element when each item in the list performs some _action_. Each item
in an action list is a `<button>` element.

<!-- example here -->

I think it would also be good to change the nav-list section similarly, but that can be done in another PR.


```html
<mat-action-list>
<button mat-list-item *ngFor="let link of links" (click)="alertItem(link.name)">
Copy link
Contributor

Choose a reason for hiding this comment

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

  1. Extra whitespace character after mat-list-item
  2. Show what the alertItem function does

Copy link
Contributor Author

Choose a reason for hiding this comment

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

removed the white space. Also removed the click part since it is not showing the key point here and may cause unnecessary confusion.

@@ -262,6 +262,22 @@ $mat-list-item-inset-divider-offset: 72px;
}
}

mat-action-list {
//remove the native button look and make is look like a list item
Copy link
Contributor

Choose a reason for hiding this comment

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

Nitpick: is should be it

@ngbot
Copy link

ngbot bot commented Jul 31, 2018

Hi @vivian-hu! This PR has merge conflicts due to recent upstream merges.
Please help to unblock it by resolving these conflicts. Thanks!

@@ -42,6 +42,20 @@ element in an `<mat-list-item>`.
</mat-nav-list>
```

### Action lists

Use `mat-action-list` tags for action lists (i.e. lists that have button tags).
Copy link
Member

Choose a reason for hiding this comment

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

I would word this as

Use the `<mat-action-list>` element when each item in the list performs some _action_. Each item
in an action list is a `<button>` element.

<!-- example here -->

I think it would also be good to change the nav-list section similarly, but that can be done in another PR.

```html
<mat-action-list>
<button mat-list-item *ngFor="let link of links"> {{link.name}} </button>
</mat-action-list>
Copy link
Member

Choose a reason for hiding this comment

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

I would make the following changes:

<mat-action-list>
  <button mat-list-item (click)="save()">Save</button>
  <button mat-list-item (click)="undo()">Undo</button>
</mat-action-list>
  • Getting rid of ngFor makes it a bit simpler
  • Adding a (click) handler shows how the action is performed

@@ -92,7 +92,7 @@ export class MatListSubheaderCssMatStyler {}
/** An item within a Material Design list. */
@Component({
moduleId: module.id,
selector: 'mat-list-item, a[mat-list-item]',
selector: 'mat-list-item, a[mat-list-item], button[mat-list-item]',
Copy link
Member

Choose a reason for hiding this comment

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

One last thing that occurred to me just now- we should default all buttons with mat-list-item to have type="button". By default, <button> elements are type="submit", which you would never really want in an action list.

Copy link
Contributor Author

@vivian-hu-zz vivian-hu-zz left a comment

Choose a reason for hiding this comment

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

add default type to button and also added unit testing to test it. Updated wording according to Jeremy's suggestion.

@@ -144,6 +146,30 @@ describe('MatList', () => {
items.forEach(item => expect(item._isRippleDisabled()).toBe(true));
});

it('should create an action list', () => {
let fixture = TestBed.createComponent(ActionListWithoutType);
Copy link
Member

Choose a reason for hiding this comment

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

Prefer const over let whenever the variable isn't going to be assigned to something else

@vivian-hu-zz vivian-hu-zz force-pushed the firstbug branch 2 times, most recently from 84b95c2 to 36e534c Compare August 3, 2018 22:59
Copy link
Contributor Author

@vivian-hu-zz vivian-hu-zz left a comment

Choose a reason for hiding this comment

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

fixed const vs. let.

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

@jelbourn jelbourn added pr: lgtm action: merge The PR is ready for merge by the caretaker merge: fix commit message When the PR is merged, rewrites/fixups of the commit messages are needed labels Aug 4, 2018
@jelbourn
Copy link
Member

jelbourn commented Aug 7, 2018

Commit message should be

feat(list): add new `<mat-action-list>`

An action-list is a list where each list item is a native `<button>` element,
meant to be used in cases where each list item has a single action with
no sub-actions, navigation, or selection.

@vivian-hu-zz vivian-hu-zz changed the title feat(list): add button as the underlining element for a list item feat(list): add new '<mat-action-list>' Aug 7, 2018
@@ -262,6 +262,22 @@ $mat-list-item-inset-divider-offset: 72px;
}
}

mat-action-list {
//remove the native button look and make it look like a list item
button {
Copy link
Member

Choose a reason for hiding this comment

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

Shouldn't this apply to all buttons for any .mat-list-item not just the ones under a mat-action-list?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

As we talked, we added mat-action-list specifically for action list to make it more clear, so the idea is to let user use it under mat-action-list.


// If no type attributed is specified for <button>, set it to "button".
// If a type attribute is already specified, do nothing.
let element: HTMLElement = this._getHostElement();
Copy link
Member

Choose a reason for hiding this comment

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

const should be used here instead of let since element does not get reassigned.


// If no type attributed is specified for <button>, set it to "button".
// If a type attribute is already specified, do nothing.
let element: HTMLElement = this._getHostElement();
Copy link
Member

Choose a reason for hiding this comment

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

Since _getHostElement() defines the return type of HTMLElement, you don't need to define the type for the element variable.

// If no type attributed is specified for <button>, set it to "button".
// If a type attribute is already specified, do nothing.
let element: HTMLElement = this._getHostElement();
if (element.nodeName && element.nodeName.toLowerCase() === 'button'
Copy link
Member

Choose a reason for hiding this comment

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

You could actually check tagName. Since element is already a type of HtmlElement, you shouldn't need to check if a tagName is defined since it always will have tagName by definition of the HtmlElement interface.

Additionally, you can just set the attribute type without performing a check beforehand.

if (element.tagName === 'BUTTON') {
  element.setAttribute('type', element.getAttribute('type') || 'button');
}

Copy link
Member

Choose a reason for hiding this comment

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

I actually prefer always doing nodeName since it's guaranteed to be safe. It should probably be in the coding standards...

Copy link
Contributor Author

@vivian-hu-zz vivian-hu-zz left a comment

Choose a reason for hiding this comment

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

more update based on Joey's feedback

@@ -262,6 +262,22 @@ $mat-list-item-inset-divider-offset: 72px;
}
}

mat-action-list {
//remove the native button look and make it look like a list item
button {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

As we talked, we added mat-action-list specifically for action list to make it more clear, so the idea is to let user use it under mat-action-list.

@ngbot
Copy link

ngbot bot commented Aug 31, 2018

Hi @vivian-hu! This PR has merge conflicts due to recent upstream merges.
Please help to unblock it by resolving these conflicts. Thanks!

Vivian Hu added 5 commits August 31, 2018 15:13
An action-list is a list where each list item is a native '<button>' element, meant to be used in cases where each list item has a single action with no sub-action, navigation or selection.
@jelbourn jelbourn merged commit 69fa762 into angular:master Sep 11, 2018
@mitchellwills mitchellwills mentioned this pull request Oct 10, 2018
@vivian-hu-zz vivian-hu-zz deleted the firstbug branch January 23, 2019 23:00
@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 10, 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: fix commit message When the PR is merged, rewrites/fixups of the commit messages are needed target: major This PR is targeted for the next major release
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants