Skip to content

Commit 7213d55

Browse files
Copilotkdinev
andcommitted
Address code review feedback - improve defensive coding
Co-authored-by: kdinev <1472513+kdinev@users.noreply.github.com>
1 parent bd22772 commit 7213d55

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

src/components/tooltip/tooltip.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -438,15 +438,13 @@ export default class IgcTooltipComponent extends EventEmitterMixin<
438438
}
439439

440440
private _checkForCustomContent(): void {
441-
if (this._defaultSlot) {
442-
const assignedNodes = this._defaultSlot.assignedNodes({ flatten: true });
443-
// If there are assigned nodes, we have custom content
444-
this._hasCustomContent = assignedNodes.length > 0;
441+
if (!this._defaultSlot) {
442+
this._hasCustomContent = false;
443+
return;
445444
}
446-
}
447-
448-
private _handleSlotChange(): void {
449-
this._checkForCustomContent();
445+
const assignedNodes = this._defaultSlot.assignedNodes({ flatten: true });
446+
// If there are assigned nodes, we have custom content
447+
this._hasCustomContent = assignedNodes.length > 0;
450448
}
451449

452450
protected override render() {
@@ -468,7 +466,9 @@ export default class IgcTooltipComponent extends EventEmitterMixin<
468466
shift
469467
>
470468
<div ${ref(this._containerRef)} part="base" class=${classMap(classes)}>
471-
<slot @slotchange=${this._handleSlotChange}>${this.message}</slot>
469+
<slot @slotchange=${this._checkForCustomContent}
470+
>${this.message}</slot
471+
>
472472
${this.sticky
473473
? html`
474474
<slot name="close-button" @click=${this._setAutoHide}>

0 commit comments

Comments
 (0)