Skip to content

Commit aada252

Browse files
committed
remove usage of scrollables until throttling is set up
1 parent 6a740a3 commit aada252

File tree

6 files changed

+17
-103
lines changed

6 files changed

+17
-103
lines changed

src/demo-app/tooltip/tooltip-demo.html

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
<div class="demo-tooltip">
22
<h1>Tooltip Demo</h1>
33

4-
<p class="centered" style="height: 200px; overflow: auto;" cdk-scrollable>
5-
<button #tooltip="mdTooltip" style="margin-bottom: 300px;"
4+
<p class="centered">
5+
<button #tooltip="mdTooltip"
66
md-raised-button
77
color="primary"
88
[mdTooltip]="message"
@@ -11,7 +11,6 @@ <h1>Tooltip Demo</h1>
1111
[mdTooltipHideDelay]="hideDelay">
1212
Mouse over to see the tooltip
1313
</button>
14-
Scroll down while tooltip is open to see it hide automatically
1514
</p>
1615

1716
<p>

src/lib/core/overlay/position/connected-position-strategy.spec.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -432,6 +432,7 @@ describe('ConnectedPositionStrategy', () => {
432432

433433
describe('onPositionChange with scrollable view properties', () => {
434434
let overlayElement: HTMLElement;
435+
let overlayContainerElement: HTMLElement;
435436
let strategy: ConnectedPositionStrategy;
436437

437438
let scrollable: HTMLDivElement;
@@ -441,7 +442,7 @@ describe('ConnectedPositionStrategy', () => {
441442

442443
beforeEach(() => {
443444
// Set up the overlay
444-
let overlayContainerElement = createFixedElement();
445+
overlayContainerElement = createFixedElement();
445446
overlayElement = createPositionedBlockElement();
446447
document.body.appendChild(overlayContainerElement);
447448
overlayContainerElement.appendChild(overlayElement);
@@ -471,6 +472,7 @@ describe('ConnectedPositionStrategy', () => {
471472
afterEach(() => {
472473
onPositionChangeSubscription.unsubscribe();
473474
document.body.removeChild(scrollable);
475+
document.body.removeChild(overlayContainerElement);
474476
});
475477

476478
it('should not have origin or overlay clipped or out of view without scroll', () => {

src/lib/sidenav/sidenav-container.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@
33

44
<ng-content select="md-sidenav, mat-sidenav"></ng-content>
55

6-
<div class="md-sidenav-content" [ngStyle]="_getStyles()" cdk-scrollable>
6+
<div class="md-sidenav-content" [ngStyle]="_getStyles()">
77
<ng-content></ng-content>
88
</div>

src/lib/sidenav/sidenav.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ import {FocusTrap} from '../core/a11y/focus-trap';
2222
import {ESCAPE} from '../core/keyboard/keycodes';
2323
import {OverlayModule} from '../core/overlay/overlay-directives';
2424
import {InteractivityChecker} from '../core/a11y/interactivity-checker';
25-
import {ScrollDispatcher} from '../core/overlay/scroll/scroll-dispatcher';
2625

2726

2827
/** Exception thrown when two MdSidenav are matching the same side. */
@@ -516,7 +515,7 @@ export class MdSidenavModule {
516515
static forRoot(): ModuleWithProviders {
517516
return {
518517
ngModule: MdSidenavModule,
519-
providers: [InteractivityChecker, ScrollDispatcher]
518+
providers: [InteractivityChecker]
520519
};
521520
}
522521
}

src/lib/tooltip/tooltip.spec.ts

Lines changed: 8 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,17 @@
11
import {
2-
async,
3-
ComponentFixture,
4-
TestBed,
5-
tick,
6-
fakeAsync,
7-
flushMicrotasks
2+
async,
3+
ComponentFixture,
4+
TestBed,
5+
tick,
6+
fakeAsync,
7+
flushMicrotasks
88
} from '@angular/core/testing';
9-
import {Component, DebugElement, AnimationTransitionEvent, ViewChild} from '@angular/core';
9+
import {Component, DebugElement, AnimationTransitionEvent} from '@angular/core';
1010
import {By} from '@angular/platform-browser';
1111
import {TooltipPosition, MdTooltip, MdTooltipModule} from './tooltip';
1212
import {OverlayContainer} from '../core';
1313
import {Dir, LayoutDirection} from '../core/rtl/dir';
1414
import {OverlayModule} from '../core/overlay/overlay-directives';
15-
import {Scrollable} from '../core/overlay/scroll/scrollable';
1615

1716
const initialTooltipMessage = 'initial tooltip message';
1817

@@ -23,7 +22,7 @@ describe('MdTooltip', () => {
2322
beforeEach(async(() => {
2423
TestBed.configureTestingModule({
2524
imports: [MdTooltipModule.forRoot(), OverlayModule],
26-
declarations: [BasicTooltipDemo, ScrollableTooltipDemo],
25+
declarations: [BasicTooltipDemo],
2726
providers: [
2827
{provide: OverlayContainer, useFactory: () => {
2928
overlayContainerElement = document.createElement('div');
@@ -298,34 +297,6 @@ describe('MdTooltip', () => {
298297
}).toThrowError('Tooltip position "everywhere" is invalid.');
299298
});
300299
});
301-
302-
303-
describe('scrollable usage', () => {
304-
let fixture: ComponentFixture<ScrollableTooltipDemo>;
305-
let buttonDebugElement: DebugElement;
306-
let buttonElement: HTMLButtonElement;
307-
let tooltipDirective: MdTooltip;
308-
309-
beforeEach(() => {
310-
fixture = TestBed.createComponent(ScrollableTooltipDemo);
311-
fixture.detectChanges();
312-
buttonDebugElement = fixture.debugElement.query(By.css('button'));
313-
buttonElement = <HTMLButtonElement> buttonDebugElement.nativeElement;
314-
tooltipDirective = buttonDebugElement.injector.get(MdTooltip);
315-
});
316-
317-
it('should hide tooltip if clipped after changing positions', fakeAsync(() => {
318-
expect(tooltipDirective._tooltipInstance).toBeUndefined();
319-
320-
tooltipDirective.show();
321-
tick(0); // Tick for the show delay (default is 0)
322-
expect(tooltipDirective._isTooltipVisible()).toBe(true);
323-
324-
fixture.componentInstance.scrollDown();
325-
tick();
326-
expect(tooltipDirective._isTooltipVisible()).toBe(false);
327-
}));
328-
});
329300
});
330301

331302
@Component({
@@ -343,33 +314,3 @@ class BasicTooltipDemo {
343314
showButton: boolean = true;
344315
}
345316

346-
@Component({
347-
selector: 'app',
348-
template: `
349-
<div cdk-scrollable style="margin-top: 300px; height: 200px; width: 200px; overflow: auto;">
350-
<button *ngIf="showButton" style="margin-bottom: 350px"
351-
[md-tooltip]="message"
352-
[tooltip-position]="position">
353-
Button
354-
</button>
355-
</div>`
356-
})
357-
class ScrollableTooltipDemo {
358-
position: string = 'below';
359-
message: string = initialTooltipMessage;
360-
showButton: boolean = true;
361-
362-
@ViewChild(Scrollable) scrollingContainer: Scrollable;
363-
364-
scrollDown() {
365-
const scrollingContainerEl = this.scrollingContainer.getElementRef().nativeElement;
366-
scrollingContainerEl.scrollTop = 50;
367-
368-
// Emit a scroll event from the scrolling element in our component.
369-
// This event should be picked up by the scrollable directive and notify.
370-
// The notification should be picked up by the service.
371-
const scrollEvent = document.createEvent('UIEvents');
372-
scrollEvent.initUIEvent('scroll', true, true, window, 0);
373-
scrollingContainerEl.dispatchEvent(scrollEvent);
374-
}
375-
}

src/lib/tooltip/tooltip.ts

Lines changed: 2 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,7 @@ import {MdTooltipInvalidPositionError} from './tooltip-errors';
3131
import {Observable} from 'rxjs/Observable';
3232
import {Subject} from 'rxjs/Subject';
3333
import {Dir} from '../core/rtl/dir';
34-
import {ScrollDispatcher} from '../core/overlay/scroll/scroll-dispatcher';
3534
import {OVERLAY_PROVIDERS} from '../core/overlay/overlay';
36-
import {ConnectedOverlayPositionChange} from '../core/overlay/position/connected-position';
3735
import 'rxjs/add/operator/first';
3836

3937
export type TooltipPosition = 'left' | 'right' | 'above' | 'below' | 'before' | 'after';
@@ -57,7 +55,7 @@ export const TOUCHEND_HIDE_DELAY = 1500;
5755
},
5856
exportAs: 'mdTooltip',
5957
})
60-
export class MdTooltip implements OnInit, OnDestroy {
58+
export class MdTooltip implements OnDestroy {
6159
_overlayRef: OverlayRef;
6260
_tooltipInstance: TooltipComponent;
6361

@@ -106,22 +104,11 @@ export class MdTooltip implements OnInit, OnDestroy {
106104
set _deprecatedMessage(v: string) { this.message = v; }
107105

108106
constructor(private _overlay: Overlay,
109-
private _scrollDispatcher: ScrollDispatcher,
110107
private _elementRef: ElementRef,
111108
private _viewContainerRef: ViewContainerRef,
112109
private _ngZone: NgZone,
113110
@Optional() private _dir: Dir) { }
114111

115-
ngOnInit() {
116-
// When a scroll on the page occurs, update the position in case this tooltip needs
117-
// to be repositioned.
118-
this._scrollDispatcher.scrolled().subscribe(() => {
119-
if (this._overlayRef) {
120-
this._overlayRef.updatePosition();
121-
}
122-
});
123-
}
124-
125112
/**
126113
* Dispose the tooltip when destroyed.
127114
*/
@@ -179,18 +166,7 @@ export class MdTooltip implements OnInit, OnDestroy {
179166
private _createOverlay(): void {
180167
let origin = this._getOrigin();
181168
let position = this._getOverlayPosition();
182-
183-
// Create connected position strategy that listens for scroll events to reposition.
184-
// After position changes occur and the overlay is clipped by a parent scrollable then
185-
// close the tooltip.
186169
let strategy = this._overlay.position().connectedTo(this._elementRef, origin, position);
187-
strategy.withScrollableContainers(this._scrollDispatcher.getScrollContainers(this._elementRef));
188-
strategy.onPositionChange.subscribe(change => {
189-
if (change.scrollableViewProperties.isOverlayClipped) {
190-
this.hide(0);
191-
}
192-
});
193-
194170
let config = new OverlayState();
195171
config.positionStrategy = strategy;
196172

@@ -412,10 +388,7 @@ export class MdTooltipModule {
412388
static forRoot(): ModuleWithProviders {
413389
return {
414390
ngModule: MdTooltipModule,
415-
providers: [
416-
OVERLAY_PROVIDERS,
417-
ScrollDispatcher
418-
]
391+
providers: [OVERLAY_PROVIDERS]
419392
};
420393
}
421394
}

0 commit comments

Comments
 (0)