Skip to content

Commit d13cd2e

Browse files
author
Tanner Reits
committed
fix(segment): programmatically scroll content into view when setting value
1 parent 751ce5f commit d13cd2e

File tree

5 files changed

+11
-5
lines changed

5 files changed

+11
-5
lines changed

core/src/components.d.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2730,7 +2730,6 @@ export namespace Components {
27302730
*/
27312731
"disabled": boolean;
27322732
/**
2733-
* This method is used to programmatically set the displayed segment content in the segment view. Calling this method will update the `value` of the corresponding segment button.
27342733
* @param id : The id of the segment content to display.
27352734
* @param smoothScroll : Whether to animate the scroll transition.
27362735
*/

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,9 +106,12 @@ export class SegmentView implements ComponentInterface {
106106
}
107107

108108
/**
109+
* @internal
110+
*
109111
* This method is used to programmatically set the displayed segment content
110112
* in the segment view. Calling this method will update the `value` of the
111113
* corresponding segment button.
114+
*
112115
* @param id: The id of the segment content to display.
113116
* @param smoothScroll: Whether to animate the scroll transition.
114117
*/

core/src/components/segment/segment.tsx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,12 @@ export class Segment implements ComponentInterface {
106106
// The scroll listener should handle scrolling the active button into view as needed
107107
if (!this.segmentViewEl) {
108108
this.scrollActiveButtonIntoView();
109+
} else {
110+
const activeButton = this.getButtons().find((button) => button.value === value);
111+
112+
if (activeButton?.contentId) {
113+
this.segmentViewEl.setContent(activeButton.contentId);
114+
}
109115
}
110116
}
111117

packages/angular/src/directives/proxies.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2027,8 +2027,7 @@ export declare interface IonSegmentContent extends Components.IonSegmentContent
20272027

20282028

20292029
@ProxyCmp({
2030-
inputs: ['disabled'],
2031-
methods: ['setContent']
2030+
inputs: ['disabled']
20322031
})
20332032
@Component({
20342033
selector: 'ion-segment-view',

packages/angular/standalone/src/directives/proxies.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1865,8 +1865,7 @@ export declare interface IonSegmentContent extends Components.IonSegmentContent
18651865

18661866
@ProxyCmp({
18671867
defineCustomElementFn: defineIonSegmentView,
1868-
inputs: ['disabled'],
1869-
methods: ['setContent']
1868+
inputs: ['disabled']
18701869
})
18711870
@Component({
18721871
selector: 'ion-segment-view',

0 commit comments

Comments
 (0)