Skip to content
This repository was archived by the owner on Sep 5, 2024. It is now read-only.

Commit 16dbf67

Browse files
committed
fix(select) rework select to match Material Design spec
automatic 16px horizontal margin when in row layout add md-inline-form support allow support for custom margins
1 parent d593229 commit 16dbf67

File tree

2 files changed

+48
-24
lines changed

2 files changed

+48
-24
lines changed

src/components/select/select.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1550,7 +1550,7 @@ function SelectProvider($$interimElementProvider) {
15501550
transformOrigin = '50% 100%';
15511551
}
15521552
} else {
1553-
left = (targetRect.left + centeredRect.left - centeredRect.paddingLeft) + 2;
1553+
left = (targetRect.left + centeredRect.left - centeredRect.paddingLeft);
15541554
top = Math.floor(targetRect.top + targetRect.height / 2 - centeredRect.height / 2 -
15551555
centeredRect.top + contentNode.scrollTop) + 2;
15561556

src/components/select/select.scss

Lines changed: 47 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,23 @@ $select-option-height: 48px !default;
55
$select-option-padding: 16px !default;
66
$select-container-padding: 16px !default;
77
$select-container-transition-duration: 350ms !default;
8+
$select-value-padding-top: 6px;
9+
$select-value-padding-bottom: 4px;
810

911
$select-max-visible-options: 5 !default;
1012

13+
// from input.scss
14+
$input-container-margin-top: 18px !default;
15+
$input-container-padding-top: 2px !default;
16+
$input-padding-top: 2px !default;
17+
$input-padding-bottom: 1px !default;
18+
19+
$input-alignment: ($input-padding-top + $input-padding-bottom)
20+
- ($select-value-padding-top + $select-value-padding-bottom);
21+
$md-inline-alignment: ($input-container-margin-top + $input-container-padding-top)
22+
+ ($input-padding-top + $input-padding-bottom)
23+
- ($select-value-padding-top + $select-value-padding-bottom);
24+
1125
// Fixes the animations with the floating label when select is inside an input container
1226
md-input-container {
1327
&:not([md-no-float]) {
@@ -72,7 +86,7 @@ md-input-container {
7286
}
7387

7488
md-input-container > md-select {
75-
margin: 0;
89+
margin-top: $input-alignment;
7690
order: 2;
7791
}
7892

@@ -102,7 +116,6 @@ md-input-container.md-input-invalid {
102116

103117
md-select {
104118
display: flex;
105-
margin: 2.5*$baseline-grid 0 3*$baseline-grid + 2 0;
106119

107120
&[required], &.ng-required {
108121
&.ng-invalid {
@@ -120,7 +133,12 @@ md-select {
120133
// to create a dotted line under the input.
121134
background-size: 4px 1px;
122135
background-repeat: repeat-x;
123-
margin-bottom: -1px; // Shift downward so dotted line is positioned the same as other bottom borders
136+
// Add to padding-bottom to keep dotted line aligned with other bottom borders
137+
// Sub from padding-top to keep height consistent
138+
// Translate text 1px up to keep in alignment
139+
padding-bottom: $select-value-padding-bottom + 1;
140+
padding-top: $select-value-padding-top - 1;
141+
transform: translate3d(0, 1px, 0);
124142
}
125143

126144
&:focus {
@@ -135,43 +153,33 @@ md-select {
135153
}
136154
&.ng-invalid.ng-touched {
137155
._md-select-value {
138-
border-bottom-style: solid;
139-
padding-bottom: 1px;
156+
border-bottom: 2px solid;
140157
}
141158
}
142159
&:focus {
143160
._md-select-value {
144161
border-bottom-width: 2px;
145162
border-bottom-style: solid;
146-
padding-bottom: 0;
147-
}
148-
&.ng-invalid.ng-touched {
149-
._md-select-value {
150-
padding-bottom: 0;
151-
}
163+
padding-bottom: $select-value-padding-bottom - 1;
152164
}
153165
}
154166
}
155167
}
156168

157-
// Fix value by 1px to align with standard text inputs (and spec)
158-
md-input-container.md-input-has-value ._md-select-value {
159-
> span:not(._md-select-icon) {
160-
transform: translate3d(0, 1px, 0);
161-
}
162-
}
163-
164169
._md-select-value {
165170
display: flex;
166171
align-items: center;
167-
padding: 2px 2px 1px;
172+
padding-top: $select-value-padding-top;
173+
padding-bottom: $select-value-padding-bottom;
168174
border-bottom-width: 1px;
169175
border-bottom-style: solid;
170176
background-color: rgba(0,0,0,0);
171177
position: relative;
172178
box-sizing: content-box;
173-
min-width: 8 * $baseline-grid;
179+
min-width: 11 * $baseline-grid;
174180
min-height: 26px;
181+
margin-bottom: auto;
182+
-ms-flex-item-align: start; // workaround for margin-bottom: auto
175183
flex-grow: 1;
176184

177185

@@ -192,7 +200,6 @@ md-input-container.md-input-has-value ._md-select-value {
192200
align-items: flex-end;
193201
text-align: end;
194202
width: 3 * $baseline-grid;
195-
margin: 0 .5 * $baseline-grid;
196203
transform: translate3d(0, -2px, 0);
197204
font-size: 1.2rem;
198205
}
@@ -202,17 +209,18 @@ md-input-container.md-input-has-value ._md-select-value {
202209
content: '\25BC';
203210
position: relative;
204211
top: 2px;
212+
@include rtl(right, -4px, auto);
213+
@include rtl(left, auto, -4px);
205214
speak: none;
206215
font-size: 16px;
207-
transform: scaleY(0.6) scaleX(1);
216+
transform: scaleY(0.5);
208217
}
209218

210219
&._md-select-placeholder {
211220
display: flex;
212221
order: 1;
213222
pointer-events: none;
214223
-webkit-font-smoothing: antialiased;
215-
padding-left: 2px;
216224
z-index: 1;
217225
}
218226
}
@@ -315,3 +323,19 @@ md-select-menu[multiple] {
315323
}
316324
}
317325
}
326+
327+
.layout-row,
328+
.layout-xs-row, .layout-gt-xs-row,
329+
.layout-sm-row, .layout-gt-sm-row,
330+
.layout-md-row, .layout-gt-md-row,
331+
.layout-lg-row, .layout-gt-lg-row,
332+
.layout-xl-row {
333+
& > md-select:not(:last-child), {
334+
@include rtl(margin-left, 0, $select-container-padding);
335+
@include rtl(margin-right, $select-container-padding, 0);
336+
}
337+
338+
.md-inline-form & > md-select {
339+
margin-top: $md-inline-alignment;
340+
}
341+
}

0 commit comments

Comments
 (0)