Skip to content

Commit 638a34a

Browse files
crisbetoandrewseguin
authored andcommitted
fix(select): panel in multiple mode not overlapping trigger (#4952)
* Fixes the select panel in multiple mode not overlapping the trigger completely. * Reformats the select.html to make it a little more manageable. Fixes #4943.
1 parent 3779395 commit 638a34a

File tree

3 files changed

+43
-20
lines changed

3 files changed

+43
-20
lines changed

src/lib/select/select-animations.ts

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -23,38 +23,43 @@ export const transformPlaceholder: AnimationTriggerMetadata = trigger('transform
2323
state('floating-ltr', style({
2424
top: '-22px',
2525
left: '-2px',
26-
transform: `scale(0.75)`
26+
transform: 'scale(0.75)'
2727
})),
2828
state('floating-rtl', style({
2929
top: '-22px',
3030
left: '2px',
31-
transform: `scale(0.75)`
31+
transform: 'scale(0.75)'
3232
})),
33-
transition('* => *', animate(`400ms cubic-bezier(0.25, 0.8, 0.25, 1)`))
33+
transition('* => *', animate('400ms cubic-bezier(0.25, 0.8, 0.25, 1)'))
3434
]);
3535

3636
/**
3737
* This animation transforms the select's overlay panel on and off the page.
3838
*
39-
* When the panel is attached to the DOM, it expands its width 32px, scales it up to
40-
* 100% on the Y axis, fades in its border, and translates slightly up and to the
39+
* When the panel is attached to the DOM, it expands its width by the amount of padding, scales it
40+
* up to 100% on the Y axis, fades in its border, and translates slightly up and to the
4141
* side to ensure the option text correctly overlaps the trigger text.
4242
*
4343
* When the panel is removed from the DOM, it simply fades out linearly.
4444
*/
4545
export const transformPanel: AnimationTriggerMetadata = trigger('transformPanel', [
4646
state('showing', style({
4747
opacity: 1,
48-
minWidth: 'calc(100% + 32px)',
49-
transform: `scaleY(1)`
48+
minWidth: 'calc(100% + 32px)', // 32px = 2 * 16px padding
49+
transform: 'scaleY(1)'
50+
})),
51+
state('showing-multiple', style({
52+
opacity: 1,
53+
minWidth: 'calc(100% + 64px)', // 64px = 48px padding on the left + 16px padding on the right
54+
transform: 'scaleY(1)'
5055
})),
5156
transition('void => *', [
5257
style({
5358
opacity: 0,
5459
minWidth: '100%',
55-
transform: `scaleY(0)`
60+
transform: 'scaleY(0)'
5661
}),
57-
animate(`150ms cubic-bezier(0.25, 0.8, 0.25, 1)`)
62+
animate('150ms cubic-bezier(0.25, 0.8, 0.25, 1)')
5863
]),
5964
transition('* => void', [
6065
animate('250ms 100ms linear', style({opacity: 0}))
@@ -66,10 +71,10 @@ export const transformPanel: AnimationTriggerMetadata = trigger('transformPanel'
6671
* select's options. It is time delayed to occur 100ms after the overlay
6772
* panel has transformed in.
6873
*/
69-
export const fadeInContent: AnimationTriggerMetadata = trigger('fadeInContent', [
74+
export const fadeInContent: AnimationTriggerMetadata = trigger('fadeInContent', [
7075
state('showing', style({opacity: 1})),
7176
transition('void => showing', [
7277
style({opacity: 0}),
73-
animate(`150ms 100ms cubic-bezier(0.55, 0, 0.55, 0.2)`)
78+
animate('150ms 100ms cubic-bezier(0.55, 0, 0.55, 0.2)')
7479
])
7580
]);

src/lib/select/select.html

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,28 @@
1313
<span class="mat-select-underline"></span>
1414
</div>
1515

16-
<ng-template cdk-connected-overlay [origin]="origin" [open]="panelOpen" hasBackdrop (backdropClick)="close()"
17-
backdropClass="cdk-overlay-transparent-backdrop" [positions]="_positions" [minWidth]="_triggerWidth"
18-
[offsetY]="_offsetY" (attach)="_onAttached()" (detach)="close()">
19-
<div class="mat-select-panel {{ 'mat-' + color }}" [ngClass]="panelClass" [@transformPanel]="'showing'"
20-
(@transformPanel.done)="_onPanelDone()" (keydown)="_handlePanelKeydown($event)"
21-
[style.transformOrigin]="_transformOrigin" [class.mat-select-panel-done-animating]="_panelDoneAnimating">
16+
<ng-template
17+
cdk-connected-overlay
18+
hasBackdrop
19+
backdropClass="cdk-overlay-transparent-backdrop"
20+
[origin]="origin"
21+
[open]="panelOpen"
22+
[positions]="_positions"
23+
[minWidth]="_triggerWidth"
24+
[offsetY]="_offsetY"
25+
(backdropClick)="close()"
26+
(attach)="_onAttached()"
27+
(detach)="close()">
28+
29+
<div
30+
class="mat-select-panel {{ 'mat-' + color }}"
31+
[ngClass]="panelClass"
32+
[@transformPanel]="multiple ? 'showing-multiple' : 'showing'"
33+
(@transformPanel.done)="_onPanelDone()"
34+
(keydown)="_handlePanelKeydown($event)"
35+
[style.transformOrigin]="_transformOrigin"
36+
[class.mat-select-panel-done-animating]="_panelDoneAnimating">
37+
2238
<div class="mat-select-content" [@fadeInContent]="'showing'" (@fadeInContent.done)="_onFadeInDone()">
2339
<ng-content></ng-content>
2440
</div>

src/lib/select/select.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -840,16 +840,18 @@ export class MdSelect extends _MdSelectMixinBase implements AfterContentInit, On
840840
const overlayRect = this.overlayDir.overlayRef.overlayElement.getBoundingClientRect();
841841
const viewportRect = this._viewportRuler.getViewportRect();
842842
const isRtl = this._isRtl();
843+
const paddingWidth = this.multiple ? SELECT_MULTIPLE_PANEL_PADDING_X + SELECT_PANEL_PADDING_X :
844+
SELECT_PANEL_PADDING_X * 2;
845+
843846
let offsetX = this.multiple ? SELECT_MULTIPLE_PANEL_PADDING_X : SELECT_PANEL_PADDING_X;
844847

845848
if (!isRtl) {
846849
offsetX *= -1;
847850
}
848851

849-
const leftOverflow = 0 - (overlayRect.left + offsetX
850-
- (isRtl ? SELECT_PANEL_PADDING_X * 2 : 0));
852+
const leftOverflow = 0 - (overlayRect.left + offsetX - (isRtl ? paddingWidth : 0));
851853
const rightOverflow = overlayRect.right + offsetX - viewportRect.width
852-
+ (isRtl ? 0 : SELECT_PANEL_PADDING_X * 2);
854+
+ (isRtl ? 0 : paddingWidth);
853855

854856
if (leftOverflow > 0) {
855857
offsetX += leftOverflow + SELECT_PANEL_VIEWPORT_PADDING;

0 commit comments

Comments
 (0)