Skip to content

Commit 7d3201e

Browse files
Zneekysimeonoff
andauthored
Fix max-width handling for tooltips with nested content - master (#16423)
* fix(tooltip): update max-width handling for tooltips with nested content * fix(tooltip): correct selector syntax for tooltip max-width handling * refactor(tooltip): improve slotted content detection for styling purposes * spec(tooltip): revert from inital to none as its the computed style --------- Co-authored-by: Simeon Simeonoff <sim.simeonoff@gmail.com>
1 parent 0d418b7 commit 7d3201e

File tree

4 files changed

+59
-4
lines changed

4 files changed

+59
-4
lines changed

projects/igniteui-angular/src/lib/core/styles/components/tooltip/_tooltip-theme.scss

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
gap: rem(8px);
2424
min-height: rem(24px);
2525
min-width: rem(24px);
26-
max-width: 200px;
26+
max-width: rem(200px);
2727
width: fit-content;
2828

2929
igx-icon {
@@ -34,6 +34,10 @@
3434
display: flex;
3535
cursor: default;
3636
}
37+
38+
&:not([data-default]) {
39+
max-width: initial;
40+
}
3741
}
3842

3943
%arrow--top {
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
<span igxTooltip>{{content}}</span>
1+
<span data-default igxTooltip>{{content}}</span>

projects/igniteui-angular/src/lib/directives/tooltip/tooltip.directive.spec.ts

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { DebugElement } from '@angular/core';
22
import { fakeAsync, TestBed, tick, flush, waitForAsync, ComponentFixture } from '@angular/core/testing';
33
import { By } from '@angular/platform-browser';
44
import { NoopAnimationsModule } from '@angular/platform-browser/animations';
5-
import { IgxTooltipSingleTargetComponent, IgxTooltipMultipleTargetsComponent, IgxTooltipPlainStringComponent, IgxTooltipWithToggleActionComponent, IgxTooltipMultipleTooltipsComponent, IgxTooltipWithCloseButtonComponent } from '../../test-utils/tooltip-components.spec';
5+
import { IgxTooltipSingleTargetComponent, IgxTooltipMultipleTargetsComponent, IgxTooltipPlainStringComponent, IgxTooltipWithToggleActionComponent, IgxTooltipMultipleTooltipsComponent, IgxTooltipWithCloseButtonComponent, IgxTooltipWithNestedContentComponent } from '../../test-utils/tooltip-components.spec';
66
import { UIInteractions } from '../../test-utils/ui-interactions.spec';
77
import { HorizontalAlignment, VerticalAlignment, AutoPositionStrategy } from '../../services/public_api';
88
import { IgxTooltipDirective } from './tooltip.directive';
@@ -28,7 +28,8 @@ describe('IgxTooltip', () => {
2828
IgxTooltipMultipleTargetsComponent,
2929
IgxTooltipPlainStringComponent,
3030
IgxTooltipWithToggleActionComponent,
31-
IgxTooltipWithCloseButtonComponent
31+
IgxTooltipWithCloseButtonComponent,
32+
IgxTooltipWithNestedContentComponent
3233
]
3334
}).compileComponents();
3435
UIInteractions.clearOverlay();
@@ -500,6 +501,36 @@ describe('IgxTooltip', () => {
500501

501502
verifyTooltipVisibility(tooltipNativeElement, tooltipTarget, false);
502503
}));
504+
505+
it('Should respect default max-width constraint for plain string tooltip', fakeAsync(() => {
506+
hoverElement(button);
507+
flush();
508+
509+
verifyTooltipVisibility(tooltipNativeElement, tooltipTarget, true);
510+
511+
const maxWidth = getComputedStyle(tooltipNativeElement).maxWidth;
512+
expect(maxWidth).toBe('200px');
513+
}));
514+
});
515+
516+
describe('Custom content tooltip', () => {
517+
beforeEach(waitForAsync(() => {
518+
fix = TestBed.createComponent(IgxTooltipWithNestedContentComponent);
519+
fix.detectChanges();
520+
button = fix.debugElement.query(By.directive(IgxTooltipTargetDirective));
521+
tooltipTarget = fix.componentInstance.tooltipTarget;
522+
tooltipNativeElement = fix.debugElement.query(By.directive(IgxTooltipDirective)).nativeElement;
523+
}));
524+
525+
it('Should not have max-width constraint for custom content tooltip', fakeAsync(() => {
526+
hoverElement(button);
527+
flush();
528+
529+
verifyTooltipVisibility(tooltipNativeElement, tooltipTarget, true);
530+
531+
const maxWidth = getComputedStyle(tooltipNativeElement).maxWidth;
532+
expect(maxWidth).toBe('none');
533+
}));
503534
});
504535

505536
describe('Multiple targets with single tooltip', () => {

projects/igniteui-angular/src/lib/test-utils/tooltip-components.spec.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,3 +149,23 @@ export class IgxTooltipWithCloseButtonComponent {
149149
@ViewChild(IgxTooltipDirective, { static: true }) public tooltip: IgxTooltipDirective;
150150
@ViewChild(IgxTooltipTargetDirective, { static: true }) public tooltipTarget: IgxTooltipTargetDirective;
151151
}
152+
153+
@Component({
154+
template: `
155+
<button class="btn" [igxTooltipTarget]="tooltipRef">
156+
Hover me
157+
</button>
158+
159+
<div igxTooltip #tooltipRef="tooltip">
160+
<div class="nested" style="background: red; width: 400px; color: white; padding: 4px;">
161+
<span>Nested content</span>
162+
</div>
163+
</div>
164+
`,
165+
imports: [IgxTooltipDirective, IgxTooltipTargetDirective],
166+
standalone: true
167+
})
168+
export class IgxTooltipWithNestedContentComponent {
169+
@ViewChild(IgxTooltipDirective, { static: true }) public tooltip!: IgxTooltipDirective;
170+
@ViewChild(IgxTooltipTargetDirective, { static: true }) public tooltipTarget!: IgxTooltipTargetDirective;
171+
}

0 commit comments

Comments
 (0)