Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: prepare tooltip overlay mixin for using by popover #7403

Merged
merged 1 commit into from
May 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions packages/tooltip/src/vaadin-lit-tooltip-overlay.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,12 @@ class TooltipOverlay extends TooltipOverlayMixin(DirMixin(ThemableMixin(PolylitM
</div>
`;
}

requestContentUpdate() {
super.requestContentUpdate();

this.toggleAttribute('hidden', this.textContent.trim() === '');
}
}

defineCustomElement(TooltipOverlay);
17 changes: 12 additions & 5 deletions packages/tooltip/src/vaadin-tooltip-overlay-mixin.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,25 @@ export const TooltipOverlayMixin = (superClass) =>
};
}

/**
* Tag name prefix used by custom properties.
* @protected
* @return {string}
*/
get _tagNamePrefix() {
return 'vaadin-tooltip';
}

requestContentUpdate() {
super.requestContentUpdate();

this.toggleAttribute('hidden', this.textContent.trim() === '');

// Copy custom properties from the tooltip
if (this.positionTarget && this.owner) {
const style = getComputedStyle(this.owner);
['top', 'bottom', 'start', 'end'].forEach((prop) => {
this.style.setProperty(
`--vaadin-tooltip-offset-${prop}`,
style.getPropertyValue(`--vaadin-tooltip-offset-${prop}`),
`--${this._tagNamePrefix}-offset-${prop}`,
style.getPropertyValue(`--${this._tagNamePrefix}-offset-${prop}`),
);
});
}
Expand All @@ -48,7 +55,7 @@ export const TooltipOverlayMixin = (superClass) =>
_updatePosition() {
super._updatePosition();

if (!this.positionTarget) {
if (!this.positionTarget || !this.opened) {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added this check to align with the corresponding logic in PositionMixin.

return;
}

Expand Down
6 changes: 6 additions & 0 deletions packages/tooltip/src/vaadin-tooltip-overlay.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,12 @@ class TooltipOverlay extends TooltipOverlayMixin(DirMixin(ThemableMixin(PolymerE
this.owner = this.__dataHost;
this.owner._overlayElement = this;
}

requestContentUpdate() {
super.requestContentUpdate();

this.toggleAttribute('hidden', this.textContent.trim() === '');
}
}

defineCustomElement(TooltipOverlay);
Loading