mirror of
https://github.com/angular/angular.git
synced 2026-09-14 13:54:52 +08:00
feat(tooltip): allow for position to be updated while open (#10362)
Allows for the position of a tooltip to be updated while it's still open. Previously we closed the tooltip, because it wasn't possible for the overlay position to be updated.
This commit is contained in:
committed by
Joey Perrott
parent
dda1d04750
commit
04045d2fad
@@ -5,7 +5,7 @@
|
||||
overflow: auto;
|
||||
|
||||
button {
|
||||
margin: 16px;
|
||||
margin: 75px 16px 16px;
|
||||
}
|
||||
}
|
||||
.mat-radio-button {
|
||||
|
||||
@@ -28,7 +28,6 @@ import {
|
||||
MatTooltipModule,
|
||||
SCROLL_THROTTLE_MS,
|
||||
TOOLTIP_PANEL_CLASS,
|
||||
TooltipPosition,
|
||||
MAT_TOOLTIP_DEFAULT_OPTIONS,
|
||||
} from './index';
|
||||
|
||||
@@ -306,24 +305,21 @@ describe('MatTooltip', () => {
|
||||
expect(tooltipDirective._isTooltipVisible()).toBe(true);
|
||||
}));
|
||||
|
||||
it('should remove the tooltip when changing position', () => {
|
||||
const initialPosition: TooltipPosition = 'below';
|
||||
const changedPosition: TooltipPosition = 'above';
|
||||
|
||||
assertTooltipInstance(tooltipDirective, false);
|
||||
|
||||
tooltipDirective.position = initialPosition;
|
||||
it('should be able to update the tooltip position while open', fakeAsync(() => {
|
||||
tooltipDirective.position = 'below';
|
||||
tooltipDirective.show();
|
||||
expect(tooltipDirective._tooltipInstance).toBeTruthy();
|
||||
tick();
|
||||
|
||||
// Same position value should not remove the tooltip
|
||||
tooltipDirective.position = initialPosition;
|
||||
expect(tooltipDirective._tooltipInstance).toBeTruthy();
|
||||
assertTooltipInstance(tooltipDirective, true);
|
||||
|
||||
// Different position value should destroy the tooltip
|
||||
tooltipDirective.position = changedPosition;
|
||||
assertTooltipInstance(tooltipDirective, false);
|
||||
});
|
||||
tooltipDirective.position = 'above';
|
||||
spyOn(tooltipDirective._overlayRef!, 'updatePosition').and.callThrough();
|
||||
fixture.detectChanges();
|
||||
tick();
|
||||
|
||||
assertTooltipInstance(tooltipDirective, true);
|
||||
expect(tooltipDirective._overlayRef!.updatePosition).toHaveBeenCalled();
|
||||
}));
|
||||
|
||||
it('should be able to modify the tooltip message', fakeAsync(() => {
|
||||
assertTooltipInstance(tooltipDirective, false);
|
||||
|
||||
@@ -119,10 +119,9 @@ export class MatTooltip implements OnDestroy {
|
||||
this._position = value;
|
||||
|
||||
if (this._overlayRef) {
|
||||
// TODO(andrewjs): When the overlay's position can be
|
||||
// dynamically changed, do not destroy the tooltip.
|
||||
this._detach();
|
||||
this._updatePosition();
|
||||
this._tooltipInstance!.show(value, 0);
|
||||
this._overlayRef.updatePosition();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user