-
Notifications
You must be signed in to change notification settings - Fork 74
Expand file tree
/
Copy pathselectmenu.xml
More file actions
329 lines (313 loc) · 14.6 KB
/
selectmenu.xml
File metadata and controls
329 lines (313 loc) · 14.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
<?xml version="1.0"?>
<entry name="selectmenu" type="widget">
<title>Selectmenu Widget</title>
<desc>Duplicates and extends the functionality of a native HTML select element to overcome the limitations of the native control.</desc>
<longdesc>
<p>Selectmenu transforms a <code><select></code> element into a themeable and customizable control. The widget acts as a proxy to the original <code><select></code>; therefore the original element's state is maintained for form submission and serialization.</p>
<p>Selectmenu supports <code><optgroup></code> elements and custom markup to render specific presentations like multiple lines. The <code><select></code> and its options can be disabled by adding a <code>disabled</code> attribute.</p>
<div class="warning"><p>
<strong>Note:</strong> Support for <code>accesskey</code> on custom elements is extremely limited in browsers. As such, if there is an <code>accesskey</code> attribute on the <code><select></code> element, it will not work with the custom selectmenu. If there is an <code>accesskey</code> attribute on any of the <code><option></code> elements, using the accesskey may cause the original element and the custom element to be out of sync. However, most browsers don't support <code>accesskey</code> on <code><option></code> elements.
</p></div>
<h3>Keyboard interaction</h3>
<p>When the menu is open, the following key commands are available:</p>
<ul>
<li><code>UP</code>/<code>LEFT</code>: Move focus to the previous item.</li>
<li><code>DOWN</code>/<code>RIGHT</code>: Move focus to the next item.</li>
<li><code>END</code>/<code>PAGE DOWN</code>: Move focus to the last item.</li>
<li><code>HOME</code>/<code>PAGE UP</code>: Move focus to the first item.</li>
<li><code>ESCAPE</code>: Close the menu.</li>
<li><code>ENTER</code>/<code>SPACE</code>: Select the currently focused item and close the menu.</li>
<li><code>ALT</code>/<code>OPTION</code> + <code>UP</code>/<code>DOWN</code>: Toggle the visibility of the menu.</li>
</ul>
<p>When the menu is closed, the following key commands are available:</p>
<ul>
<li><code>UP</code>/<code>LEFT</code>: Select the previous item.</li>
<li><code>DOWN</code>/<code>RIGHT</code>: Select the next item.</li>
<li><code>END</code>/<code>PAGE DOWN</code>: Select the last item.</li>
<li><code>HOME</code>/<code>PAGE UP</code>: Select the first item.</li>
<li><code>ALT</code>/<code>OPTION</code> + <code>UP</code>/<code>DOWN</code>: Toggle the visibility of the menu.</li>
<li><code>SPACE</code>: Open the menu.</li>
</ul>
<xi:include href="../includes/widget-theming.xml" xmlns:xi="http://www.w3.org/2003/XInclude"/>
<ul>
<li>
<code>ui-selectmenu-button</code>: The button-like element replacing the native selectmenu on the page. Has the <code>ui-selectmenu-button-closed</code> class when closed, the <code>ui-selectmenu-button-open</code> class when open.
<ul>
<li><code>ui-selectmenu-text</code>: The span representing the text portion of the button element.</li>
<li><code>ui-selectmenu-icon</code>: The icon within the selectmenu button.</li>
</ul>
</li>
<li>
<code>ui-selectmenu-menu</code>: The wrapper element around the <a href="/menu/#theming">menu</a> used to display options to the user (not the menu itself). When the menu is open, the <code>ui-selectmenu-open</code> class is added.
<ul>
<li><code>ui-selectmenu-optgroup</code>: One of the elements that replicates <code><optgroup></code> elements from native selects.</li>
</ul>
</li>
</ul>
<h3>Dependencies</h3>
<ul>
<li><a href="/category/ui-core/">UI Core</a></li>
<li><a href="/jQuery.widget/">Widget Factory</a></li>
<li><a href="/position/">Position</a></li>
<li><a href="/menu/">Menu</a></li>
</ul>
</longdesc>
<note id="functional-css"/>
<added>1.11</added>
<options>
<option name="appendTo" type="Selector" default="null" example-value='"#someElem"'>
<desc>Which element to append the menu to. When the value is <code>null</code>, the parents of the <code><select></code> are checked for a class name of <code>ui-front</code>. If an element with the <code>ui-front</code> class name is found, the menu is appended to that element. Regardless of the value, if no element is found, the menu is appended to the body.</desc>
</option>
<option name="classes" type="Object">
<default>{
"ui-selectmenu-button-closed": "ui-corner-all",
"ui-selectmenu-button-open": "ui-corner-top",
}</default>
<xi:include href="../includes/classes-option-desc.xml" xmlns:xi="http://www.w3.org/2003/XInclude"/>
<examples>
<example>
<desc>Initialize the <placeholder name="name"/> with the <code>classes</code> option specified, changing the theming for the <code>ui-selectmenu-menu</code> class:</desc>
<code>
$( ".selector" ).<placeholder name="name"/>({
classes: {
"ui-selectmenu-menu": "highlight"
}
});
</code>
</example>
<example>
<desc>Get or set a property of the <code>classes</code> option, after initialization, here reading and changing the theming for the <code>ui-selectmenu-menu</code> class:</desc>
<code>
// Getter
var themeClass = $( ".selector" ).<placeholder name="name"/>( "option", "classes.ui-selectmenu-menu" );
// Setter
$( ".selector" ).<placeholder name="name"/>( "option", "classes.ui-selectmenu-menu", "highlight" );
</code>
</example>
</examples>
</option>
<xi:include href="../includes/widget-option-disabled.xml" xmlns:xi="http://www.w3.org/2003/XInclude"/>
<option name="icons" type="Object" default='{ button: "ui-icon-triangle-1-s" }' example-value='{ button: "ui-icon-circle-triangle-s" }'>
<desc>
Icons to use for the button, matching <a href="/theming/icons/">an icon defined by the jQuery UI CSS Framework</a>.
<ul>
<li>button (string, default: "ui-icon-triangle-1-s")</li>
</ul>
</desc>
</option>
<option name="position" type="Object" default='{ my: "left top", at: "left bottom", collision: "none" }' example-value='{ my : "left+10 center", at: "right center" }'>
<desc>Identifies the position of the menu in relation to the associated button element. You can refer to the <a href="/position/">jQuery UI Position</a> utility for more details about the various options.</desc>
</option>
<option name="width" default="false" example-value="200">
<desc>The width of the menu, in pixels. When the value is <code>null</code>, the width of the native select is used. When the value is <code>false</code>, no inline style will be set for the width, allowing the width to be set in a stylesheet.</desc>
<type name="Number" />
<type name="Boolean" />
</option>
</options>
<events>
<event name="change">
<desc>Triggered when the selected item has changed. Not every <a href="#event-select"><code>select</code></a> event will fire a <code>change</code> event.</desc>
<argument name="event" type="Event"/>
<argument name="ui" type="Object">
<property name="item" type="jQuery">
<desc>The active item.</desc>
</property>
</argument>
</event>
<event name="close">
<desc>Triggered when the menu is hidden.</desc>
<argument name="event" type="Event"/>
</event>
<xi:include href="../includes/widget-event-create.xml" xmlns:xi="http://www.w3.org/2003/XInclude"/>
<event name="focus">
<desc>
Triggered when an items gains focus.
</desc>
<argument name="event" type="Event"/>
<argument name="ui" type="Object">
<property name="item" type="jQuery">
<desc>The focused item.</desc>
</property>
</argument>
</event>
<event name="open">
<desc>Triggered when the menu is opened.</desc>
<argument name="event" type="Event"/>
</event>
<event name="select">
<desc>
Triggered when a menu item is selected.
</desc>
<argument name="event" type="Event"/>
<argument name="ui" type="Object">
<property name="item" type="jQuery">
<desc>The selected item.</desc>
</property>
</argument>
</event>
</events>
<methods>
<method name="close">
<desc>Closes the menu.</desc>
</method>
<xi:include href="../includes/widget-method-destroy.xml" xmlns:xi="http://www.w3.org/2003/XInclude"/>
<xi:include href="../includes/widget-method-disable.xml" xmlns:xi="http://www.w3.org/2003/XInclude"/>
<xi:include href="../includes/widget-method-enable.xml" xmlns:xi="http://www.w3.org/2003/XInclude"/>
<xi:include href="../includes/widget-method-instance.xml" xmlns:xi="http://www.w3.org/2003/XInclude"/>
<method name="menuWidget">
<desc>Returns a <code>jQuery</code> object containing the menu element.</desc>
</method>
<method name="open">
<desc>Opens the menu.</desc>
</method>
<xi:include href="../includes/widget-method-option.xml" xmlns:xi="http://www.w3.org/2003/XInclude"/>
<method name="refresh">
<desc>
Parses the original element and re-renders the menu. Processes any <code><option></code> or <code><optgroup></code> elements that were added, removed or disabled.
</desc>
</method>
<method name="widget">
<desc>Returns a <code>jQuery</code> object containing the button element.</desc>
</method>
</methods>
<extension-points>
<method name="_renderItem" return="jQuery">
<desc>
<p>Method that controls the creation of each option in the widget's menu. The method must create a new <code><li></code> element, append it to the menu, and return it. See the <a href="/menu/">Menu</a> documentation for more details about the markup.</p>
</desc>
<argument name="ul" type="jQuery">
<desc>The <code><ul></code> element that the newly created <code><li></code> element must be appended to.</desc>
</argument>
<argument name="item" type="Object">
<property name="element" type="jQuery">
<desc>The original <code><option></code> element.</desc>
</property>
<property name="index" type="Integer">
<desc>The index of the <code><option></code> within the <code><select></code>.</desc>
</property>
<property name="value" type="String">
<desc>The value of the <code><option></code>.</desc>
</property>
<property name="label" type="String">
<desc>The label of the <code><option></code>.</desc>
</property>
<property name="optgroup" type="String">
<desc>The label for the parent <code>optgroup</code>, if any.</desc>
</property>
<property name="disabled" type="Boolean">
<desc>Whether the <code><option></code> is disabled.</desc>
</property>
</argument>
<example>
<desc>Style the menu item background colors based on the value of their corresponding option elements.</desc>
<code><![CDATA[
_renderItem: function( ul, item ) {
var li = $( "<li>" )
.css( "background-color", item.value );
if ( item.disabled ) {
li.addClass( "ui-state-disabled" );
}
this._setText( li, item.label );
return li.appendTo( ul );
}
]]></code>
</example>
</method>
<method name="_renderMenu">
<desc>
Method that controls building the widget's menu. The method is passed an empty <code><ul></code> and an array of items based on the <code><option></code> elements in the original <code><select></code>. Creation of the individual <code><li></code> elements should be delegated to <code>_renderItemData()</code>, which in turn delegates to the <a href="#method-_renderItem"><code>_renderItem()</code></a> extension point.
</desc>
<argument name="ul" type="jQuery">
<desc>An empty <code><ul></code> element to use as the widget's menu.</desc>
</argument>
<argument name="items" type="Array">
<desc>An array of items based on the <code><option></code> elements in the original <code><select></code>. See the <a href="#method-_renderItem"><code>_renderItem()</code></a> extension point for details on the format of the item objects.</desc>
</argument>
<example>
<desc>
<p>Add a CSS class name to the odd menu items.</p>
<div class="warning"><strong>Note:</strong> For simplicity, this example does not support optgroups or disabled menu items.</div>
</desc>
<code><![CDATA[
_renderMenu: function( ul, items ) {
var that = this;
$.each( items, function( index, item ) {
that._renderItemData( ul, item );
});
$( ul ).find( "li:odd" ).addClass( "odd" );
}
]]></code>
</example>
</method>
<method name="_resizeMenu">
<desc>Method responsible for sizing the menu before it is displayed. The menu element is available at <code>this.menu</code>.</desc>
<example>
<desc>Always display the menu as 500 pixels wide.</desc>
<code><![CDATA[
_resizeMenu: function() {
this.menu.outerWidth( 500 );
}
]]></code>
</example>
</method>
<method name="_renderButtonItem" return="jQuery">
<desc>
<p>Method that controls the creation of the generated button content. The method must create and return a new element.</p>
</desc>
<argument name="item" type="Object">
<property name="disabled" type="Boolean">
<desc>Whether the item is disabled.</desc>
</property>
<property name="element" type="jQuery">
<desc>A reference to the item's original <code><option></code> element.</desc>
</property>
<property name="index" type="Number">
<desc>The numeric index of the item.</desc>
</property>
<property name="label" type="String">
<desc>The string to display for the item.</desc>
</property>
<property name="optgroup" type="String">
<desc>If the item is within an <code><optgroup></code>, this is set to that <code><optgroup></code>'s label.</desc>
</property>
<property name="value" type="String">
<desc>The <code>value</code> attribute of the item's original <code><option></code>.</desc>
</property>
</argument>
<example>
<desc>Style the button background color based on the value of the selected option.</desc>
<code><![CDATA[
_renderButtonItem: function( item ) {
var buttonItem = $( "<span>", {
"class": "ui-selectmenu-text"
})
this._setText( buttonItem, item.label );
buttonItem.css( "background-color", item.value )
return buttonItem;
}
]]></code>
</example>
</method>
</extension-points>
<example>
<desc>A simple jQuery UI Selectmenu</desc>
<code><![CDATA[
$( "#speed" ).selectmenu();
]]></code>
<html><![CDATA[
<label for="speed">Select a speed:</label>
<select name="speed" id="speed">
<option value="Slower">Slower</option>
<option value="Slow">Slow</option>
<option value="Medium" selected>Medium</option>
<option value="Fast">Fast</option>
<option value="Faster">Faster</option>
</select>
]]></html>
<css><![CDATA[
label { display: block; }
select { width: 200px; }
]]></css>
</example>
<category slug="widgets"/>
</entry>