Skip to content

Commit 7e3434a

Browse files
committed
make placeholder float when select is opened, and prevent it from overlapping the trigger arrow
1 parent 9749bc1 commit 7e3434a

File tree

4 files changed

+23
-18
lines changed

4 files changed

+23
-18
lines changed

src/demo-app/baseline/baseline-demo.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
</md-form-field>
1616
| Text 5 |
1717
<md-form-field>
18-
<md-select placeholder="Select">
18+
<md-select placeholder="This placeholder is really really really long">
1919
<md-option value="option">Option</md-option>
2020
<md-option value="long">This option is really really really long</md-option>
2121
</md-select>
@@ -46,7 +46,7 @@ <h1>
4646
</md-form-field>
4747
| Text 5 |
4848
<md-form-field>
49-
<md-select placeholder="Select">
49+
<md-select placeholder="This placeholder is really really really long">
5050
<md-option value="option">Option</md-option>
5151
<md-option value="long">This option is really really really long</md-option>
5252
</md-select>

src/lib/select/select.scss

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ $mat-select-arrow-margin: 4px !default;
99
$mat-select-panel-max-height: 256px !default;
1010
$mat-select-item-height: 3em !default;
1111

12+
$mat-select-placeholder-arrow-space: 2 * ($mat-select-arrow-size + $mat-select-arrow-margin);
13+
1214
.mat-select {
1315
//display: inline-block;
1416
outline: none;
@@ -82,6 +84,12 @@ $mat-select-item-height: 3em !default;
8284
}
8385
}
8486

85-
.mat-form-field-type-mat-select .mat-form-field-flex {
86-
cursor: pointer;
87+
.mat-form-field-type-mat-select {
88+
.mat-form-field-flex {
89+
cursor: pointer;
90+
}
91+
92+
.mat-form-field-placeholder {
93+
width: calc(100% - #{$mat-select-placeholder-arrow-space});
94+
}
8795
}

src/lib/select/select.spec.ts

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -581,8 +581,8 @@ describe('MdSelect', () => {
581581

582582
const options =
583583
overlayContainerElement.querySelectorAll('md-option') as NodeListOf<HTMLElement>;
584-
expect(options[1].classList)
585-
.toContain('mat-selected', `Expected option with the control's new value to be selected.`);
584+
expect(options[1].classList).toContain('mat-selected',
585+
`Expected option with the control's new value to be selected.`);
586586
});
587587

588588
it('should update the form value when the view changes', () => {
@@ -965,7 +965,7 @@ describe('MdSelect', () => {
965965
trigger = fixture.debugElement.query(By.css('.mat-select-trigger')).nativeElement;
966966
formField = fixture.debugElement.query(By.css('.mat-form-field')).nativeElement;
967967
}));
968-
/* TODO(mmalerba): Verify this is correct behavior
968+
969969
it('should float the placeholder when the panel is open and unselected', () => {
970970
expect(formField.classList.contains('mat-form-field-should-float'))
971971
.toBe(false, 'Expected placeholder to initially have a normal position.');
@@ -983,7 +983,7 @@ describe('MdSelect', () => {
983983
expect(formField.classList.contains('mat-form-field-should-float'))
984984
.toBe(false, 'Expected placeholder to animate back down to normal position.');
985985
});
986-
*/
986+
987987
it('should add a class to the panel when the menu is done animating', fakeAsync(() => {
988988
trigger.click();
989989
fixture.detectChanges();
@@ -1028,7 +1028,7 @@ describe('MdSelect', () => {
10281028
const optionTop = options[index].getBoundingClientRect().top;
10291029
const triggerFontSize = parseInt(window.getComputedStyle(trigger)['font-size']);
10301030

1031-
// TODO(mmalerba): not really sure where the "+1" is coming from here...
1031+
/** TODO(mmalerba): not really sure where the "+1" is coming from here... */
10321032
expect(Math.floor(optionTop)).toBe(Math.floor(triggerTop - triggerFontSize + 1),
10331033
`Expected trigger to align with option ${index}.`);
10341034

@@ -1142,8 +1142,8 @@ describe('MdSelect', () => {
11421142
fixture.whenStable().then(() => {
11431143
// The selected option should be scrolled to the center of the panel.
11441144
// This will be its original offset from the scrollTop - half the panel height + half the
1145-
// option height. 10 (option index + 3 group labels before it) * 48 (option height) = 480px.
1146-
// 480 (offset from scrollTop) - 256/2 + 48/2 = 376px
1145+
// option height. 10 (option index + 3 group labels before it) * 48 (option height) =
1146+
// 480px. 480 (offset from scrollTop) - 256/2 + 48/2 = 376px
11471147
expect(Math.floor(scrollContainer.scrollTop))
11481148
.toBe(376, `Expected overlay panel to be scrolled to center the selected option.`);
11491149

@@ -3068,7 +3068,6 @@ class BasicSelectWithTheming {
30683068
<md-option *ngFor="let food of foods" [value]="food.value">
30693069
{{ food.viewValue }}
30703070
</md-option>
3071-
30723071
<md-option>None</md-option>
30733072
</md-select>
30743073
</md-form-field>
@@ -3114,12 +3113,10 @@ class FalsyValueSelect {
31143113
<md-select placeholder="Pokemon" [formControl]="control">
31153114
<md-optgroup *ngFor="let group of pokemonTypes" [label]="group.name"
31163115
[disabled]="group.disabled">
3117-
31183116
<md-option *ngFor="let pokemon of group.pokemon" [value]="pokemon.value">
31193117
{{ pokemon.viewValue }}
31203118
</md-option>
31213119
</md-optgroup>
3122-
31233120
<md-option value="mime-11">Mr. Mime</md-option>
31243121
</md-select>
31253122
</md-form-field>
@@ -3246,7 +3243,7 @@ class BasicSelectWithoutFormsPreselected {
32463243
}
32473244

32483245
@Component({
3249-
template: `
3246+
template: `
32503247
<md-form-field>
32513248
<md-select placeholder="Food" [(value)]="selectedFoods" multiple>
32523249
<md-option *ngFor="let food of foods" [value]="food.value">
@@ -3269,8 +3266,8 @@ class BasicSelectWithoutFormsMultiple {
32693266

32703267
@Component({
32713268
selector: 'select-with-custom-trigger',
3272-
template: `
3273-
<md-form-field>
3269+
template: `
3270+
<md-form-field>
32743271
<md-select placeholder="Food" [formControl]="control" #select="mdSelect">
32753272
<md-select-trigger>
32763273
{{ select.selected?.viewValue.split('').reverse().join('') }}

src/lib/select/select.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1182,7 +1182,7 @@ export class MdSelect extends _MdSelectMixinBase implements AfterContentInit, On
11821182
}
11831183

11841184
// Implemented as part of MdFormFieldControl.
1185-
get shouldPlaceholderFloat() { return !this.empty; }
1185+
get shouldPlaceholderFloat() { return this._panelOpen || !this.empty; }
11861186
}
11871187

11881188
/** Clamps a value n between min and max values. */

0 commit comments

Comments
 (0)