Skip to content

Commit c6d07d0

Browse files
committed
make placeholder float when select is opened, and prevent it from overlapping the trigger arrow
1 parent ed8cedf commit c6d07d0

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
@@ -589,8 +589,8 @@ describe('MdSelect', () => {
589589

590590
const options =
591591
overlayContainerElement.querySelectorAll('md-option') as NodeListOf<HTMLElement>;
592-
expect(options[1].classList)
593-
.toContain('mat-selected', `Expected option with the control's new value to be selected.`);
592+
expect(options[1].classList).toContain('mat-selected',
593+
`Expected option with the control's new value to be selected.`);
594594
});
595595

596596
it('should update the form value when the view changes', () => {
@@ -973,7 +973,7 @@ describe('MdSelect', () => {
973973
trigger = fixture.debugElement.query(By.css('.mat-select-trigger')).nativeElement;
974974
formField = fixture.debugElement.query(By.css('.mat-form-field')).nativeElement;
975975
}));
976-
/* TODO(mmalerba): Verify this is correct behavior
976+
977977
it('should float the placeholder when the panel is open and unselected', () => {
978978
expect(formField.classList.contains('mat-form-field-should-float'))
979979
.toBe(false, 'Expected placeholder to initially have a normal position.');
@@ -991,7 +991,7 @@ describe('MdSelect', () => {
991991
expect(formField.classList.contains('mat-form-field-should-float'))
992992
.toBe(false, 'Expected placeholder to animate back down to normal position.');
993993
});
994-
*/
994+
995995
it('should add a class to the panel when the menu is done animating', fakeAsync(() => {
996996
trigger.click();
997997
fixture.detectChanges();
@@ -1036,7 +1036,7 @@ describe('MdSelect', () => {
10361036
const optionTop = options[index].getBoundingClientRect().top;
10371037
const triggerFontSize = parseInt(window.getComputedStyle(trigger)['font-size']);
10381038

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

@@ -1150,8 +1150,8 @@ describe('MdSelect', () => {
11501150
fixture.whenStable().then(() => {
11511151
// The selected option should be scrolled to the center of the panel.
11521152
// This will be its original offset from the scrollTop - half the panel height + half the
1153-
// option height. 10 (option index + 3 group labels before it) * 48 (option height) = 480px.
1154-
// 480 (offset from scrollTop) - 256/2 + 48/2 = 376px
1153+
// option height. 10 (option index + 3 group labels before it) * 48 (option height) =
1154+
// 480px. 480 (offset from scrollTop) - 256/2 + 48/2 = 376px
11551155
expect(Math.floor(scrollContainer.scrollTop))
11561156
.toBe(376, `Expected overlay panel to be scrolled to center the selected option.`);
11571157

@@ -3144,7 +3144,6 @@ class BasicSelectWithTheming {
31443144
<md-option *ngFor="let food of foods" [value]="food.value">
31453145
{{ food.viewValue }}
31463146
</md-option>
3147-
31483147
<md-option>None</md-option>
31493148
</md-select>
31503149
</md-form-field>
@@ -3190,12 +3189,10 @@ class FalsyValueSelect {
31903189
<md-select placeholder="Pokemon" [formControl]="control">
31913190
<md-optgroup *ngFor="let group of pokemonTypes" [label]="group.name"
31923191
[disabled]="group.disabled">
3193-
31943192
<md-option *ngFor="let pokemon of group.pokemon" [value]="pokemon.value">
31953193
{{ pokemon.viewValue }}
31963194
</md-option>
31973195
</md-optgroup>
3198-
31993196
<md-option value="mime-11">Mr. Mime</md-option>
32003197
</md-select>
32013198
</md-form-field>
@@ -3322,7 +3319,7 @@ class BasicSelectWithoutFormsPreselected {
33223319
}
33233320

33243321
@Component({
3325-
template: `
3322+
template: `
33263323
<md-form-field>
33273324
<md-select placeholder="Food" [(value)]="selectedFoods" multiple>
33283325
<md-option *ngFor="let food of foods" [value]="food.value">
@@ -3346,8 +3343,8 @@ class BasicSelectWithoutFormsMultiple {
33463343

33473344
@Component({
33483345
selector: 'select-with-custom-trigger',
3349-
template: `
3350-
<md-form-field>
3346+
template: `
3347+
<md-form-field>
33513348
<md-select placeholder="Food" [formControl]="control" #select="mdSelect">
33523349
<md-select-trigger>
33533350
{{ 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
@@ -1221,7 +1221,7 @@ export class MdSelect extends _MdSelectMixinBase implements AfterContentInit, On
12211221
}
12221222

12231223
// Implemented as part of MdFormFieldControl.
1224-
get shouldPlaceholderFloat() { return !this.empty; }
1224+
get shouldPlaceholderFloat() { return this._panelOpen || !this.empty; }
12251225
}
12261226

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

0 commit comments

Comments
 (0)