Repository navigation
feat(list): add new '<mat-action-list>' - #12415
Conversation
| # schematics | ||
| /src/lib/schematics/**/*.js | ||
| /src/lib/schematics/**/*.map | ||
| /src/lib/schematics/**/*.map No newline at end of file |
There was a problem hiding this comment.
Can you configure your IDE to always add a newline at the end of files? Looks like it removed the newline here.
| </div> | ||
|
|
||
| <div> | ||
| <h2>Button lists</h2> |
There was a problem hiding this comment.
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 }} |
There was a problem hiding this comment.
Omit space in braces
{{link.name}}| this.modelChangeEventCount++; | ||
| } | ||
|
|
||
| onButtonClick(msg: string) { |
There was a problem hiding this comment.
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 {} |
There was a problem hiding this comment.
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', |
There was a problem hiding this comment.
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', |
There was a problem hiding this comment.
The selector for the new variant should be mat-action-list
|
|
||
| .mat-button-list { | ||
| //remove the native button look and make is look like a list item | ||
| button { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
We discussed and decided to go with the current nav list pattern.
| @Component({ | ||
| moduleId: module.id, | ||
| selector: 'mat-list-item, a[mat-list-item]', | ||
| selector: 'mat-list-item, a[mat-list-item], button[mat-list-item]', |
There was a problem hiding this comment.
We'll need to add documentation for the new list variant to list.md
|
|
||
| .mat-list-option, | ||
| .mat-nav-list .mat-list-item { | ||
| .mat-nav-list .mat-button-list .mat-list-item { |
There was a problem hiding this comment.
This selector doesn't look correct. It'll target items inside a button list that is inside a nav list.
|
|
||
| // Default list | ||
| .mat-list, .mat-nav-list, .mat-selection-list { | ||
| .mat-list, .mat-nav-list, .mat-button-list, .mat-selection-list { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Agreed, we should do that in a follow-up PR.
224eb2d to
0f5d2ee
Compare
vivian-hu-zz
left a comment
There was a problem hiding this comment.
Please take a look again.
| items.forEach(item => expect(item._isRippleDisabled()).toBe(true)); | ||
| }); | ||
|
|
||
| it('action list should be created successfully', () => { |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
Indenting here should be 2 spaces instead of 4
| # IDEs | ||
| /.idea | ||
| /.vscode | ||
| *.iml |
There was a problem hiding this comment.
Where did this additional line come from?
There was a problem hiding this comment.
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)"> |
There was a problem hiding this comment.
Extra whitespace character after mat-list-item
| } | ||
|
|
||
| alertItem(msg: string) { | ||
| alert(msg); |
There was a problem hiding this comment.
Maybe use a snack bar instead?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
This app is only for our own development, so it doesn't really matter what the action does.
|
|
||
| ### Action lists | ||
|
|
||
| Use `mat-action-list` tags for action lists (i.e. lists that have button tags). |
There was a problem hiding this comment.
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.)
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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)"> |
There was a problem hiding this comment.
- Extra whitespace character after
mat-list-item - Show what the
alertItemfunction does
There was a problem hiding this comment.
removed the white space. Also removed the click part since it is not showing the key point here and may cause unnecessary confusion.
| } | ||
|
|
||
| mat-action-list { | ||
| //remove the native button look and make is look like a list item |
There was a problem hiding this comment.
Nitpick: is should be it
|
Hi @vivian-hu! This PR has merge conflicts due to recent upstream merges. |
|
|
||
| ### Action lists | ||
|
|
||
| Use `mat-action-list` tags for action lists (i.e. lists that have button tags). |
There was a problem hiding this comment.
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> |
There was a problem hiding this comment.
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
ngFormakes it a bit simpler - Adding a
(click)handler shows how the action is performed
| @Component({ | ||
| moduleId: module.id, | ||
| selector: 'mat-list-item, a[mat-list-item]', | ||
| selector: 'mat-list-item, a[mat-list-item], button[mat-list-item]', |
There was a problem hiding this comment.
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.
| }); | ||
|
|
||
| it('should create an action list', () => { | ||
| let fixture = TestBed.createComponent(ActionListWithoutType); |
There was a problem hiding this comment.
Prefer const over let whenever the variable isn't going to be assigned to something else
84b95c2 to
36e534c
Compare
vivian-hu-zz
left a comment
There was a problem hiding this comment.
fixed const vs. let.
|
Commit message should be |
|
|
||
| mat-action-list { | ||
| //remove the native button look and make it look like a list item | ||
| button { |
There was a problem hiding this comment.
Shouldn't this apply to all buttons for any .mat-list-item not just the ones under a mat-action-list?
There was a problem hiding this comment.
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(); |
There was a problem hiding this comment.
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(); |
There was a problem hiding this comment.
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' |
There was a problem hiding this comment.
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');
}There was a problem hiding this comment.
I actually prefer always doing nodeName since it's guaranteed to be safe. It should probably be in the coding standards...
vivian-hu-zz
left a comment
There was a problem hiding this comment.
more update based on Joey's feedback
|
|
||
| mat-action-list { | ||
| //remove the native button look and make it look like a list item | ||
| button { |
There was a problem hiding this comment.
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.
|
Hi @vivian-hu! This PR has merge conflicts due to recent upstream merges. |
simple list only in this check in
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.
|
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. |
simple list only in this check in