Actions

Toggle Group

A named set of toggles where one option, or several, can be on.

Class nameTypeDescription
joinplf:joinComponentJoins the items into one control
join-itemplf:join-itemPartA joined Toggle
join-verticalplf:join-verticalDirectionStacks the items

Name the group with aria-label or aria-labelledby, give each item a unique value, and leave data-plf-toggle off the items; otherwise the group gets no behavior.

Filter a list

The script shows the projects whose data-status matches the pressed item, and all of them when none is pressed.

  • Website redesign

    Due March 14

    Active
  • Mobile app

    Due April 2

    Active
  • Brand guidelines

    Finished January 20

    Archived

JavaScript

Toggle Group needs JavaScript to change the selection. The Full script (pelatform-ui.min.js) starts every component on page load, with no code of your own; with ESM imports, call init() yourself, as in Installation. For markup you add later, see Dynamic content.

<link rel="stylesheet" href="pelatform-ui.min.css">
<link rel="stylesheet" href="icons/icons.min.css">
<script src="pelatform-ui.min.js" defer></script>
<link rel="stylesheet" href="pelatform-ui.prefixed.min.css">
<link rel="stylesheet" href="icons/icons.prefixed.min.css">
<script src="pelatform-ui.min.js" defer></script>
Attribute Purpose
data-plf-toggle-group On the named role="group" element: empty for one item at a time, or multiple
value Each item’s unique value
aria-pressed An item’s state: "true" starts pressed, one item at most without multiple; the script adds "false" to the others
disabled An item that cannot be pressed or released
Method Behavior
PLF.ToggleGroup.getOrCreateInstance(group) Returns the instance, creating it for valid markup
PLF.ToggleGroup.getInstance(group) Returns the instance or null
instance.getValue() Returns the pressed values as an array, in item order
instance.setValue(values) Sets the selection from an array of values; returns false for unknown values, more than one in a single group, no change, a disabled item or cancellation
instance.toggle(value) Presses or releases one item; in a single group, the other item is released. Returns like setValue
instance.destroy() Removes the listener; items keep their state
Event When
plf:toggle-group:before-change Before the selection changes; cancelable
plf:toggle-group:change After the items’ aria-pressed is updated

Each event’s detail:

Property Value
instance The Toggle Group instance
reason api or trigger
trigger The clicked item, or null from a method
previousValue The pressed values before, as an array
value The new pressed values, as an array

Both fire on the group.

The group only changes its selection: apply it in your plf:toggle-group:change handler. It submits no form value.

Key Action
Tab, Shift+Tab Move between items
Enter, Space Presses or releases the focused item

React

ToggleGroup from @pelatform/react renders this group and gives its items their state: it keeps its own, or the application sets it with value.

Prop Values Default
type single, one item pressed at a time, or multiple single
value The pressed item’s value, or '' with none; with multiple, an array of values in item order. The application changes it in onValueChange Its own state
defaultValue The value pressed at first, written as value, when the application does not set value None pressed
onValueChange (value), called when a click presses or releases an item; keep value to stay as it is None
join true joins the items into one control (join) false
orientation horizontal, vertical (join-vertical), for a joined group horizontal
Part Element
ToggleGroupItem A Toggle, type="button", whose state is the group’s: Button’s classes from variant, size and shape, a unique value, and join-item in a joined group

The other props are the element’s own, className and ref included.

CSS variables

Items take Toggle’s and Button’s variables; a connected group takes Button Group’s.


Built with Pelatform UIv0.1.0

Components

Getting started

Foundations

Components

Actions

Data display

Navigation

Feedback

Data input

Layout

Advanced

Integrations

Blocks

Application

Authentication

Icons