Skip to content

Commit

Permalink
fix(select): make floating labels work for ion-select
Browse files Browse the repository at this point in the history
fixes #10751
  • Loading branch information
ibrahim-mg-iga committed Mar 14, 2017
1 parent 446e468 commit 8c483f2
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 4 deletions.
4 changes: 0 additions & 4 deletions src/components/label/label.scss
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,3 @@ ion-label[floating] {

max-width: 100%;
}

.item-select ion-label[floating] {
transform: translate3d(0, 0, 0) scale(.8);
}
18 changes: 18 additions & 0 deletions src/components/select/select.ts
Original file line number Diff line number Diff line change
Expand Up @@ -387,6 +387,21 @@ export class Select extends Ion implements AfterContentInit, ControlValueAccesso
return (this._multi ? this._texts : this._texts.join());
}

/**
* @private
*/
checkHasValue(inputValue: any) {
if (this._item) {
let hasValue: boolean;
if (Array.isArray(inputValue)) {
hasValue = inputValue.length > 0;
} else {
hasValue = !isBlank(inputValue);
}
this._item.setElementClass('input-has-value', hasValue);
}
}

/**
* @private
*/
Expand Down Expand Up @@ -445,6 +460,7 @@ export class Select extends Ion implements AfterContentInit, ControlValueAccesso
console.debug('select, writeValue', val);
this._values = (Array.isArray(val) ? val : isBlank(val) ? [] : [val]);
this._updOpts();
this.checkHasValue(val);
}

/**
Expand All @@ -464,6 +480,7 @@ export class Select extends Ion implements AfterContentInit, ControlValueAccesso
fn(val);
this._values = (Array.isArray(val) ? val : isBlank(val) ? [] : [val]);
this._updOpts();
this.checkHasValue(val);
this.onTouched();
};
}
Expand All @@ -481,6 +498,7 @@ export class Select extends Ion implements AfterContentInit, ControlValueAccesso
console.debug('select, onChange w/out formControlName', val);
this._values = (Array.isArray(val) ? val : isBlank(val) ? [] : [val]);
this._updOpts();
this.checkHasValue(val);
this.onTouched();
}

Expand Down
16 changes: 16 additions & 0 deletions src/components/select/test/multiple-value/main.html
Original file line number Diff line number Diff line change
Expand Up @@ -83,4 +83,20 @@
</ion-list>
</form>

<ion-item>
<ion-label floating>Floating label</ion-label>
<ion-select multiple="true">
<ion-option value="bacon">Bacon</ion-option>
<ion-option value="olives">Black Olives</ion-option>
<ion-option value="xcheese">Extra Cheese</ion-option>
<ion-option value="peppers">Green Peppers</ion-option>
<ion-option value="mushrooms">Mushrooms</ion-option>
<ion-option value="onions">Onions</ion-option>
<ion-option value="pepperoni">Pepperoni</ion-option>
<ion-option value="pineapple">Pineapple</ion-option>
<ion-option value="sausage">Sausage</ion-option>
<ion-option value="Spinach">Spinach</ion-option>
</ion-select>
</ion-item>

</ion-content>
8 changes: 8 additions & 0 deletions src/components/select/test/single-value/main.html
Original file line number Diff line number Diff line change
Expand Up @@ -137,4 +137,12 @@
</ion-item>
</form>

<ion-item>
<ion-label floating>Floating label</ion-label>
<ion-select>
<ion-option value="f">Female</ion-option>
<ion-option value="m">Male</ion-option>
</ion-select>
</ion-item>

</ion-content>

0 comments on commit 8c483f2

Please sign in to comment.