Skip to content

Commit 4a20486

Browse files
authored
[dropdown] Add parent item type to allow submenus (#256)
1 parent 7644ca4 commit 4a20486

2 files changed

Lines changed: 42 additions & 0 deletions

File tree

docs/components-dropdown.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,13 @@ See Tabler documentation at https://preview.tabler.io/dropdowns.html
2828
| extraClass | Add custom class to the item | `string` | _empty string_ |
2929
| attr | Custom HTML attributes to add to the item | `Object` | `{}` |
3030

31+
##### Item type `parent`
32+
| Parameter | Description | Type | Default |
33+
|:---------:|-----------------------------------------------------------------------------------------|:------------------:|:---------:|
34+
| type | `parent` | `string` | `parent` |
35+
| autoClose | See [autoClose option](https://getbootstrap.com/docs/5.2/components/dropdowns/#options) | `boolean / string` | `outside` |
36+
| children | Array of the nested [items](#Item) | `array` | `[]` |
37+
3138
##### Item Options
3239
| Parameter | Description | Type | Default |
3340
|:---------------:|----------------------------------|:---------:|:--------------:|
@@ -132,6 +139,24 @@ See Tabler documentation at https://preview.tabler.io/dropdowns.html
132139
{
133140
type: 'divider',
134141
},
142+
{
143+
type: 'parent',
144+
title: 'Parent',
145+
children : [
146+
{
147+
title: 'Child 1',
148+
},
149+
{
150+
title: 'Child 2',
151+
},
152+
{
153+
title: 'Child 3',
154+
},
155+
],
156+
},
157+
{
158+
type: 'divider',
159+
},
135160
{
136161
title: 'Logout',
137162
icon: 'back',

templates/components/dropdown.html.twig

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,23 @@
5050
{{ _html | raw }}
5151
</div>
5252
{% endif %}
53+
{% elseif _type is same as 'parent' %}
54+
{% set _children = item.children ?? [] %}
55+
{% if item.autoClose is not defined %}
56+
{% set _autoClose = 'outside' %}
57+
{% elseif item.autoClose is same as true %}
58+
{% set _autoClose = 'true' %}
59+
{% elseif item.autoClose is same as false %}
60+
{% set _autoClose = 'false' %}
61+
{% else %}
62+
{% set _autoClose = item.autoClose %}
63+
{% endif %}
64+
<div class="dropend">
65+
<a class="dropdown-item dropdown-toggle" data-bs-toggle="dropdown" data-bs-auto-close="{{ _autoClose }}" role="button">
66+
{{ _title }}
67+
</a>
68+
{{ _self.dropdown(_children) }}
69+
</div>
5370
{% else %}
5471
{% set classes = 'dropdown-item ' ~ (_disabled ? 'disabled ' : '') ~ (_active ? 'active ' : '') ~ _extraClass %}
5572
{% if _type is same as 'link' %}

0 commit comments

Comments
 (0)