Skip to content

Commit

Permalink
Revert "feat(material/tooltip): add option to open tooltip at mouse p…
Browse files Browse the repository at this point in the history
…osition (angular#25202)" (angular#25430)

This reverts commit 1337f36.
  • Loading branch information
mmalerba committed Aug 10, 2022
1 parent 20db76d commit 08fba43
Show file tree
Hide file tree
Showing 10 changed files with 27 additions and 269 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ export class FlexibleConnectedPositionStrategy implements PositionStrategy {
_preferredPositions: ConnectionPositionPair[] = [];

/** The origin element against which the overlay will be positioned. */
_origin: FlexibleConnectedPositionStrategyOrigin;
private _origin: FlexibleConnectedPositionStrategyOrigin;

/** The overlay pane element. */
private _pane: HTMLElement;
Expand Down
3 changes: 0 additions & 3 deletions src/components-examples/material/tooltip/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import {TooltipMessageExample} from './tooltip-message/tooltip-message-example';
import {TooltipModifiedDefaultsExample} from './tooltip-modified-defaults/tooltip-modified-defaults-example';
import {TooltipOverviewExample} from './tooltip-overview/tooltip-overview-example';
import {TooltipPositionExample} from './tooltip-position/tooltip-position-example';
import {TooltipPositionAtOriginExample} from './tooltip-position-at-origin/tooltip-position-at-origin-example';
import {TooltipHarnessExample} from './tooltip-harness/tooltip-harness-example';

export {
Expand All @@ -30,7 +29,6 @@ export {
TooltipModifiedDefaultsExample,
TooltipOverviewExample,
TooltipPositionExample,
TooltipPositionAtOriginExample,
};

const EXAMPLES = [
Expand All @@ -44,7 +42,6 @@ const EXAMPLES = [
TooltipModifiedDefaultsExample,
TooltipOverviewExample,
TooltipPositionExample,
TooltipPositionAtOriginExample,
];

@NgModule({
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

3 changes: 0 additions & 3 deletions src/dev-app/tooltip/tooltip-demo.html
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,3 @@ <h3>Tooltip overview</h3>

<h3>Tooltip positioning</h3>
<tooltip-position-example></tooltip-position-example>

<h3>Tooltip with position at origin</h3>
<tooltip-position-at-origin-example></tooltip-position-at-origin-example>
98 changes: 7 additions & 91 deletions src/material/legacy-tooltip/tooltip.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import {
dispatchFakeEvent,
dispatchKeyboardEvent,
dispatchMouseEvent,
dispatchTouchEvent,
patchElementFocus,
} from '../../cdk/testing/private';
import {
Expand Down Expand Up @@ -233,63 +232,6 @@ describe('MatTooltip', () => {
expect(tooltipDirective._getOverlayPosition().fallback.overlayX).toBe('end');
}));

it('should position center-bottom by default', fakeAsync(() => {
TestBed.resetTestingModule()
.configureTestingModule({
imports: [MatLegacyTooltipModule, OverlayModule],
declarations: [WideTooltipDemo]
})
.compileComponents();

const wideFixture = TestBed.createComponent(WideTooltipDemo);
wideFixture.detectChanges();
tooltipDirective = wideFixture.debugElement
.query(By.css('button'))!
.injector.get<MatLegacyTooltip>(MatLegacyTooltip);
const button: HTMLButtonElement = wideFixture.nativeElement.querySelector('button');
const triggerRect = button.getBoundingClientRect();

dispatchMouseEvent(button, 'mouseenter', triggerRect.right - 100, triggerRect.top + 100);
wideFixture.detectChanges();
tick();
expect(tooltipDirective._isTooltipVisible()).toBe(true);

expect(tooltipDirective._overlayRef!.overlayElement.offsetLeft).toBeGreaterThan(triggerRect.left + 200);
expect(tooltipDirective._overlayRef!.overlayElement.offsetLeft).toBeLessThan(triggerRect.left + 300);
expect(tooltipDirective._overlayRef!.overlayElement.offsetTop).toBe(triggerRect.bottom);
}));

it('should be able to override the default positionAtOrigin', fakeAsync(() => {
TestBed.resetTestingModule()
.configureTestingModule({
imports: [MatLegacyTooltipModule, OverlayModule],
declarations: [WideTooltipDemo],
providers: [
{
provide: MAT_TOOLTIP_DEFAULT_OPTIONS,
useValue: {positionAtOrigin: true},
},
],
})
.compileComponents();

const wideFixture = TestBed.createComponent(WideTooltipDemo);
wideFixture.detectChanges();
tooltipDirective = wideFixture.debugElement
.query(By.css('button'))!
.injector.get<MatLegacyTooltip>(MatLegacyTooltip);
const button: HTMLButtonElement = wideFixture.nativeElement.querySelector('button');
const triggerRect = button.getBoundingClientRect();

dispatchMouseEvent(button, 'mouseenter', triggerRect.left + 50, triggerRect.bottom - 10);
wideFixture.detectChanges();
tick();
expect(tooltipDirective._isTooltipVisible()).toBe(true);

expect(tooltipDirective._overlayRef!.overlayElement.offsetLeft).toBe(triggerRect.left + 28);
expect(tooltipDirective._overlayRef!.overlayElement.offsetTop).toBe(triggerRect.bottom - 10);
}));

it('should be able to disable tooltip interactivity', fakeAsync(() => {
TestBed.resetTestingModule()
.configureTestingModule({
Expand Down Expand Up @@ -1227,10 +1169,7 @@ describe('MatTooltip', () => {
fixture.detectChanges();
const button: HTMLButtonElement = fixture.nativeElement.querySelector('button');

const triggerRect = button.getBoundingClientRect();
const offsetX = triggerRect.right - 10;
const offsetY = triggerRect.top + 10;
dispatchTouchEvent(button, 'touchstart', offsetX, offsetY, offsetX, offsetY);
dispatchFakeEvent(button, 'touchstart');
fixture.detectChanges();
tick(250); // Halfway through the delay.

Expand All @@ -1249,10 +1188,7 @@ describe('MatTooltip', () => {
fixture.detectChanges();
const button: HTMLButtonElement = fixture.nativeElement.querySelector('button');

const triggerRect = button.getBoundingClientRect();
const offsetX = triggerRect.right - 10;
const offsetY = triggerRect.top + 10;
dispatchTouchEvent(button, 'touchstart', offsetX, offsetY, offsetX, offsetY);
dispatchFakeEvent(button, 'touchstart');
fixture.detectChanges();
tick(500); // Finish the delay.
fixture.detectChanges();
Expand All @@ -1265,10 +1201,7 @@ describe('MatTooltip', () => {
const fixture = TestBed.createComponent(BasicTooltipDemo);
fixture.detectChanges();
const button: HTMLButtonElement = fixture.nativeElement.querySelector('button');
const triggerRect = button.getBoundingClientRect();
const offsetX = triggerRect.right - 10;
const offsetY = triggerRect.top + 10;
const event = dispatchTouchEvent(button, 'touchstart', offsetX, offsetY, offsetX, offsetY);
const event = dispatchFakeEvent(button, 'touchstart');
fixture.detectChanges();

expect(event.defaultPrevented).toBe(false);
Expand All @@ -1279,10 +1212,7 @@ describe('MatTooltip', () => {
fixture.detectChanges();
const button: HTMLButtonElement = fixture.nativeElement.querySelector('button');

const triggerRect = button.getBoundingClientRect();
const offsetX = triggerRect.right - 10;
const offsetY = triggerRect.top + 10;
dispatchTouchEvent(button, 'touchstart', offsetX, offsetY, offsetX, offsetY);
dispatchFakeEvent(button, 'touchstart');
fixture.detectChanges();
tick(500); // Finish the open delay.
fixture.detectChanges();
Expand All @@ -1306,10 +1236,7 @@ describe('MatTooltip', () => {
fixture.detectChanges();
const button: HTMLButtonElement = fixture.nativeElement.querySelector('button');

const triggerRect = button.getBoundingClientRect();
const offsetX = triggerRect.right - 10;
const offsetY = triggerRect.top + 10;
dispatchTouchEvent(button, 'touchstart', offsetX, offsetY, offsetX, offsetY);
dispatchFakeEvent(button, 'touchstart');
fixture.detectChanges();
tick(500); // Finish the open delay.
fixture.detectChanges();
Expand Down Expand Up @@ -1474,16 +1401,16 @@ describe('MatTooltip', () => {
const fixture = TestBed.createComponent(BasicTooltipDemo);
fixture.detectChanges();
const button: HTMLButtonElement = fixture.nativeElement.querySelector('button');
const triggerRect = button.getBoundingClientRect();

dispatchMouseEvent(button, 'mouseenter', triggerRect.right - 10, triggerRect.top + 10);
dispatchFakeEvent(button, 'mouseenter');
fixture.detectChanges();
tick(500); // Finish the open delay.
fixture.detectChanges();
finishCurrentTooltipAnimation(overlayContainerElement, true);
assertTooltipInstance(fixture.componentInstance.tooltip, true);

// Simulate the pointer over the trigger.
const triggerRect = button.getBoundingClientRect();
const wheelEvent = createFakeEvent('wheel');
Object.defineProperties(wheelEvent, {
clientX: {get: () => triggerRect.left + 1},
Expand Down Expand Up @@ -1629,17 +1556,6 @@ class TooltipDemoWithoutPositionBinding {
@ViewChild('button') button: ElementRef<HTMLButtonElement>;
}

@Component({
selector: 'app',
styles: [`button { width: 500px; height: 500px; }`],
template: `<button #button [matTooltip]="message">Button</button>`,
})
class WideTooltipDemo {
message = 'Test';
@ViewChild(MatLegacyTooltip) tooltip: MatLegacyTooltip;
@ViewChild('button') button: ElementRef<HTMLButtonElement>;
}

/** Asserts whether a tooltip directive has a tooltip instance. */
function assertTooltipInstance(tooltip: MatLegacyTooltip, shouldExist: boolean): void {
// Note that we have to cast this to a boolean, because Jasmine will go into an infinite loop
Expand Down
6 changes: 0 additions & 6 deletions src/material/tooltip/tooltip.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,6 @@ CSS class that can be used for style (e.g. to add an arrow). The possible classe

<!-- example(tooltip-position) -->

To display the tooltip relative to the mouse or touch that triggered it, use the
`matTooltipPositionAtOrigin` input.
With this setting turned on, the tooltip will display relative to the origin of the trigger rather
than the host element. In cases where the tooltip is not triggered by a touch event or mouse click,
it will display the same as if this setting was turned off.

### Showing and hiding

By default, the tooltip will be immediately shown when the user's mouse hovers over the tooltip's
Expand Down

0 comments on commit 08fba43

Please sign in to comment.