Skip to content

Commit d9b2d85

Browse files
crisbetotinayuangao
authored andcommitted
fix(select): transparent background when overscrolling (#2117)
* fix(select): transparent background when overscrolling Fixes the select being transparent on browsers that allow overscrolling (mostly mobile). * Add the panel background after the animations are done. * Reduce expression verbosity * Reset the color on close. * Add a unit test to verify that the class is added to the panel.
1 parent 3ed76f5 commit d9b2d85

File tree

4 files changed

+24
-4
lines changed

4 files changed

+24
-4
lines changed

src/lib/select/_select-theme.scss

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
}
3535
}
3636

37-
.md-select-content {
37+
.md-select-content, .md-select-panel-done-animating {
3838
background: md-color($background, card);
3939
}
4040

src/lib/select/select.html

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,12 @@
55
<span class="md-select-arrow"></span>
66
</div>
77

8-
<template cdk-connected-overlay [origin]="origin" [open]="panelOpen" hasBackdrop (backdropClick)="close()"
8+
<template cdk-connected-overlay [origin]="origin" [open]="panelOpen" hasBackdrop (backdropClick)="close()"
99
backdropClass="cdk-overlay-transparent-backdrop" [positions]="_positions" [minWidth]="_triggerWidth"
1010
[offsetY]="_offsetY" [offsetX]="_offsetX" (attach)="_setScrollTop()">
1111
<div class="md-select-panel" [@transformPanel]="'showing'" (@transformPanel.done)="_onPanelDone()"
12-
(keydown)="_keyManager.onKeydown($event)" [style.transformOrigin]="_transformOrigin">
12+
(keydown)="_keyManager.onKeydown($event)" [style.transformOrigin]="_transformOrigin"
13+
[class.md-select-panel-done-animating]="_panelDoneAnimating">
1314
<div class="md-select-content" [@fadeInContent]="'showing'">
1415
<ng-content></ng-content>
1516
</div>

src/lib/select/select.spec.ts

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import {TestBed, async, ComponentFixture} from '@angular/core/testing';
1+
import {TestBed, async, ComponentFixture, fakeAsync, tick} from '@angular/core/testing';
22
import {By} from '@angular/platform-browser';
33
import {Component, DebugElement, QueryList, ViewChild, ViewChildren} from '@angular/core';
44
import {MdSelectModule} from './index';
@@ -539,6 +539,20 @@ describe('MdSelect', () => {
539539
expect(fixture.componentInstance.select._placeholderState).toEqual('floating-rtl');
540540
});
541541

542+
543+
it('should add a class to the panel when the menu is done animating', fakeAsync(() => {
544+
trigger.click();
545+
fixture.detectChanges();
546+
547+
const panel = overlayContainerElement.querySelector('.md-select-panel');
548+
549+
expect(panel.classList).not.toContain('md-select-panel-done-animating');
550+
551+
tick(250);
552+
fixture.detectChanges();
553+
554+
expect(panel.classList).toContain('md-select-panel-done-animating');
555+
}));
542556
});
543557

544558
describe('positioning', () => {

src/lib/select/select.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,9 @@ export class MdSelect implements AfterContentInit, ControlValueAccessor, OnDestr
147147
/** The value of the select panel's transform-origin property. */
148148
_transformOrigin: string = 'top';
149149

150+
/** Whether the panel's animation is done. */
151+
_panelDoneAnimating: boolean = false;
152+
150153
/**
151154
* The x-offset of the overlay panel in relation to the trigger's top start corner.
152155
* This must be adjusted to align the selected option text over the trigger text when
@@ -353,6 +356,8 @@ export class MdSelect implements AfterContentInit, ControlValueAccessor, OnDestr
353356
} else {
354357
this.onClose.emit();
355358
}
359+
360+
this._panelDoneAnimating = this.panelOpen;
356361
}
357362

358363
/**

0 commit comments

Comments
 (0)