You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit 4ee2e5e
Browse filesBrowse the repository at this point in the historyBrowse files
You can use the `accordion` component to render JavaScript accordion. The `accordion` component requires an array or Collection of items. The content for each item can be passed as named slots with the slot names same as the key of the item in kebab case. If you want to add html content to the item header, you can use the `{item-slot-name}-header` slot to provide the content for that item's header.
6
+
The `accordion` component groups content into collapsible panels. It supports Bootstrap 5 and Material Admin 2.6 and can render items from an array or Collection, or from components in its default slot.
7
7
8
+
## Basic Usage
8
9
9
-
```bladehtml
10
+
Provide a unique `id` for the accordion and pass an array or Collection to `items`.
The first panel starts open because its `show` value is `true`. Panels default to closed; the component does not automatically open the first item.
31
+
32
+
Opening and closing panels requires the Bootstrap collapse JavaScript used by your theme. Load it in your application layout; the component generates the markup without loading JavaScript itself.
33
+
34
+
### Item Options
35
+
36
+
Each entry in `items` accepts these keys:
37
+
38
+
| Key | Default | Description |
39
+
| --- | --- | --- |
40
+
|`title`|`''`| Header text. A header slot takes precedence. No title is generated from the item key. |
41
+
|`content`|`''`| Body text. A body slot takes precedence. HTML is escaped and line breaks are converted to `<br>` tags. |
42
+
|`show`|`false`| Whether the panel is initially expanded. |
43
+
|`id`| Not set | Optional ID for the item wrapper, separate from the collapsible panel's ID. |
44
+
45
+
### Panel IDs
46
+
47
+
For named items, the array key becomes the panel ID, with spaces replaced by hyphens. In the example above, the panels have IDs `applicationRequirements` and `applicationStatus`.
48
+
49
+
For numeric keys, the panel ID is `{accordion-id}-item-{key}-collapse`. For example, key `0` inside `application-faq` produces `application-faq-item-0-collapse`.
50
+
51
+
Keep panel IDs unique across the page. Named keys are not prefixed with the accordion ID, so use different keys when rendering multiple accordions. Setting an item's `id` changes its wrapper ID, not its panel ID.
21
52
22
-
<x-slot:collapse-one>
23
-
<strong>First item Body</strong>
24
-
</x-slot:collapse-one>
53
+
## Custom Headers and Content
54
+
55
+
Use named slots when headers or bodies need HTML. For a named item, use its key in kebab case for the body slot and append `-header` for the header slot. For example, `applicationRequirements` uses `application-requirements` and `application-requirements-header`.
Without passing an items array, you can manually create accordion items using the `accordion.item` component as well.
108
+
## Creating Items Manually
109
+
110
+
Omit `items` and place `accordion.item` components in the default slot. Each item requires a `name` for its panel ID and a `parent` matching the accordion ID, without a leading `#`.
content="Sign in to view your application status."
132
+
:show="false"
133
+
/>
134
+
</x-forms::accordion>
135
+
```
136
+
137
+
The item's `header` slot takes precedence over `title`. For a manually created item, a non-empty `content` attribute takes precedence over the default body slot. Use the default slot for HTML and leave `content` empty.
138
+
139
+
The accordion's default slot is rendered after any generated items, so you can also combine an `items` array with manually created items.
140
+
141
+
### Accordion Options
142
+
143
+
| Attribute | Type | Default | Description |
144
+
| --- | --- | --- | --- |
145
+
|`id`|`string`|**Required**| ID of the outer accordion and the parent used by generated panels. |
146
+
|`items`|`array` or `Collection`|`[]`| Items to render. Omit when creating items in the default slot. |
147
+
|`framework`|`string`|`''`| Uses `forms.framework` when omitted. Supports `bootstrap-5` and `material-admin-26`. |
148
+
149
+
### Accordion Item Options
150
+
151
+
| Attribute | Type | Default | Description |
152
+
| --- | --- | --- | --- |
153
+
|`name`|`string`|**Required**| ID of the collapsible panel, also used as the header's target. |
154
+
|`parent`|`string`|**Required**| ID of the parent accordion, without `#`. |
155
+
|`title`|`string`|`''`| Header text when no non-empty `header` slot is provided. |
156
+
|`content`|`string`|`''`| Body text, escaped with line breaks preserved. When non-empty, overrides the default slot. |
157
+
|`show`|`bool`|`false`| Sets the initial expanded state of both the header and panel. |
158
+
|`framework`|`string`|`''`| Uses `forms.framework` when omitted. |
159
+
160
+
## Separate Header and Collapse Components
161
+
162
+
For a custom item layout, use `accordion.header` and `accordion.collapse` directly. Match the header's `target` to the collapse element's `id`, and use the same `show` value on both.
The `accordion.item` component supports the following attributes.
78
-
-`name` - (Required) Name of the item. This will be used for the collpase id.
79
-
-`parent` - (Required) CSS id of the parent accordion.
80
-
-`title` - Title for the item. Title can be passed through the `header` slot as well if HTML content is needed in the title.
81
-
-`content` - Content for the item. Content can be passed through the main slot as well if HTML content is needed.
82
-
-`show` - Whether to have the item open or not
83
-
-`framework` - Which css framework to use.
178
+
This example uses Bootstrap 5's item wrapper class. For Material Admin 2.6, use `accordion__item` on the wrapper.
179
+
180
+
### Header Options
181
+
182
+
| Attribute | Type | Default | Description |
183
+
| --- | --- | --- | --- |
184
+
|`target`|`string`|**Required**| ID of the panel to toggle, without `#`. |
185
+
|`title`|`string`|`''`| Header text when the default slot is empty. |
186
+
|`show`|`bool`|`false`| Initial `aria-expanded` state. Match the panel's `show` value. |
187
+
|`framework`|`string`|`''`| Uses `forms.framework` when omitted. |
188
+
189
+
### Collapse Options
190
+
191
+
| Attribute | Type | Default | Description |
192
+
| --- | --- | --- | --- |
193
+
|`parent`|`string`|**Required**| ID of the parent accordion, without `#`. |
194
+
|`content`|`string`|`''`| Body text, escaped with line breaks preserved. When non-empty, overrides the default slot. |
195
+
|`show`|`bool`|`false`| Adds the `show` class to initially expand the panel. |
196
+
|`framework`|`string`|`''`| Uses `forms.framework` when omitted. |
197
+
198
+
Set the collapse element's `id` as an HTML attribute; the collapse component does not generate one itself.
199
+
200
+
## Frameworks and HTML Attributes
201
+
202
+
Generated items inherit the accordion's `framework`. When creating items or separate header and collapse components manually, pass the same `framework` to each if you are overriding the configured default.
203
+
204
+
Bootstrap 5 uses `data-bs-toggle`, `data-bs-target`, and `data-bs-parent` for collapse behavior. Material Admin 2.6 uses `data-toggle`, `data-target`, and `data-parent`. Load the matching theme styles and JavaScript.
205
+
206
+
Additional HTML attributes are passed to the outer element of each component. Classes are merged with the component's default classes.
0 commit comments