Skip to content

Commit 85ead4b

Browse files
Di-did-doneDinara Nikolaeva
authored andcommitted
fix(tags): remove circular dependencies (#UIM-872) (#816)
Co-authored-by: Dinara Nikolaeva <[email protected]>
1 parent 69c71be commit 85ead4b

File tree

1 file changed

+45
-45
lines changed

1 file changed

+45
-45
lines changed

packages/mosaic/tags/tag.component.ts

Lines changed: 45 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import {
99
ElementRef,
1010
EventEmitter,
1111
forwardRef,
12+
Inject,
1213
Input,
1314
NgZone,
1415
OnDestroy,
@@ -64,6 +65,50 @@ export class McTagAvatar {}
6465
})
6566
export class McTagTrailingIcon {}
6667

68+
/**
69+
*
70+
* Example:
71+
*
72+
* `<mc-tag>
73+
* <mc-icon mcTagRemove>cancel</mc-icon>
74+
* </mc-tag>`
75+
*
76+
* You *may* use a custom icon, but you may need to override the `mc-tag-remove` positioning
77+
* styles to properly center the icon within the tag.
78+
*/
79+
@Directive({
80+
selector: '[mcTagRemove]',
81+
host: {
82+
class: 'mc-tag-remove mc-tag-trailing-icon',
83+
'[attr.tabindex]': '-1',
84+
'(click)': 'handleClick($event)',
85+
'(focus)': 'focus($event)'
86+
}
87+
})
88+
export class McTagRemove {
89+
constructor(@Inject(forwardRef(() => McTag)) protected parentTag: McTag) {}
90+
91+
focus($event): void {
92+
$event.stopPropagation();
93+
}
94+
95+
/** Calls the parent tag's public `remove()` method if applicable. */
96+
handleClick(event: Event): void {
97+
if (this.parentTag.removable) {
98+
this.parentTag.hasFocus = true;
99+
100+
this.parentTag.remove();
101+
}
102+
103+
// We need to stop event propagation because otherwise the event will bubble up to the
104+
// form field and cause the `onContainerClick` method to be invoked. This method would then
105+
// reset the focused tag that has been focused after tag removal. Usually the parent
106+
// the parent click listener of the `McTag` would prevent propagation, but it can happen
107+
// that the tag is being removed before the event bubbles up.
108+
event.stopPropagation();
109+
}
110+
}
111+
67112
export class McTagBase {
68113
// tslint:disable-next-line:naming-convention
69114
constructor(public _elementRef: ElementRef) {}
@@ -391,48 +436,3 @@ export class McTag extends McTagMixinBase implements IFocusableOption, OnDestroy
391436
});
392437
}
393438
}
394-
395-
396-
/**
397-
*
398-
* Example:
399-
*
400-
* `<mc-tag>
401-
* <mc-icon mcTagRemove>cancel</mc-icon>
402-
* </mc-tag>`
403-
*
404-
* You *may* use a custom icon, but you may need to override the `mc-tag-remove` positioning
405-
* styles to properly center the icon within the tag.
406-
*/
407-
@Directive({
408-
selector: '[mcTagRemove]',
409-
host: {
410-
class: 'mc-tag-remove mc-tag-trailing-icon',
411-
'[attr.tabindex]': '-1',
412-
'(click)': 'handleClick($event)',
413-
'(focus)': 'focus($event)'
414-
}
415-
})
416-
export class McTagRemove {
417-
constructor(protected parentTag: McTag) {}
418-
419-
focus($event): void {
420-
$event.stopPropagation();
421-
}
422-
423-
/** Calls the parent tag's public `remove()` method if applicable. */
424-
handleClick(event: Event): void {
425-
if (this.parentTag.removable) {
426-
this.parentTag.hasFocus = true;
427-
428-
this.parentTag.remove();
429-
}
430-
431-
// We need to stop event propagation because otherwise the event will bubble up to the
432-
// form field and cause the `onContainerClick` method to be invoked. This method would then
433-
// reset the focused tag that has been focused after tag removal. Usually the parent
434-
// the parent click listener of the `McTag` would prevent propagation, but it can happen
435-
// that the tag is being removed before the event bubbles up.
436-
event.stopPropagation();
437-
}
438-
}

0 commit comments

Comments
 (0)