Toolbelt components provide their own set of directives. There are modifiers to adjust the behavior of each component. Custom events are emitted. Data attributes are set on the elements. All this functionality is to allow your Javascript and CSS to work with Toolbelt components. Each component page documents these features.
Initialize component: Alpine runs directives only if an x-init (or x-data) is included.
Include Toolbelt directives: The accordion component includes a family of directives that depend on each other. There is always top-level root directive, usually followed by one or more children directives depending on the complexity of the component.
Add modifiers, if needed: Certain directives’ behaviors can be modified. These are the dot notated parameters that follow directives. In this example, this accordion can only open a single item at a time, loops keyboard navigation, and opens the first item by default.
Styling to State
Data attributes are used to track any relevant state of each element. In the case of accordions, each item tracks whether it is open or closed.
You can style each element with the data attributes. Here’s a simple example:
Listening to Events
Custom events are emitted when state changes. To avoid potential conflicts with built-in events, Toolbelt namespaces the custom events based on the components. In the accordion, for example, the accordion:change event is emitted whenever an item is opened or closed. The detail property of the event should include additional information if appropriate.