Skip to content

Commit 8c483f2

Browse files
author
Ibrahim Ghazal
committed
fix(select): make floating labels work for ion-select
fixes #10751
1 parent 446e468 commit 8c483f2

File tree

4 files changed

+42
-4
lines changed

4 files changed

+42
-4
lines changed

src/components/label/label.scss

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,3 @@ ion-label[floating] {
6565

6666
max-width: 100%;
6767
}
68-
69-
.item-select ion-label[floating] {
70-
transform: translate3d(0, 0, 0) scale(.8);
71-
}

src/components/select/select.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -387,6 +387,21 @@ export class Select extends Ion implements AfterContentInit, ControlValueAccesso
387387
return (this._multi ? this._texts : this._texts.join());
388388
}
389389

390+
/**
391+
* @private
392+
*/
393+
checkHasValue(inputValue: any) {
394+
if (this._item) {
395+
let hasValue: boolean;
396+
if (Array.isArray(inputValue)) {
397+
hasValue = inputValue.length > 0;
398+
} else {
399+
hasValue = !isBlank(inputValue);
400+
}
401+
this._item.setElementClass('input-has-value', hasValue);
402+
}
403+
}
404+
390405
/**
391406
* @private
392407
*/
@@ -445,6 +460,7 @@ export class Select extends Ion implements AfterContentInit, ControlValueAccesso
445460
console.debug('select, writeValue', val);
446461
this._values = (Array.isArray(val) ? val : isBlank(val) ? [] : [val]);
447462
this._updOpts();
463+
this.checkHasValue(val);
448464
}
449465

450466
/**
@@ -464,6 +480,7 @@ export class Select extends Ion implements AfterContentInit, ControlValueAccesso
464480
fn(val);
465481
this._values = (Array.isArray(val) ? val : isBlank(val) ? [] : [val]);
466482
this._updOpts();
483+
this.checkHasValue(val);
467484
this.onTouched();
468485
};
469486
}
@@ -481,6 +498,7 @@ export class Select extends Ion implements AfterContentInit, ControlValueAccesso
481498
console.debug('select, onChange w/out formControlName', val);
482499
this._values = (Array.isArray(val) ? val : isBlank(val) ? [] : [val]);
483500
this._updOpts();
501+
this.checkHasValue(val);
484502
this.onTouched();
485503
}
486504

src/components/select/test/multiple-value/main.html

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,4 +83,20 @@
8383
</ion-list>
8484
</form>
8585

86+
<ion-item>
87+
<ion-label floating>Floating label</ion-label>
88+
<ion-select multiple="true">
89+
<ion-option value="bacon">Bacon</ion-option>
90+
<ion-option value="olives">Black Olives</ion-option>
91+
<ion-option value="xcheese">Extra Cheese</ion-option>
92+
<ion-option value="peppers">Green Peppers</ion-option>
93+
<ion-option value="mushrooms">Mushrooms</ion-option>
94+
<ion-option value="onions">Onions</ion-option>
95+
<ion-option value="pepperoni">Pepperoni</ion-option>
96+
<ion-option value="pineapple">Pineapple</ion-option>
97+
<ion-option value="sausage">Sausage</ion-option>
98+
<ion-option value="Spinach">Spinach</ion-option>
99+
</ion-select>
100+
</ion-item>
101+
86102
</ion-content>

src/components/select/test/single-value/main.html

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,4 +137,12 @@
137137
</ion-item>
138138
</form>
139139

140+
<ion-item>
141+
<ion-label floating>Floating label</ion-label>
142+
<ion-select>
143+
<ion-option value="f">Female</ion-option>
144+
<ion-option value="m">Male</ion-option>
145+
</ion-select>
146+
</ion-item>
147+
140148
</ion-content>

0 commit comments

Comments
 (0)