<ons-segment />

Segment component. Use this component to have a button bar with automatic styles that switch on click of another button. Will automatically display as a Material Design segment on Android.

Tutorial

Segment

The <Segment> component allows you to have a nice button bar with only one active button at a time.

It may be useful for example for filtering lists or especially for connecting to <Tabbar>. See the next page to find out how to do it.

Connecting to <Tabbar>

Sometimes you may want a segment instead of the normal tabs in your tabbar.

You can connect <Segment> and <Tabbar> by providing the ID of the <Tabbar> you want to control as the tabbarId prop of <Segment>.

This way the tabbar will be automatically hidden and the active button of <Segment> will always be in sync with the active tab of <Tabbar>.

See also

Name Type Description
modifier String The appearance of the segment. Optional.
tabbar-id String ID of the tabbar element to “connect” to the segment. Must be inside the same page. Optional. Works only during initialization.
active-index Number
0
Index of the active button. If a tabbar is connected, this will be set to the tabbar’s active index. Optional.
disabled Specify if segment should be disabled. Optional.
Name Description
activeIndex Index of the active button. If a tabbar is connected, this will be set to the tabbar’s active index.
disabled Whether the segment is disabled or not.
Name Description
material Material Design segment
Signature Description
setActiveButton(index, [options]) Make button with the specified index active. If there is a connected tabbar it shows the corresponding tab page. In this case animations and their options can be specified by the second parameter.
getActiveButtonIndex() Returns button index of current active button. If active button is not found, returns -1.
setActiveButton(index, [options]): Promise

Make button with the specified index active. If there is a connected tabbar it shows the corresponding tab page. In this case animations and their options can be specified by the second parameter.

Returns: Resolves to the selected index or to the new page element if there is a connected tabbar.

Parameters
Name Type Description
index Number Button index.
options Object Parameter object, works only if there is a connected tabbar. Supports the same options as ons-tabbar‘s setActiveTab method.
getActiveButtonIndex(): Number

Returns button index of current active button. If active button is not found, returns -1.

Returns: The index of the currently active button.

Name Description
postchange Fires after the active button is changed.
postchange

Fires after the active button is changed.

Parameters
Name Type Description
event Object Event object.
event.index Number Tapped button index.
event.segmentItem Object Segment item object.

Need Help?

If you have any questions, use our Community Forum or talk to us on Discord chat. The Onsen UI team and your peers in the community will work together to help solve your issues.

For bug reports and feature requests use our GitHub Issues page.