refactor(segment): link the button and content with content-id and id

This commit is contained in:
Brandy Carney
2024-09-18 15:32:48 -04:00
parent 8af4d74846
commit 00c378f0f5
10 changed files with 111 additions and 70 deletions

View File

@ -307,6 +307,7 @@ export class Segment implements ComponentInterface {
this.value = current.value;
this.setCheckedClasses();
this.updateSegmentView();
}
private setCheckedClasses() {
@ -322,6 +323,24 @@ export class Segment implements ComponentInterface {
}
}
private updateSegmentView() {
const buttons = this.getButtons();
const button = buttons.find((btn) => btn.value === this.value);
// If the button does not have a contentId then there is
// no associated segment view to update
if (!button?.contentId) {
return;
}
const content = document.getElementById(button.contentId);
const segmentView = content?.closest('ion-segment-view');
if (segmentView) {
segmentView.setContent(button.contentId);
}
}
private scrollActiveButtonIntoView(smoothScroll = true) {
const { scrollable, value, el } = this;