|
9 | 9 | ElementRef, |
10 | 10 | EventEmitter, |
11 | 11 | forwardRef, |
| 12 | + Inject, |
12 | 13 | Input, |
13 | 14 | NgZone, |
14 | 15 | OnDestroy, |
@@ -64,6 +65,50 @@ export class McTagAvatar {} |
64 | 65 | }) |
65 | 66 | export class McTagTrailingIcon {} |
66 | 67 |
|
| 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 | + |
67 | 112 | export class McTagBase { |
68 | 113 | // tslint:disable-next-line:naming-convention |
69 | 114 | constructor(public _elementRef: ElementRef) {} |
@@ -391,48 +436,3 @@ export class McTag extends McTagMixinBase implements IFocusableOption, OnDestroy |
391 | 436 | }); |
392 | 437 | } |
393 | 438 | } |
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