File tree Expand file tree Collapse file tree 3 files changed +43
-2
lines changed Expand file tree Collapse file tree 3 files changed +43
-2
lines changed Original file line number Diff line number Diff line change @@ -2723,6 +2723,11 @@ export namespace Components {
27232723 * If `true`, the segment view cannot be interacted with.
27242724 */
27252725 "disabled" : boolean ;
2726+ /**
2727+ * 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.
2728+ * @param id : The id of the segment content to display.
2729+ * @param smoothScroll : Whether to animate the scroll transition.
2730+ */
27262731 "setContent" : ( id : string , smoothScroll ?: boolean ) => Promise < void > ;
27272732 }
27282733 interface IonSelect {
Original file line number Diff line number Diff line change @@ -36,6 +36,13 @@ export class SegmentView implements ComponentInterface {
3636 }
3737 }
3838
39+ /**
40+ * This method is used to programmatically set the displayed segment content
41+ * in the segment view. Calling this method will update the `value` of the
42+ * corresponding segment button.
43+ * @param id: The id of the segment content to display.
44+ * @param smoothScroll: Whether to animate the scroll transition.
45+ */
3946 @Method ( )
4047 async setContent ( id : string , smoothScroll = true ) {
4148 const contents = this . getSegmentContents ( ) ;
Original file line number Diff line number Diff line change 4848
4949 < ion-content >
5050 < ion-toolbar >
51- < ion-segment >
51+ < ion-segment id =" noValueSegment " >
5252 < ion-segment-button content-id ="no " value ="no ">
5353 < ion-label > No</ ion-label >
5454 </ ion-segment-button >
5757 </ ion-segment-button >
5858 </ ion-segment >
5959 </ ion-toolbar >
60- < ion-segment-view >
60+ < ion-segment-view id =" noValueSegmentView " >
6161 < ion-segment-content id ="no "> No</ ion-segment-content >
6262 < ion-segment-content id ="value "> Value</ ion-segment-content >
6363 </ ion-segment-view >
7676 < ion-segment-content id ="favorites "> Favorites</ ion-segment-content >
7777 </ ion-segment-view >
7878
79+ < ion-toolbar >
7980 < ion-segment value ="free ">
8081 < ion-segment-button content-id ="paid " value ="paid ">
8182 < ion-label > Paid</ ion-label >
112113 < ion-segment-content id ="reading-list "> Reading List</ ion-segment-content >
113114 < ion-segment-content id ="shared-links "> Shared Links</ ion-segment-content >
114115 </ ion-segment-view >
116+
117+ < button class ="expand " onClick ="changeSegmentContent() ">
118+ Change Segment Content
119+ </ button >
120+
121+ < button class ="expand " onClick ="clearSegmentValue() ">
122+ Clear Segment Value
123+ </ button >
115124 </ ion-content >
116125
117126 < ion-footer >
118127 < ion-toolbar >
119128 < ion-title > Footer</ ion-title >
120129 </ ion-toolbar >
121130 </ ion-footer >
131+
132+ < script >
133+ let currentValue ;
134+
135+ function changeSegmentContent ( ) {
136+ const segmentView = document . querySelector ( '#noValueSegmentView' ) ;
137+
138+ if ( currentValue === 'value' ) {
139+ currentValue = 'no' ;
140+ } else {
141+ currentValue = 'value' ;
142+ }
143+ segmentView . setContent ( currentValue ) ;
144+ }
145+
146+ function clearSegmentValue ( ) {
147+ const segment = document . querySelector ( '#noValueSegment' ) ;
148+ segment . value = undefined ;
149+ }
150+ </ script >
122151 </ ion-app >
123152 </ body >
124153</ html >
You can’t perform that action at this time.
0 commit comments