# ion-segment-button Segment buttons are groups of related buttons inside of a [Segment](../segment). They are displayed in a horizontal row. A segment button can be checked by default by adding the `checked` attribute or by setting the `value` of the segment to the `value` of the segment button. Only one segment button should be selected at a time. ## Usage ### Angular ```html Friends Enemies Paid Free Top Bookmarks Reading List Shared Links Item One Item Two Item Three Item One Item Two Item Three Item One Item Two Item Three Item One Item Two Item Three Item One Item Two Item Three ``` ```typescript import { Component } from '@angular/core'; @Component({ selector: 'segment-button-example', templateUrl: 'segment-button-example.html', styleUrls: ['./segment-button-example.css'], }) export class SegmentButtonExample { segmentButtonClicked(ev: any) { console.log('Segment button clicked', ev); } } ``` ### Javascript ```html Friends Enemies Paid Free Top Bookmarks Reading List Shared Links Item One Item Two Item Three Item One Item Two Item Three Item One Item Two Item Three Item One Item Two Item Three Item One Item Two Item Three ``` ```javascript // Listen for ionClick on all segment buttons const segmentButtons = document.querySelectorAll('ion-segment-button') for (let i = 0; i < segmentButtons.length; i++) { segmentButtons[i].addEventListener('ionSelect', (ev) => { console.log('Segment button clicked', ev); }) } ``` ### React ```tsx import React from 'react'; import { IonSegment, IonSegmentButton, IonLabel, IonIcon, IonContent } from '@ionic/react'; export const SegmentButtonExample: React.FC = () => ( {/*-- Segment buttons with text and click listeners --*/} console.log('Friends segment selected')}> Friends console.log('Enemies segment selected')}> Enemies {/*-- Segment buttons with the first checked and the last disabled --*/} Paid Free Top {/*-- Segment buttons with values and icons --*/} {/*-- Segment with a value that checks the last button --*/} Bookmarks Reading List Shared Links {/*-- Label only --*/} Item One Item Two Item Three {/*-- Icon only --*/} {/*-- Icon top --*/} Item One Item Two Item Three {/*-- Icon bottom --*/} Item One Item Two Item Three {/*-- Icon start --*/} Item One Item Two Item Three {/*-- Icon end --*/} Item One Item Two Item Three ); ``` ### Vue ```html ``` ## Properties | Property | Attribute | Description | Type | Default | | ---------- | ---------- | ------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------- | --------------------- | | `checked` | `checked` | If `true`, the segment button is selected. | `boolean` | `false` | | `disabled` | `disabled` | If `true`, the user cannot interact with the segment button. | `boolean` | `false` | | `layout` | `layout` | Set the layout of the text and icon in the segment. | `"icon-bottom" \| "icon-end" \| "icon-hide" \| "icon-start" \| "icon-top" \| "label-hide" \| undefined` | `'icon-top'` | | `mode` | `mode` | The mode determines which platform styles to use. | `"ios" \| "md"` | `undefined` | | `type` | `type` | The type of the button. | `"button" \| "reset" \| "submit"` | `'button'` | | `value` | `value` | The value of the segment button. | `string` | `'ion-sb-' + (ids++)` | ## Events | Event | Description | Type | | ----------- | ------------------------------------------- | ------------------- | | `ionSelect` | Emitted when the segment button is clicked. | `CustomEvent` | ## CSS Custom Properties | Name | Description | | --------------------------- | ----------------------------------------------------------------------------------------------------------------- | | `--background` | Background of the segment button | | `--background-activated` | Background of the segment button when pressed | | `--background-checked` | Background of the checked segment button | | `--background-hover` | Background of the segment button on hover | | `--border-color` | Color of the segment button border | | `--border-radius` | Radius of the segment button border | | `--border-style` | Style of the segment button border | | `--border-width` | Width of the segment button border | | `--color` | Color of the segment button | | `--color-activated` | Color of the segment button when pressed | | `--color-checked` | Color of the checked segment button | | `--color-checked-disabled` | Color of the checked & disabled segment button | | `--color-disabled` | Color of the disabled segment button | | `--indicator-color` | Color of the indicator (highlight) under the segment button | | `--indicator-color-checked` | Color of the indicator (highlight) under the checked segment button | | `--margin-bottom` | Bottom margin of the segment button | | `--margin-end` | Right margin if direction is left-to-right, and left margin if direction is right-to-left of the segment button | | `--margin-start` | Left margin if direction is left-to-right, and right margin if direction is right-to-left of the segment button | | `--margin-top` | Top margin of the segment button | | `--padding-bottom` | Bottom padding of the segment button | | `--padding-end` | Right padding if direction is left-to-right, and left padding if direction is right-to-left of the segment button | | `--padding-start` | Left padding if direction is left-to-right, and right padding if direction is right-to-left of the segment button | | `--padding-top` | Top padding of the segment button | | `--transition` | Transition of the segment button | ## Dependencies ### Depends on - [ion-ripple-effect](../ripple-effect) ### Graph ```mermaid graph TD; ion-segment-button --> ion-ripple-effect style ion-segment-button fill:#f9f,stroke:#333,stroke-width:4px ``` ---------------------------------------------- *Built with [StencilJS](https://stenciljs.com/)*