Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(angular): set active segment button when dynamically changing items #29418

Merged
merged 3 commits into from
May 1, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 5 additions & 9 deletions core/src/components/segment/segment.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -141,14 +141,6 @@ export class Segment implements ComponentInterface {
async componentDidLoad() {
this.setCheckedClasses();

/**
* If the value changes before watchers
* are setup, then the ionSelect watch callback
* will not fire. As a result, we manually
* fire this event when Select is loaded.
*/
this.ionSelect.emit({ value: this.value });

/**
* We need to wait for the buttons to all be rendered
* before we can scroll.
Expand Down Expand Up @@ -495,6 +487,10 @@ export class Segment implements ComponentInterface {
}
};

private onSlottedItemsChange = () => {
this.valueChanged(this.value);
sean-perkins marked this conversation as resolved.
Show resolved Hide resolved
};

private getSegmentButton = (selector: 'first' | 'last' | 'next' | 'previous'): HTMLIonSegmentButtonElement | null => {
const buttons = this.getButtons().filter((button) => !button.disabled);
const currIndex = buttons.findIndex((button) => button === document.activeElement);
Expand Down Expand Up @@ -573,7 +569,7 @@ export class Segment implements ComponentInterface {
'segment-scrollable': this.scrollable,
})}
>
<slot></slot>
<slot onSlotchange={this.onSlottedItemsChange}></slot>
</Host>
);
}
Expand Down