Fix tooltip max-width constraint for custom content#1936
Conversation
Co-authored-by: kdinev <1472513+kdinev@users.noreply.github.com>
Co-authored-by: kdinev <1472513+kdinev@users.noreply.github.com>
|
@copilot There's a failing test |
Move slot content check to updated() lifecycle to ensure slot element is available. The @query() decorated properties are only populated after firstUpdated() completes, so checking in firstUpdated() was too early. Now using updated() with a flag to check on first update and when message property changes. Co-authored-by: kdinev <1472513+kdinev@users.noreply.github.com>
Fixed in commit 530a7a8. The issue was a timing problem - the slot content check was happening too early in the lifecycle before the |
|
There was a problem hiding this comment.
Pull Request Overview
This PR introduces a conditional CSS part (simple-text) to the tooltip component that allows styling differentiation between tooltips using the message property versus those with custom slotted content. The simple-text part is only applied when the tooltip displays text via the message property, and this allows moving the max-width constraint from the base container to only simple text tooltips.
- Added
simple-textCSS part that is conditionally applied based on slot usage - Integrated slot controller to detect whether custom content is slotted
- Moved
max-widthstyling from base part tosimple-textpart for better flexibility with custom content
Reviewed Changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| src/components/tooltip/tooltip.ts | Added slot controller, partMap utility, and conditional simple-text part logic to the render method |
| src/components/tooltip/tooltip.spec.ts | Added tests verifying the simple-text part is applied correctly based on content type |
| src/components/tooltip/themes/tooltip.base.scss | Updated CSS selectors to use part tokens (~=) and moved max-width to simple-text part only |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Fix igc-tooltip max-width for custom content
Problem
When placing custom content inside the tooltip, the component does not automatically unset the max-width: 200px style that is applied by default for simple text tooltips. As a result, tooltips with custom content are incorrectly constrained in width.
Solution Implemented
Recent Fix
Fixed a timing issue where the slot content check was happening too early in the lifecycle. The
@query()decorator only populates properties afterfirstUpdated()completes, so calling_checkForCustomContent()infirstUpdated()meant the_defaultSlotwas not yet available.Moved the check to
updated()lifecycle method with a flag to ensure it runs on the first update (when the slot is available) and whenever themessageproperty changes.Technical Changes
1. TypeScript Component (
tooltip.ts)@state()property_hasCustomContentto track if custom content is slotted@query()for the default slot to detect slotted content_initialCheckDoneflag to track if initial check has been performed_checkForCustomContent()method with defensive null check and early returnclassMapdirective to conditionally applysimple-textclass based on_hasCustomContent@slotchangeevent listener directly bound to_checkForCustomContent()updated()lifecycle to check for custom content after slot is available2. CSS (
tooltip.base.scss)max-width: 200pxfrom[part="base"]to[part="base"].simple-text3. Tests (
tooltip.spec.ts)Backward Compatibility
✅ Fully backward compatible
messageproperty will continue to have the 200px max-width constraintOriginal prompt
💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.