Skip to content

Commit 3c403b5

Browse files
committed
Account for the checkbox when aligning the option and fix RTL.
1 parent e4fbfe4 commit 3c403b5

File tree

3 files changed

+26
-10
lines changed

3 files changed

+26
-10
lines changed

src/lib/core/option/_option.scss

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,14 @@
3131
}
3232
}
3333

34-
.md-option-content {
35-
vertical-align: middle;
36-
}
34+
.md-option-pseudo-checkbox {
35+
$margin: $md-menu-side-padding / 2;
36+
margin-right: $margin;
3737

38-
// TODO: doesn't handle RTL yet
39-
md-pseudo-checkbox {
40-
margin-right: $md-menu-side-padding / 2;
38+
[dir="rtl"] & {
39+
margin-left: $margin;
40+
margin-right: 0;
41+
}
4142
}
4243
}
4344

src/lib/core/option/option.html

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
<md-pseudo-checkbox *ngIf="multiple" [state]="selected ? 'checked' : ''"
2-
color="primary"></md-pseudo-checkbox>
3-
<span class="md-option-content"><ng-content></ng-content></span>
1+
<md-pseudo-checkbox class="md-option-pseudo-checkbox" *ngIf="multiple"
2+
[state]="selected ? 'checked' : ''" color="primary"></md-pseudo-checkbox>
3+
<ng-content></ng-content>
44
<div class="md-option-ripple" *ngIf="!disabled" md-ripple mdRippleBackgroundColor="rgba(0,0,0,0)"
55
[mdRippleTrigger]="_getHostElement()"></div>

src/lib/select/select.ts

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,17 @@ export const SELECT_OPTION_HEIGHT_ADJUSTMENT = 9;
5757
/** The panel's padding on the x-axis */
5858
export const SELECT_PANEL_PADDING_X = 16;
5959

60+
/**
61+
* Distance between the panel edge and the option text in
62+
* multi-selection mode.
63+
*
64+
* (SELECT_PADDING * 1.75) + 20 = 48
65+
* The padding is multiplied by 1.75, because the checkbox's margin is half the padding, and
66+
* the browser adds ~4px, because we're using inline elements.
67+
* The checkbox width is 20px.
68+
*/
69+
export const SELECT_MULTIPLE_PANEL_PADDING_X = SELECT_PANEL_PADDING_X * 1.75 + 20;
70+
6071
/**
6172
* The panel's padding on the y-axis. This padding indicates there are more
6273
* options available if you scroll.
@@ -611,7 +622,11 @@ export class MdSelect implements AfterContentInit, ControlValueAccessor, OnDestr
611622

612623
/** Calculates the scroll position and x- and y-offsets of the overlay panel. */
613624
private _calculateOverlayPosition(): void {
614-
this._offsetX = this._isRtl() ? SELECT_PANEL_PADDING_X : -SELECT_PANEL_PADDING_X;
625+
this._offsetX = this.multiple ? SELECT_MULTIPLE_PANEL_PADDING_X : SELECT_PANEL_PADDING_X;
626+
627+
if (!this._isRtl()) {
628+
this._offsetX *= -1;
629+
}
615630

616631
const panelHeight =
617632
Math.min(this.options.length * SELECT_OPTION_HEIGHT, SELECT_PANEL_MAX_HEIGHT);

0 commit comments

Comments
 (0)