mirror of
https://github.com/ionic-team/ionic-framework.git
synced 2025-08-20 12:29:55 +08:00
fix(segment): animate the highlight with value changes
This commit is contained in:
@ -78,7 +78,17 @@ export class Segment implements ComponentInterface {
|
|||||||
@Prop({ mutable: true }) value?: SegmentValue;
|
@Prop({ mutable: true }) value?: SegmentValue;
|
||||||
|
|
||||||
@Watch('value')
|
@Watch('value')
|
||||||
protected valueChanged(value: SegmentValue | undefined) {
|
protected valueChanged(value: SegmentValue | undefined, oldValue?: SegmentValue | undefined) {
|
||||||
|
if (oldValue !== undefined && value !== undefined) {
|
||||||
|
const buttons = this.getButtons();
|
||||||
|
const previous = buttons.find(button => button.value === oldValue);
|
||||||
|
const current = buttons.find(button => button.value === value);
|
||||||
|
|
||||||
|
if (previous && current) {
|
||||||
|
this.checkButton(previous, current);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* `ionSelect` is emitted every time the value changes (internal or external changes).
|
* `ionSelect` is emitted every time the value changes (internal or external changes).
|
||||||
* Used by `ion-segment-button` to determine if the button should be checked.
|
* Used by `ion-segment-button` to determine if the button should be checked.
|
||||||
@ -208,7 +218,7 @@ export class Segment implements ComponentInterface {
|
|||||||
this.ionChange.emit({ value });
|
this.ionChange.emit({ value });
|
||||||
}
|
}
|
||||||
|
|
||||||
private getButtons() {
|
private getButtons(): HTMLIonSegmentButtonElement[] {
|
||||||
return Array.from(this.el.querySelectorAll('ion-segment-button'));
|
return Array.from(this.el.querySelectorAll('ion-segment-button'));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user