Skip to content

Latest commit

 

History

History
123 lines (76 loc) · 4.18 KB

File metadata and controls

123 lines (76 loc) · 4.18 KB
title ion-segment

import Props from '@ionic-internal/component-api/v6/segment/props.md'; import Events from '@ionic-internal/component-api/v6/segment/events.md'; import Methods from '@ionic-internal/component-api/v6/segment/methods.md'; import Parts from '@ionic-internal/component-api/v6/segment/parts.md'; import CustomProps from '@ionic-internal/component-api/v6/segment/custom-props.mdx'; import Slots from '@ionic-internal/component-api/v6/segment/slots.md';

<title>ion-segment: API Documentation for Segmented Controls</title>

import EncapsulationPill from '@components/page/api/EncapsulationPill';

Segments display a group of related buttons, sometimes known as segmented controls, in a horizontal row. They can be displayed inside of a toolbar or the main content.

Their functionality is similar to tabs, where selecting one will deselect all others. Segments are useful for toggling between different views inside of the content. Tabs should be used instead of a segment when clicking on a control should navigate between pages.

Basic Usage

Segments consist of segment buttons with a value property on each button. Set the value property on the segment to match the value of a button to select that button. Segments can also be disabled to prevent users from interacting with them.

import Basic from '@site/static/usage/v6/segment/basic/index.md';

Scrollable Segments

Segments are not scrollable by default. Each segment button has a fixed width, and the width is determined by dividing the number of segment buttons by the screen width. This ensures that each segment button can be displayed on the screen without having to scroll. As a result, some segment buttons with longer labels may get cut off. To avoid this we recommend either using a shorter label or switching to a scrollable segment by setting the scrollable property to true. This will cause the segment to scroll horizontally, but will allow each segment button to have a variable width.

import Scrollable from '@site/static/usage/v6/segment/scrollable/index.md';

Segments in Toolbars

import Toolbar from '@site/static/usage/v6/toolbar/segments/index.md';

Theming

Colors

import Colors from '@site/static/usage/v6/segment/theming/colors/index.md';

CSS Custom Properties

import CSSProps from '@site/static/usage/v6/segment/theming/css-properties/index.md';

Accessibility

Keyboard Navigation

The component has full keyboard support for navigating between and selecting ion-segment-button elements. By default, keyboard navigation will only focus ion-segment-button elements, but you can use the selectOnFocus property to ensure that they get selected on focus as well. The following table details what each key does:

Key Function
ArrowRight Focuses the next focusable element.
ArrowLeft Focuses the previous focusable element.
Home Focuses the first focusable element.
End Focuses the last focusable element.
Space or Enter Selects the element that is currently focused.

Interfaces

SegmentChangeEventDetail

interface SegmentChangeEventDetail {
  value?: string;
}

SegmentCustomEvent

While not required, this interface can be used in place of the CustomEvent interface for stronger typing with Ionic events emitted from this component.

interface SegmentCustomEvent extends CustomEvent {
  target: HTMLIonSegmentElement;
  detail: SegmentChangeEventDetail;
}

Properties

Events

Methods

CSS Shadow Parts

CSS Custom Properties

Slots