-
Notifications
You must be signed in to change notification settings - Fork 6.8k
feat(material/chips): add (optional) edit icon to input chips #31041
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
base: main
Are you sure you want to change the base?
Conversation
Deployed dev-app for 809e1e8 to: https://ng-dev-previews-comp--pr-angular-components-31041-dev-jgj91wpx.web.app Note: As new commits are pushed to this pull request, this link is updated after the preview is rebuilt. |
c0b7505
to
0dfcea0
Compare
5a782e6
to
d5b2141
Compare
4960510
to
809e1e8
Compare
class="mdc-evolution-chip__cell mdc-evolution-chip__cell--primary" | ||
role="gridcell"> | ||
<ng-content select="[matChipEdit]"></ng-content> | ||
</span> |
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.
nit: formatting appears to be off here.
if ((event.keyCode === ENTER || event.keyCode === SPACE) && !this.disabled) { | ||
event.stopPropagation(); | ||
event.preventDefault(); | ||
this._parentChip._edit(); |
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 appears to allow editing even if the chip isn't marked as editable.
selector: '[matChipEdit]', | ||
host: { | ||
'class': | ||
'mat-mdc-chip-edit mat-mdc-chip-avatar mat-focus-indicator ' + |
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 shouldn't reuse the avatar class here since this isn't the avatar.
- The focus indicator class already comes from whatever is used as the edit trigger (e.g.
matButton
).
* | ||
* ``` | ||
* <mat-chip> | ||
* <button matChipEdit aria-label="Edit"> |
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.
Should the component show matIconButton
?
@@ -107,6 +108,11 @@ export class MatChipRow extends MatChip implements AfterViewInit { | |||
}); | |||
} | |||
|
|||
/** Returns whether the chip has a leading icon. */ | |||
_hasLeadingIcon() { |
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 one can be made protected so it's not exposed as a public API.
@@ -107,6 +108,11 @@ export class MatChipRow extends MatChip implements AfterViewInit { | |||
}); | |||
} | |||
|
|||
/** Returns whether the chip has a leading icon. */ | |||
_hasLeadingIcon() { | |||
return !this._isEditing && !!(this.editIcon || this.leadingIcon); |
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.
Won't this end up hiding the avatar if the chip is being edited?
@@ -158,7 +172,7 @@ export class MatChipRow extends MatChip implements AfterViewInit { | |||
afterNextRender( | |||
() => { | |||
this._getEditInput().initialize(value); | |||
this._editStartPending = false; | |||
setTimeout(() => this._ngZone.run(() => (this._editStartPending = false))); |
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.
Why do we need a timeout here?
Adds an optional edit icon to input chips to allow for better discoverability of editable chips over existing double-click and focus-enter to edit behavior.
The edit icon introduces concept of a leading action with an icon button similar to trailing action used for delete icon button. This can be combined with the existing avatar icon for a chip. The editable flag is preserved but is independent of the edit icon, allowing for both existing and new behavior or either one.
Updated chip demo to add option to show avatar and/or edit icon.