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

Commit 0d4d37f

Browse files
clshortfuseSplaktar
authored andcommitted
fix(select): support for md-inline-form, more configurable SCSS
Create better flexibility for manipulating select while still following Material Design spec - Add `md-inline-form` support - Add alignment math to SCSS - Support custom margin and padding for `md-select` - Dynamically adjust bottom margin to allow denser layouts Fixes #8712. Closes #8716.
1 parent c2c336b commit 0d4d37f

File tree

3 files changed

+48
-25
lines changed

3 files changed

+48
-25
lines changed

package-lock.json

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/components/select/select.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2067,7 +2067,7 @@ function SelectProvider($$interimElementProvider) {
20672067
transformOrigin = '50% 100%';
20682068
}
20692069
} else {
2070-
left = (targetRect.left + centeredRect.left - centeredRect.paddingLeft) + 2;
2070+
left = (targetRect.left + centeredRect.left - centeredRect.paddingLeft);
20712071
top = Math.floor(targetRect.top + targetRect.height / 2 - centeredRect.height / 2 -
20722072
centeredRect.top + contentNode.scrollTop) + 2;
20732073

src/components/select/select.scss

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

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

14+
// from input.scss
15+
$input-container-margin-top: 18px !default;
16+
$input-container-padding-top: 2px !default;
17+
$input-padding-top: 2px !default;
18+
$input-padding-bottom: 1px !default;
19+
20+
$input-alignment: ($input-padding-top + $input-padding-bottom)
21+
- ($select-value-padding-top + $select-value-padding-bottom);
22+
$md-inline-alignment: ($input-container-margin-top + $input-container-padding-top)
23+
+ ($input-padding-top + $input-padding-bottom)
24+
- ($select-value-padding-top + $select-value-padding-bottom);
25+
1226
// Fixes the animations with the floating label when select is inside an input container
1327
md-input-container {
1428
&:not([md-no-float]) {
@@ -20,7 +34,7 @@ md-input-container {
2034
&.md-input-focused {
2135
&:not([md-no-float]) {
2236
.md-select-placeholder span:first-child {
23-
transform: translateY(-22px) translateX(-2px) scale(0.75);
37+
transform: translate(-2px, -22px) scale(0.75);
2438
}
2539
}
2640
}
@@ -47,7 +61,6 @@ md-input-container {
4761
margin: 3*$baseline-grid auto !important;
4862
}
4963

50-
5164
// enter: md-select scales in, then options fade in.
5265
&.md-active {
5366
display: block;
@@ -72,11 +85,19 @@ md-input-container {
7285
}
7386
}
7487

75-
md-input-container > md-select {
76-
margin: 0;
77-
order: 2;
88+
.md-inline-form md-select {
89+
margin-top: $md-inline-alignment;
7890
}
7991

92+
md-input-container {
93+
> md-select,
94+
.md-inline-form & > md-select {
95+
margin-top: $input-alignment;
96+
}
97+
> md-select {
98+
order: 2;
99+
}
100+
}
80101

81102
// Show the asterisk on the placeholder if the element is required
82103
//
@@ -103,7 +124,6 @@ md-input-container.md-input-invalid {
103124

104125
md-select {
105126
display: flex;
106-
margin: 2.5*$baseline-grid 0 3*$baseline-grid + 2 0;
107127

108128
&[required], &.ng-required {
109129
&.ng-empty.ng-invalid:not(.md-no-asterisk) {
@@ -124,6 +144,12 @@ md-select {
124144
// to create a dotted line under the input.
125145
background-size: 4px 1px;
126146
background-repeat: repeat-x;
147+
// Add to padding-bottom to keep dotted line aligned with other bottom borders
148+
// Sub from padding-top to keep height consistent
149+
// Translate text 1px up to keep in alignment
150+
padding-bottom: $select-value-padding-bottom + 1;
151+
padding-top: $select-value-padding-top - 1;
152+
transform: translateY(1px);
127153
}
128154

129155
&:focus {
@@ -138,20 +164,14 @@ md-select {
138164
}
139165
&.ng-invalid.ng-touched {
140166
.md-select-value {
141-
border-bottom-style: solid;
142-
padding-bottom: 1px;
167+
border-bottom: 2px solid;
143168
}
144169
}
145170
&:focus {
146171
.md-select-value {
147172
border-bottom-width: $select-border-width-default + 1px;
148173
border-bottom-style: solid;
149-
padding-bottom: 0;
150-
}
151-
&.ng-invalid.ng-touched {
152-
.md-select-value {
153-
padding-bottom: 0;
154-
}
174+
padding-bottom: $select-value-padding-bottom - 1;
155175
}
156176
}
157177
}
@@ -187,17 +207,19 @@ md-input-container md-select {
187207
.md-select-value {
188208
display: flex;
189209
align-items: center;
190-
padding-top: 2px;
191-
padding-bottom: 1px;
210+
padding-top: $select-value-padding-top;
211+
padding-bottom: $select-value-padding-bottom;
192212
@include rtl(padding-left, 0, $input-container-padding);
193213
@include rtl(padding-right, $input-container-padding, 0);
194214
border-bottom-width: $select-border-width-default;
195215
border-bottom-style: solid;
196216
background-color: rgba(0,0,0,0);
197217
position: relative;
198218
box-sizing: content-box;
199-
min-width: 8 * $baseline-grid;
219+
min-width: 11 * $baseline-grid;
200220
min-height: 26px;
221+
margin-bottom: auto;
222+
-ms-flex-item-align: start; // workaround for margin-bottom: auto
201223
flex-grow: 1;
202224

203225
> span:not(.md-select-icon) {
@@ -217,8 +239,7 @@ md-input-container md-select {
217239
@include rtl(align-items, flex-end, flex-start);
218240
@include rtl(text-align, right, left);
219241
width: 3 * $baseline-grid;
220-
margin: 0 .5 * $baseline-grid;
221-
transform: translate3d(0, -2px, 0);
242+
transform: translateY(-2px);
222243
font-size: 1.2rem;
223244
}
224245

@@ -227,9 +248,11 @@ md-input-container md-select {
227248
content: '\25BC';
228249
position: relative;
229250
top: 2px;
251+
@include rtl(right, -4px, auto);
252+
@include rtl(left, auto, -4px);
230253
speak: none;
231-
font-size: 13px;
232-
transform: scaleY(0.5) scaleX(1);
254+
font-size: 16px;
255+
transform: scaleY(0.5);
233256
}
234257

235258
&.md-select-placeholder {

0 commit comments

Comments
 (0)