Skip to content

Commit 633fe76

Browse files
committed
hook up rest of edit icon
1 parent f9f1718 commit 633fe76

File tree

6 files changed

+36
-16
lines changed

6 files changed

+36
-16
lines changed

src/material/chips/chip-action.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ export class MatChipAction {
4343
_handlePrimaryActionInteraction(): void;
4444
remove(): void;
4545
disabled: boolean;
46+
_edit(): void;
4647
_isEditing?: boolean;
4748
}>(MAT_CHIP);
4849

src/material/chips/chip-icons.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,15 +76,15 @@ export class MatChipEdit extends MatChipAction {
7676
if (!this.disabled) {
7777
event.stopPropagation();
7878
event.preventDefault();
79-
// this._parentChip.remove();
79+
this._parentChip._edit();
8080
}
8181
}
8282

8383
override _handleKeydown(event: KeyboardEvent) {
8484
if ((event.keyCode === ENTER || event.keyCode === SPACE) && !this.disabled) {
8585
event.stopPropagation();
8686
event.preventDefault();
87-
// this._parentChip.remove();
87+
this._parentChip._edit();
8888
}
8989
}
9090
}

src/material/chips/chip-row.html

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,19 @@
22
<span class="mat-mdc-chip-focus-overlay"></span>
33
}
44

5-
@if (editIcon) {
5+
@if (!_isEditing && editIcon) {
66
<span
77
class="mdc-evolution-chip__cell mdc-evolution-chip__cell--primary"
88
role="gridcell">
9-
<ng-content select="[matChipEdit]"></ng-content>
9+
<ng-content select="[matChipEdit]"></ng-content>
1010
</span>
1111
}
1212
<span class="mdc-evolution-chip__cell mdc-evolution-chip__cell--primary" role="gridcell"
1313
matChipAction
1414
[disabled]="disabled"
1515
[attr.aria-label]="ariaLabel"
1616
[attr.aria-describedby]="_ariaDescriptionId">
17-
@if (leadingIcon) {
17+
@if (!_isEditing && leadingIcon) {
1818
<span class="mdc-evolution-chip__graphic mat-mdc-chip-graphic">
1919
<ng-content select="mat-chip-avatar, [matChipAvatar]"></ng-content>
2020
</span>

src/material/chips/chip-row.ts

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -90,9 +90,6 @@ export class MatChipRow extends MatChip implements AfterViewInit {
9090
/** The default chip edit input that is used if none is projected into this chip row. */
9191
@ViewChild(MatChipEditInput) defaultEditInput?: MatChipEditInput;
9292

93-
/** The chip's leading edit icon. */
94-
@ContentChild(MAT_CHIP_EDIT) editIcon: MatChipEdit;
95-
9693
/** The projected chip edit input. */
9794
@ContentChild(MatChipEditInput) contentEditInput?: MatChipEditInput;
9895

@@ -113,7 +110,7 @@ export class MatChipRow extends MatChip implements AfterViewInit {
113110

114111
/** Returns whether the chip has a leading icon. */
115112
_hasLeadingIcon() {
116-
return !!(this.editIcon || this.leadingIcon);
113+
return !this._isEditing && !!(this.editIcon || this.leadingIcon);
117114
}
118115

119116
override _hasTrailingIcon() {
@@ -144,16 +141,26 @@ export class MatChipRow extends MatChip implements AfterViewInit {
144141
}
145142
}
146143

147-
_handleDoubleclick(event: MouseEvent) {
144+
_handleDoubleclick(event: Event) {
148145
if (!this.disabled && this.editable) {
149146
this._startEditing(event);
150147
}
151148
}
152149

153-
private _startEditing(event: Event) {
150+
override _edit(): void {
151+
if (!this.disabled && this.editable) {
152+
// markForCheck necessary for edit input to be rendered
153+
this._changeDetectorRef.markForCheck();
154+
this._startEditing();
155+
}
156+
}
157+
158+
private _startEditing(event?: Event) {
154159
if (
155160
!this.primaryAction ||
156-
(this.removeIcon && this._getSourceAction(event.target as Node) === this.removeIcon)
161+
(this.removeIcon &&
162+
!!event &&
163+
this._getSourceAction(event.target as Node) === this.removeIcon)
157164
) {
158165
return;
159166
}
@@ -167,7 +174,7 @@ export class MatChipRow extends MatChip implements AfterViewInit {
167174
afterNextRender(
168175
() => {
169176
this._getEditInput().initialize(value);
170-
this._editStartPending = false;
177+
setTimeout(() => this._ngZone.run(() => (this._editStartPending = false)));
171178
},
172179
{injector: this._injector},
173180
);

src/material/chips/chip.scss

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -528,7 +528,7 @@ $token-slots: m2-chip.get-token-slots();
528528
}
529529
}
530530

531-
.mat-mdc-chip-remove {
531+
.mat-mdc-chip-edit, .mat-mdc-chip-remove {
532532
opacity: token-utils.slot(trailing-action-opacity);
533533

534534
&:focus {
@@ -680,7 +680,7 @@ $token-slots: m2-chip.get-token-slots();
680680
}
681681
}
682682

683-
.mat-mdc-chip-remove {
683+
.mat-mdc-chip-edit, .mat-mdc-chip-remove {
684684
&::before {
685685
$default-border-width: focus-indicators-private.$default-border-width;
686686
$offset: var(--mat-focus-indicator-border-width, #{$default-border-width});
@@ -744,6 +744,6 @@ $token-slots: m2-chip.get-token-slots();
744744
// Prevents icon from being cut off when text spacing is increased.
745745
// .mat-mdc-chip-remove selector necessary for remove button with icon.
746746
// Fixes b/250063405.
747-
.mdc-evolution-chip__icon, .mat-mdc-chip-remove .mat-icon {
747+
.mdc-evolution-chip__icon, .mat-mdc-chip-edit .mat-icon, .mat-mdc-chip-remove .mat-icon {
748748
min-height: fit-content;
749749
}

src/material/chips/chip.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,9 @@ export class MatChip implements OnInit, AfterViewInit, AfterContentInit, DoCheck
235235
/** The chip's leading icon. */
236236
@ContentChild(MAT_CHIP_AVATAR) leadingIcon: MatChipAvatar;
237237

238+
/** The chip's leading edit icon. */
239+
@ContentChild(MAT_CHIP_EDIT) editIcon: MatChipEdit;
240+
238241
/** The chip's trailing icon. */
239242
@ContentChild(MAT_CHIP_TRAILING_ICON) trailingIcon: MatChipTrailingIcon;
240243

@@ -369,6 +372,10 @@ export class MatChip implements OnInit, AfterViewInit, AfterContentInit, DoCheck
369372
_getActions(): MatChipAction[] {
370373
const result: MatChipAction[] = [];
371374

375+
if (this.editIcon) {
376+
result.push(this.editIcon);
377+
}
378+
372379
if (this.primaryAction) {
373380
result.push(this.primaryAction);
374381
}
@@ -389,6 +396,11 @@ export class MatChip implements OnInit, AfterViewInit, AfterContentInit, DoCheck
389396
// Empty here, but is overwritten in child classes.
390397
}
391398

399+
/** Handles interactions with the edit action of the chip. */
400+
_edit(event: Event) {
401+
// Empty here, but is overwritten in child classes.
402+
}
403+
392404
/** Starts the focus monitoring process on the chip. */
393405
private _monitorFocus() {
394406
this._focusMonitor.monitor(this._elementRef, true).subscribe(origin => {

0 commit comments

Comments
 (0)