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

Commit ce27fda

Browse files
author
Vasilii Burlacu
committed
Add new docs page about Dropdown Widget
1 parent 6e12e46 commit ce27fda

File tree

6 files changed

+209
-0
lines changed

6 files changed

+209
-0
lines changed

_data/toc/javascript-developer-guide.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,9 @@ pages:
5555
- label: Confirmation widget
5656
url: /javascript-dev-guide/widgets/widget_confirm.html
5757

58+
- label: Dropdown widget
59+
url: /javascript-dev-guide/widgets/widget_dropdown.html
60+
5861
- label: DropdownDialog widget
5962
url: /javascript-dev-guide/widgets/widget_dialog.html
6063

Loading

guides/v2.1/javascript-dev-guide/widgets/jquery-widgets-about.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ This guide discusses the following widgets:
1414
- [Calendar widget]
1515
- [Collapsible widget]
1616
- [Confirm widget]
17+
- [Dropdown widget]
1718
- [DropdownDialog widget]
1819
- [Gallery widget]
1920
- [List widget]
@@ -36,6 +37,7 @@ Magento out of the box does not contain jQuery UI styles. Also, it is not recomm
3637
[Calendar widget]: {{page.baseurl}}/javascript-dev-guide/widgets/widget_calendar.html
3738
[Collapsible widget]: {{page.baseurl}}/javascript-dev-guide/widgets/widget_collapsible.html
3839
[Confirm widget]: {{page.baseurl}}/javascript-dev-guide/widgets/widget_confirm.html
40+
[Dropdown widget]: {{page.baseurl}}/javascript-dev-guide/widgets/widget_dropdown.html
3941
[DropdownDialog widget]: {{page.baseurl}}/javascript-dev-guide/widgets/widget_dialog.html
4042
[Gallery widget]: {{page.baseurl}}/javascript-dev-guide/widgets/widget_gallery.html
4143
[List widget]: {{page.baseurl}}/javascript-dev-guide/widgets/widget_list.html
Lines changed: 202 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,202 @@
1+
---
2+
group: javascript-developer-guide
3+
subgroup: 3_Widgets
4+
title: Dropdown widget
5+
functional_areas: frontend,theme,dropdown
6+
---
7+
8+
## Overview
9+
10+
Widget source file is [lib/web/mage/dropdowns.js].
11+
12+
The dropdown widget allows to show show on storefront a select box with custom
13+
content for each of available options.
14+
15+
{:.bs-callout .bs-callout-info} Dropdown widget is not meant to replace default
16+
HTML select element. By replacing default select in store forms don't expect
17+
the store to work 100% the same as before changes.
18+
19+
20+
**Usages:**
21+
- [Shipping policy]
22+
- [Customer menu]
23+
- [UI Tooltip]
24+
25+
[lib/web/mage/dropdowns.js]: {{ site.mage2bloburl }}/{{ page.guide_version }}/lib/web/mage/dropdowns.js
26+
[Shipping policy]: {{ site.mage2bloburl }}/{{ page.guide_version }}/app/code/Magento/Shipping/view/frontend/web/template/checkout/shipping/shipping-policy.html
27+
[Customer menu]: {{ site.mage2bloburl }}/{{ page.guide_version }}/app/code/Magento/Customer/view/frontend/templates/account/customer.phtml
28+
[UI Tooltip]: {{ site.mage2bloburl }}/{{ page.guide_version }}/app/code/Magento/Ui/view/frontend/web/templates/form/element/helper/tooltip.html
29+
30+
### HTML markup
31+
32+
```html
33+
<div class="magento__dropdown-widget">
34+
<span class="action toggle" data-toggle="dropdown" aria-haspopup="true">
35+
<span>Dropdown Opener Button</span>
36+
</span>
37+
<ul class="dropdown-options" data-target="dropdown">
38+
<li>
39+
<span class="item">Dropdown Item One</span>
40+
</li>
41+
<li>
42+
<span class="item"><a href="#">Dropdown Item Two, With Link</a></span>
43+
</li>
44+
<li>
45+
<span class="item">Dropdown Item Three</span>
46+
</li>
47+
</ul>
48+
</div>
49+
```
50+
51+
### Styles
52+
53+
By default the dropdown is not styled. But, there is a handy
54+
[LESS mixin `.lib-dropdown()`] that comes to the rescue:
55+
56+
```less
57+
//
58+
// Simple dropdown
59+
// ---------------------------------------------
60+
61+
.lib-dropdown(
62+
@_toggle-selector : ~".action.toggle",
63+
@_options-selector : ~"ul.dropdown",
64+
65+
@_dropdown-actions-padding: @dropdown-actions__padding,
66+
@_dropdown-list-min-width: @dropdown-list__min-width,
67+
@_dropdown-list-width: @dropdown-list__width,
68+
@_dropdown-list-height: @dropdown-list__height,
69+
@_dropdown-list-margin-top: @dropdown-list__margin-top,
70+
@_dropdown-list-position-top: @dropdown-list__position-top,
71+
@_dropdown-list-position-bottom: @dropdown-list__position-bottom,
72+
@_dropdown-list-position-left: @dropdown-list__position-left,
73+
@_dropdown-list-position-right: @dropdown-list__position-right,
74+
@_dropdown-list-background: @dropdown-list__background,
75+
@_dropdown-list-border: @dropdown-list__border,
76+
@_dropdown-list-pointer: @dropdown-list__pointer,
77+
@_dropdown-list-pointer-border: @dropdown-list-pointer__border,
78+
@_dropdown-list-pointer-position: @dropdown-list-pointer__position,
79+
@_dropdown-list-pointer-position-top: @dropdown-list-pointer__position-top,
80+
@_dropdown-list-pointer-position-left-right: @dropdown-list-pointer__position-left-right,
81+
@_dropdown-list-item-border: @dropdown-list-item__border,
82+
@_dropdown-list-item-padding: @dropdown-list-item__padding,
83+
@_dropdown-list-item-margin: @dropdown-list-item__margin,
84+
@_dropdown-list-item-hover: @dropdown-list-item__hover,
85+
@_dropdown-list-shadow: @dropdown-list__shadow,
86+
@_dropdown-list-z-index: @dropdown-list__z-index,
87+
88+
@_dropdown-toggle-icon-content: @dropdown-toggle-icon__content,
89+
@_dropdown-toggle-active-icon-content: @dropdown-toggle-icon__active__content,
90+
91+
@_icon-font: @dropdown-toggle-icon__font,
92+
@_icon-font-size: @dropdown-toggle-icon__font-size,
93+
@_icon-font-line-height: @dropdown-toggle-icon__font-line-height,
94+
@_icon-font-color: @dropdown-toggle-icon__font-color,
95+
@_icon-font-color-hover: @dropdown-toggle-icon__font-color-hover,
96+
@_icon-font-color-active: @dropdown-toggle-icon__font-color-active,
97+
@_icon-font-margin: @dropdown-toggle-icon__font-margin,
98+
@_icon-font-position: @dropdown-toggle-icon__position,
99+
@_icon-font-vertical-align: @dropdown-toggle-icon__font-vertical-align,
100+
@_icon-font-text-hide: @dropdown-toggle-icon__text-hide
101+
) {
102+
// ...
103+
}
104+
```
105+
106+
[LESS mixin `.lib-dropdown()`]: {{ site.mage2bloburl }}/{{ page.guide_version }}/lib/web/css/source/lib/_dropdowns.less
107+
108+
## Initialize the dropdown widget {#dropdown_init}
109+
110+
The loader widget is initialized as described in [JavaScript initialization].
111+
112+
### Initialize with `data-mage-init` attribute
113+
114+
```html
115+
<div class="magento__dropdown-widget">
116+
<span class="action toggle"
117+
data-toggle="dropdown"
118+
aria-haspopup="true"
119+
data-mage-init='{"dropdown":{}}'>
120+
<span>Dropdown Opener Button</span>
121+
</span>
122+
<ul class="dropdown-options" data-target="dropdown" />
123+
</div>
124+
```
125+
126+
### Initialize in `.js` file with options
127+
128+
```js
129+
$('.magento__dropdown-widget').dropdown();
130+
```
131+
132+
## Options {#dropdown_options}
133+
134+
- [parent](#d_parent)
135+
- [autoclose](#d_autoclose)
136+
- [btnArrow](#d_btnArrow)
137+
- [menu](#d_menu)
138+
- [activeClass](#d_activeClass)
139+
140+
Description of each option as follows below location.
141+
142+
### `parent` {#d_parent}
143+
144+
The parent of element on which the widget was initialized. If not specified,
145+
the widget finds it himself with jQuery method `.parent()`.
146+
147+
**Type**:
148+
149+
- jQuery object
150+
- HTML
151+
- String
152+
153+
**Default value**: `null`
154+
155+
156+
### `autoclose` {#d_autoclose}
157+
158+
Whenever to close or not the dropdown menu when mouse is clicked outside of dropdown scope.
159+
160+
**Type**: Boolean
161+
162+
**Default value**: `true`
163+
164+
165+
### `btnArrow` {#d_btnArrow}
166+
167+
A jQuery selector for the arrow that expresses the state of the dropdown.
168+
The widget changes given element's text to '+' or '-", depending on the dropdown state.
169+
It's not required the element to be present into the dropdown HTML markup. It works
170+
just fine without it as well.
171+
172+
**Type**: String
173+
174+
**Default value**: `.arrow`
175+
176+
177+
### `menu` {#d_menu}
178+
179+
A jQuery selector that represents the dropdown's menu element.
180+
Looking at the HTML markup, given element has to be inside the `parent` option.
181+
182+
**Type**: String
183+
184+
**Default value**: `[data-target="dropdown"]`
185+
186+
187+
### `activeClass` {#d_activeClass}
188+
189+
The CSS class that reflects the current state of the dropdown widget.
190+
Given class is added to the element widget was initialized when the dropdown
191+
menu should be visible.
192+
193+
**Type**: String
194+
195+
**Default value**: `active`
196+
197+
198+
## Result
199+
200+
The result is a custom select dropdown with custom content as options.
201+
202+
![Dropdown Widget]({{ page.baseurl }}/javascript-dev-guide/widgets/images/dropdown-widget-result.png)
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../../../v2.1/javascript-dev-guide/widgets/widget_dropdown.md
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../../../v2.1/javascript-dev-guide/widgets/widget_dropdown.md

0 commit comments

Comments
 (0)