Skip to content

Commit b94bec2

Browse files
committed
fix(segment): update segment content to disabled when button is
1 parent 279300f commit b94bec2

File tree

3 files changed

+27
-4
lines changed

3 files changed

+27
-4
lines changed

core/src/components/segment-button/segment-button.tsx

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,27 @@ export class SegmentButton implements ComponentInterface, ButtonInterface {
7272
addEventListener(segmentEl, 'ionSelect', this.updateState);
7373
addEventListener(segmentEl, 'ionStyle', this.updateStyle);
7474
}
75+
76+
// Return if there is no contentId defined
77+
if (!this.contentId) return;
78+
79+
// Attempt to find the Segment Content by its contentId
80+
const segmentContent = document.getElementById(this.contentId) as HTMLIonSegmentContentElement | null;
81+
82+
// If no associated Segment Content exists, log an error and return
83+
if (!segmentContent) {
84+
console.error(`Segment Button: Unable to find Segment Content with id="${this.contentId}".`);
85+
return;
86+
}
87+
88+
// Ensure the found element is a valid ION-SEGMENT-CONTENT
89+
if (segmentContent.tagName !== 'ION-SEGMENT-CONTENT') {
90+
console.error(`Segment Button: Element with id="${this.contentId}" is not an <ion-segment-content> element.`);
91+
return;
92+
}
93+
94+
// Set the disabled state of the Segment Content based on the button's disabled state
95+
segmentContent.disabled = this.disabled;
7596
}
7697

7798
disconnectedCallback() {

core/src/components/segment-view/segment-view.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,8 @@ export class SegmentView implements ComponentInterface {
8282
}
8383

8484
// Update active content ID and scroll to the segment content
85+
// TODO this is erroring because all of the segment contents are disabled
86+
// in the last example
8587
this.activeContentId = segmentContent.id;
8688
this.setContent(segmentContent.id);
8789

core/src/components/segment-view/test/disabled/index.html

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@
6060
</ion-segment-button>
6161
</ion-segment>
6262
<ion-segment-view>
63-
<ion-segment-content disabled id="all">All</ion-segment-content>
63+
<ion-segment-content id="all">All</ion-segment-content>
6464
<ion-segment-content id="favorites">Favorites</ion-segment-content>
6565
</ion-segment-view>
6666

@@ -77,7 +77,7 @@
7777
</ion-segment>
7878
<ion-segment-view>
7979
<ion-segment-content id="paid">Paid</ion-segment-content>
80-
<ion-segment-content disabled id="free">Free</ion-segment-content>
80+
<ion-segment-content id="free">Free</ion-segment-content>
8181
<ion-segment-content id="top">Top</ion-segment-content>
8282
</ion-segment-view>
8383

@@ -97,8 +97,8 @@
9797
</ion-segment>
9898
<ion-segment-view>
9999
<ion-segment-content id="a">a</ion-segment-content>
100-
<ion-segment-content disabled id="b">b</ion-segment-content>
101-
<ion-segment-content disabled id="c">c</ion-segment-content>
100+
<ion-segment-content id="b">b</ion-segment-content>
101+
<ion-segment-content id="c">c</ion-segment-content>
102102
<ion-segment-content id="d">d</ion-segment-content>
103103
</ion-segment-view>
104104

0 commit comments

Comments
 (0)