|
8 | 8 | HostListener, |
9 | 9 | Input, |
10 | 10 | NgZone, |
| 11 | + OnChanges, |
11 | 12 | Renderer2, |
| 13 | + SimpleChanges, |
12 | 14 | TemplateRef, |
13 | 15 | ViewChild |
14 | 16 | } from "@angular/core"; |
@@ -47,7 +49,7 @@ import { PopoverContainer } from "carbon-components-angular/popover"; |
47 | 49 | </span> |
48 | 50 | ` |
49 | 51 | }) |
50 | | -export class Tooltip extends PopoverContainer implements AfterContentChecked { |
| 52 | +export class Tooltip extends PopoverContainer implements OnChanges, AfterContentChecked { |
51 | 53 | static tooltipCount = 0; |
52 | 54 |
|
53 | 55 | @HostBinding("class.cds--tooltip") tooltipClass = true; |
@@ -132,6 +134,29 @@ export class Tooltip extends PopoverContainer implements AfterContentChecked { |
132 | 134 | return value instanceof TemplateRef; |
133 | 135 | } |
134 | 136 |
|
| 137 | + /** |
| 138 | + * Close the popover and reopen it with updated values without emitting an event |
| 139 | + * @param changes |
| 140 | + */ |
| 141 | + ngOnChanges(changes: SimpleChanges): void { |
| 142 | + // Close and reopen the popover, handle alignment/programmatic open/close |
| 143 | + const originalState = this.isOpen; |
| 144 | + this.handleChange(false); |
| 145 | + |
| 146 | + // Ignore first change since content is not initialized |
| 147 | + if ((changes.autoAlign && !changes.autoAlign.firstChange) |
| 148 | + || (changes.disabled && !changes.disabled.firstChange && !changes.disabled.currentValue)) { |
| 149 | + // Update view before getting popover content |
| 150 | + this.changeDetectorRef.detectChanges(); |
| 151 | + // Reset the inline styles |
| 152 | + this.popoverContentRef = this.elementRef.nativeElement.querySelector(".cds--popover-content"); |
| 153 | + this.popoverContentRef.setAttribute("style", ""); |
| 154 | + this.caretRef = this.elementRef.nativeElement.querySelector("span.cds--popover-caret"); |
| 155 | + } |
| 156 | + |
| 157 | + this.handleChange(originalState); |
| 158 | + } |
| 159 | + |
135 | 160 | /** |
136 | 161 | * Check for any changes in the projected content & apply accessibility attribute if needed |
137 | 162 | */ |
|
0 commit comments