docs(segment-view): document setContent method and add example

This commit is contained in:
Brandy Carney
2024-09-23 16:18:37 -04:00
parent e6f76d53a9
commit 9103c403b2
3 changed files with 43 additions and 2 deletions

View File

@@ -2723,6 +2723,11 @@ export namespace Components {
* If `true`, the segment view cannot be interacted with.
*/
"disabled": boolean;
/**
* 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.
* @param id : The id of the segment content to display.
* @param smoothScroll : Whether to animate the scroll transition.
*/
"setContent": (id: string, smoothScroll?: boolean) => Promise<void>;
}
interface IonSelect {

View File

@@ -36,6 +36,13 @@ export class SegmentView implements ComponentInterface {
}
}
/**
* 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.
* @param id: The id of the segment content to display.
* @param smoothScroll: Whether to animate the scroll transition.
*/
@Method()
async setContent(id: string, smoothScroll = true) {
const contents = this.getSegmentContents();

View File

@@ -48,7 +48,7 @@
<ion-content>
<ion-toolbar>
<ion-segment>
<ion-segment id="noValueSegment">
<ion-segment-button content-id="no" value="no">
<ion-label>No</ion-label>
</ion-segment-button>
@@ -57,7 +57,7 @@
</ion-segment-button>
</ion-segment>
</ion-toolbar>
<ion-segment-view>
<ion-segment-view id="noValueSegmentView">
<ion-segment-content id="no">No</ion-segment-content>
<ion-segment-content id="value">Value</ion-segment-content>
</ion-segment-view>
@@ -76,6 +76,7 @@
<ion-segment-content id="favorites">Favorites</ion-segment-content>
</ion-segment-view>
<ion-toolbar>
<ion-segment value="free">
<ion-segment-button content-id="paid" value="paid">
<ion-label>Paid</ion-label>
@@ -112,6 +113,14 @@
<ion-segment-content id="reading-list">Reading List</ion-segment-content>
<ion-segment-content id="shared-links">Shared Links</ion-segment-content>
</ion-segment-view>
<button class="expand" onClick="changeSegmentContent()">
Change Segment Content
</button>
<button class="expand" onClick="clearSegmentValue()">
Clear Segment Value
</button>
</ion-content>
<ion-footer>
@@ -119,6 +128,26 @@
<ion-title>Footer</ion-title>
</ion-toolbar>
</ion-footer>
<script>
let currentValue;
function changeSegmentContent() {
const segmentView = document.querySelector('#noValueSegmentView');
if (currentValue === 'value') {
currentValue = 'no';
} else {
currentValue = 'value';
}
segmentView.setContent(currentValue);
}
function clearSegmentValue() {
const segment = document.querySelector('#noValueSegment');
segment.value = undefined;
}
</script>
</ion-app>
</body>
</html>