mirror of
https://github.com/ionic-team/ionic-framework.git
synced 2025-08-19 03:32:21 +08:00
refactor(segment): link the button and content with content-id and id
This commit is contained in:
@ -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;
|
||||
|
||||
|
Reference in New Issue
Block a user