Skip to content
This repository was archived by the owner on Nov 19, 2024. It is now read-only.

Commit e00f469

Browse files
authored
Merge pull request #8679 from volodymyrDashuk/add-example-dropdown-widget
magento/devdocs#: added example of using dropdown widget
2 parents f2f286a + ba55bda commit e00f469

File tree

3 files changed

+30
-1
lines changed

3 files changed

+30
-1
lines changed
-35.1 KB
Binary file not shown.
48.4 KB
Loading

src/guides/v2.3/javascript-dev-guide/widgets/widget_dropdown.md

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,8 @@ Because the dropdown widget is not formatted by default, use [LESS mixin `.lib-d
9797
}
9898
```
9999

100+
If there is a need to customize the button and arrow, the [Magento UI Library](https://magento-devdocs.github.io/magento2-ui-library/dropdowns.html) provides the ability to do this with ready-made Less mixins.
101+
100102
[LESS mixin `.lib-dropdown()`]: {{ site.mage2bloburl }}/{{ page.guide_version }}/lib/web/css/source/lib/_dropdowns.less
101103

102104
## Initialize the dropdown widget {#dropdown_init}
@@ -175,8 +177,35 @@ Given class is added to the widget element when the menu is visible.
175177

176178
**Default value**: `active`
177179

180+
## Code sample
181+
182+
The following example shows how to initialize the dropdown widget.
183+
184+
```html
185+
<div class="customer-welcome">
186+
<button
187+
data-mage-init='{"dropdown":{}}'
188+
data-toggle="dropdown"
189+
class="action"
190+
data-action="customer-menu-toggle">
191+
<span><?= $block->escapeHtml(__('Dropdown open button')) ?></span>
192+
</button>
193+
<ul data-target="dropdown" class="dropdown-options">
194+
<li>
195+
<span class="item"><?= $block->escapeHtml(__('Item 1')) ?></span>
196+
</li>
197+
<li>
198+
<span class="item"><a href="#"><?= $block->escapeHtml(__('Item 2 with link')) ?></a></span>
199+
</li>
200+
<li>
201+
<span class="item"><?= $block->escapeHtml(__('Item 3')) ?></span>
202+
</li>
203+
</ul>
204+
</div>
205+
```
206+
178207
## Result
179208

180209
The result is a custom select dropdown with custom content as options.
181210

182-
![Dropdown Widget]({{ site.baseurl }}/common/images/widget/dropdown-widget-result.jpg)
211+
![Dropdown Widget]({{ site.baseurl }}/common/images/widget/dropdown-widget-result.png)

0 commit comments

Comments
 (0)