fix(segment): fixed segment UI not updating when changing value from view button

Added a test for this. Closes #657
This commit is contained in:
Brandy Carney
2015-12-10 12:58:51 -05:00
parent 9f0ab4a86e
commit 37ca863531
4 changed files with 46 additions and 12 deletions

View File

@@ -72,6 +72,9 @@ export class Segment extends Ion {
*/
writeValue(value) {
this.value = !value ? '' : value;
for (let button of this.buttons) {
button.isActive = (button.value === value);
}
}
/**
@@ -109,11 +112,9 @@ export class Segment extends Ion {
if (this.buttons.length == 0) {
return;
}
this.buttons.forEach(function(button) {
if (button.value === value) {
button.isActive = true;
}
});
for (let button of this.buttons) {
button.isActive = (button.value === value);
}
}
/**

View File

@@ -0,0 +1,8 @@
it('existing should be selected', function() {
element(by.css('.e2eSegmentExistingSegment')).click();
});
it('test should be selected', function() {
element(by.css('.e2eSegmentTestButton')).click();
});

View File

@@ -10,7 +10,7 @@ import {App, Page} from 'ionic/ionic';
})
class SegmentPage {
constructor(fb: FormBuilder) {
this.relationship = 'enemies';
this.signInType = 'new';
}
}

View File

@@ -5,18 +5,43 @@
</ion-navbar>
<ion-toolbar>
<ion-segment [(ng-model)]="relationship">
<ion-segment-button value="friends" class="e2eSegmentFriends">
Friends
<ion-segment [(ng-model)]="signInType">
<ion-segment-button value="new">
New
</ion-segment-button>
<ion-segment-button value="enemies">
Enemies
<ion-segment-button value="existing" class="e2eSegmentExistingSegment">
Existing
</ion-segment-button>
<ion-segment-button value="test">
Test
</ion-segment-button>
</ion-segment>
</ion-toolbar>
<ion-content padding>
<p>Are we friends or enemies? <b>{{ relationship }}</b></p>
<ion-row>
<ion-col>
<button type="button" block (click)="signInType='new'">New</button>
</ion-col>
<ion-col>
<button type="button" light block (click)="signInType='existing'">Existing</button>
</ion-col>
<ion-col>
<button type="button" dark block (click)="signInType='test'" class="e2eSegmentTestButton">Test</button>
</ion-col>
</ion-row>
<div [ng-switch]="signInType">
<div *ng-switch-when="'existing'">
Signing up as an <b>Existing User</b>.
</div>
<div *ng-switch-when="'new'">
Signing up as a <b>New User</b>.
</div>
<div *ng-switch-when="'test'">
Signing up as a <b>Test User</b>.
</div>
</div>
</ion-content>