Skip to content

Commit cbbe2b6

Browse files
committed
fix: refresh view on disabled or autoalign changes
Signed-off-by: Akshat Patel <[email protected]>
1 parent 4b4c8f1 commit cbbe2b6

File tree

1 file changed

+26
-1
lines changed

1 file changed

+26
-1
lines changed

src/tooltip/tooltip.component.ts

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@ import {
88
HostListener,
99
Input,
1010
NgZone,
11+
OnChanges,
1112
Renderer2,
13+
SimpleChanges,
1214
TemplateRef,
1315
ViewChild
1416
} from "@angular/core";
@@ -47,7 +49,7 @@ import { PopoverContainer } from "carbon-components-angular/popover";
4749
</span>
4850
`
4951
})
50-
export class Tooltip extends PopoverContainer implements AfterContentChecked {
52+
export class Tooltip extends PopoverContainer implements OnChanges, AfterContentChecked {
5153
static tooltipCount = 0;
5254

5355
@HostBinding("class.cds--tooltip") tooltipClass = true;
@@ -132,6 +134,29 @@ export class Tooltip extends PopoverContainer implements AfterContentChecked {
132134
return value instanceof TemplateRef;
133135
}
134136

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+
135160
/**
136161
* Check for any changes in the projected content & apply accessibility attribute if needed
137162
*/

0 commit comments

Comments
 (0)