Skip to content

Commit 05dffe8

Browse files
committed
fix floating placehodler and color
1 parent 5cf0348 commit 05dffe8

File tree

6 files changed

+42
-44
lines changed

6 files changed

+42
-44
lines changed

src/demo-app/select/select-demo.html

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
<md-card>
77
<md-card-subtitle>ngModel</md-card-subtitle>
88

9-
<md-form-field>
10-
<md-select placeholder="Drink" [color]="drinksTheme" [(ngModel)]="currentDrink" [required]="drinksRequired"
9+
<md-form-field [floatPlaceholder]="floatPlaceholder" [color]="drinksTheme">
10+
<md-select placeholder="Drink" [(ngModel)]="currentDrink" [required]="drinksRequired"
1111
[disabled]="drinksDisabled" #drinkControl="ngModel">
1212
<md-option>None</md-option>
1313
<md-option *ngFor="let drink of drinks" [value]="drink.value" [disabled]="drink.disabled">
@@ -44,8 +44,8 @@
4444
<md-card-subtitle>Multiple selection</md-card-subtitle>
4545

4646
<md-card-content>
47-
<md-form-field>
48-
<md-select multiple [color]="pokemonTheme" placeholder="Pokemon" [(ngModel)]="currentPokemon"
47+
<md-form-field [color]="pokemonTheme">
48+
<md-select multiple placeholder="Pokemon" [(ngModel)]="currentPokemon"
4949
[required]="pokemonRequired" [disabled]="pokemonDisabled" #pokemonControl="ngModel">
5050
<md-option *ngFor="let creature of pokemon" [value]="creature.value">
5151
{{ creature.viewValue }}
@@ -138,9 +138,11 @@
138138
<md-card-subtitle>formControl</md-card-subtitle>
139139

140140
<md-card-content>
141-
<md-select placeholder="Food i would like to eat" [formControl]="foodControl">
142-
<md-option *ngFor="let food of foods" [value]="food.value"> {{ food.viewValue }}</md-option>
143-
</md-select>
141+
<md-form-field>
142+
<md-select placeholder="Food i would like to eat" [formControl]="foodControl">
143+
<md-option *ngFor="let food of foods" [value]="food.value"> {{ food.viewValue }}</md-option>
144+
</md-select>
145+
</md-form-field>
144146
<p> Value: {{ foodControl.value }} </p>
145147
<p> Touched: {{ foodControl.touched }} </p>
146148
<p> Dirty: {{ foodControl.dirty }} </p>

src/demo-app/select/select-demo.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ export class SelectDemo {
2121
currentPokemonFromGroup: string;
2222
currentDigimon: string;
2323
latestChangeEvent: MdSelectChange;
24-
floatPlaceholder: string = 'auto'; // add to form-field
24+
floatPlaceholder: string = 'auto';
2525
foodControl = new FormControl('pizza-1');
2626
topHeightCtrl = new FormControl(0);
2727
drinksTheme = 'primary';

src/lib/form-field/form-field.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,9 @@ let nextUniqueId = 0;
7373
'[class.mat-input-invalid]': '_control.errorState',
7474
'[class.mat-form-field-invalid]': '_control.errorState',
7575
'[class.mat-focused]': '_control.focused',
76+
'[class.mat-primary]': 'color == "primary"',
77+
'[class.mat-accent]': 'color == "accent"',
78+
'[class.mat-warn]': 'color == "warn"',
7679
'[class.ng-untouched]': '_shouldForward("untouched")',
7780
'[class.ng-touched]': '_shouldForward("touched")',
7881
'[class.ng-pristine]': '_shouldForward("pristine")',

src/lib/select/_select-theme.scss

Lines changed: 20 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,6 @@
33
@import '../core/style/form-common';
44
@import '../core/typography/typography-utils';
55

6-
@mixin _mat-select-inner-content-theme($palette) {
7-
$color: mat-color($palette);
8-
9-
.mat-select-trigger, .mat-select-arrow {
10-
color: $color;
11-
}
12-
}
136

147
@mixin mat-select-theme($theme) {
158
$foreground: map-get($theme, foreground);
@@ -19,14 +12,8 @@
1912
$warn: map-get($theme, warn);
2013
$is-dark-theme: map-get($theme, is-dark);
2114

22-
.mat-select-trigger,
23-
.mat-select-arrow {
24-
color: mat-color($foreground, secondary-text);
25-
}
26-
2715
.mat-select-disabled .mat-select-value,
28-
.mat-select-arrow,
29-
.mat-select-trigger {
16+
.mat-select-arrow {
3017
color: mat-color($foreground, secondary-text);
3118
}
3219

@@ -44,23 +31,32 @@
4431
}
4532
}
4633

47-
.mat-select:focus:not(.mat-select-disabled) {
48-
&.mat-primary {
49-
@include _mat-select-inner-content-theme($primary);
34+
.mat-form-field {
35+
&.mat-focused {
36+
&.mat-primary .mat-select-arrow {
37+
color: mat-color($primary);
38+
}
39+
40+
&.mat-accent .mat-select-arrow {
41+
color: mat-color($accent);
42+
}
43+
44+
&.mat-warn .mat-select-arrow {
45+
color: mat-color($warn);
46+
}
5047
}
5148

52-
&.mat-accent {
53-
@include _mat-select-inner-content-theme($accent);
49+
.mat-select.mat-select-invalid .mat-select-arrow {
50+
color: mat-color($warn);
5451
}
5552

56-
&.mat-warn,
57-
&.mat-select-invalid {
58-
@include _mat-select-inner-content-theme($warn);
53+
.mat-select.mat-select-disabled .mat-select-arrow {
54+
color: mat-color($foreground, secondary-text);
5955
}
6056
}
6157

62-
.mat-select.mat-select-invalid:not(.mat-select-disabled) {
63-
@include _mat-select-inner-content-theme($warn);
58+
.mat-select.mat-select-disabled .mat-select-arrow {
59+
color: mat-color($warn);
6460
}
6561
}
6662

src/lib/select/select.scss

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,6 @@ $mat-select-item-height: 3em !default;
1212
.mat-select {
1313
display: inline-block;
1414
outline: none;
15-
16-
// Inside of a form field we want it to expand to take the available space.
17-
.mat-form-field & {
18-
width: 100%;
19-
}
2015
}
2116

2217
.mat-select-trigger {

src/lib/select/select.ts

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -47,13 +47,11 @@ import {
4747
} from '@angular/core';
4848
import {ControlValueAccessor, FormGroupDirective, NgControl, NgForm} from '@angular/forms';
4949
import {
50-
CanColor,
5150
CanDisable,
5251
HasTabIndex,
5352
MdOptgroup,
5453
MdOption,
5554
MdOptionSelectionChange,
56-
mixinColor,
5755
mixinDisabled,
5856
mixinTabIndex,
5957
} from '@angular/material/core';
@@ -147,8 +145,7 @@ export class MdSelectChange {
147145
export class MdSelectBase {
148146
constructor(public _renderer: Renderer2, public _elementRef: ElementRef) {}
149147
}
150-
export const _MdSelectMixinBase =
151-
mixinTabIndex(mixinColor(mixinDisabled(MdSelectBase), 'primary'));
148+
export const _MdSelectMixinBase = mixinTabIndex(mixinDisabled(MdSelectBase));
152149

153150

154151
/**
@@ -165,7 +162,7 @@ export class MdSelectTrigger {}
165162
selector: 'md-select, mat-select',
166163
templateUrl: 'select.html',
167164
styleUrls: ['select.css'],
168-
inputs: ['color', 'disabled', 'tabIndex'],
165+
inputs: ['disabled', 'tabIndex'],
169166
encapsulation: ViewEncapsulation.None,
170167
preserveWhitespaces: false,
171168
changeDetection: ChangeDetectionStrategy.OnPush,
@@ -197,7 +194,7 @@ export class MdSelectTrigger {}
197194
exportAs: 'mdSelect, matSelect',
198195
})
199196
export class MdSelect extends _MdSelectMixinBase implements AfterContentInit, OnDestroy, OnInit,
200-
ControlValueAccessor, CanColor, CanDisable, HasTabIndex, MdFormFieldControl<any> {
197+
ControlValueAccessor, CanDisable, HasTabIndex, MdFormFieldControl<any> {
201198
/** Whether or not the overlay panel is open. */
202199
private _panelOpen = false;
203200

@@ -379,7 +376,6 @@ export class MdSelect extends _MdSelectMixinBase implements AfterContentInit, On
379376
set value(newValue: any) {
380377
this.writeValue(newValue);
381378
this._value = newValue;
382-
this.stateChanges.next();
383379
}
384380
private _value: any;
385381

@@ -455,6 +451,7 @@ export class MdSelect extends _MdSelectMixinBase implements AfterContentInit, On
455451

456452
ngOnInit() {
457453
this._selectionModel = new SelectionModel<MdOption>(this.multiple, undefined, false);
454+
this.stateChanges.next();
458455
}
459456

460457
ngAfterContentInit() {
@@ -753,6 +750,7 @@ export class MdSelect extends _MdSelectMixinBase implements AfterContentInit, On
753750
if (correspondingOption) {
754751
isUserInput ? correspondingOption._selectViaInteraction() : correspondingOption.select();
755752
this._selectionModel.select(correspondingOption);
753+
this.stateChanges.next();
756754
}
757755

758756
return correspondingOption;
@@ -770,6 +768,7 @@ export class MdSelect extends _MdSelectMixinBase implements AfterContentInit, On
770768
option.deselect();
771769
}
772770
});
771+
this.stateChanges.next();
773772
}
774773

775774
private _getTriggerRect(): ClientRect {
@@ -810,6 +809,7 @@ export class MdSelect extends _MdSelectMixinBase implements AfterContentInit, On
810809
// TODO(crisbeto): handle blank/null options inside multi-select.
811810
if (this.multiple) {
812811
this._selectionModel.toggle(option);
812+
this.stateChanges.next();
813813
wasSelected ? option.deselect() : option.select();
814814
this._sortValues();
815815
} else {
@@ -819,6 +819,7 @@ export class MdSelect extends _MdSelectMixinBase implements AfterContentInit, On
819819
this._propagateChanges(option.value);
820820
} else {
821821
this._selectionModel.select(option);
822+
this.stateChanges.next();
822823
}
823824
}
824825

@@ -840,6 +841,7 @@ export class MdSelect extends _MdSelectMixinBase implements AfterContentInit, On
840841
this._selectionModel.select(option);
841842
}
842843
});
844+
this.stateChanges.next();
843845
}
844846
}
845847

0 commit comments

Comments
 (0)