Skip to content

Commit 6fc11b8

Browse files
author
Gabriel Schulhof
committed
Selectmenu: Document generated IDs
Fixes gh-359 Closes gh-360
1 parent adfcec2 commit 6fc11b8

File tree

1 file changed

+80
-13
lines changed

1 file changed

+80
-13
lines changed

entries/selectmenu.xml

Lines changed: 80 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
<p>This will produce a basic select menu. The default styles set the width of the input to 100% of the parent container and stacks the label on a separate line.
2424
<iframe src="/resources/select/example1.html" style="width:100%;height:190px;border:0px"></iframe></p>
2525

26-
<h3>Mini version</h3>
26+
<h2 id="mini-version">Mini version</h2>
2727

2828
<p>For a more compact version that is useful in toolbars and tight spaces, add the <code>data-mini="true"</code> attribute to the element to create a mini version. </p>
2929

@@ -40,7 +40,7 @@
4040
<p>This will produce a select that a not as tall as the standard version and has a smaller text size.
4141
<iframe src="/resources/select/example2.html" style="width:100%;height:190px;border:0px"></iframe></p>
4242

43-
<h3>Field containers</h3>
43+
<h2 id="field-containers">Field containers</h2>
4444

4545
<p>Optionally wrap the selects in a container with class <code>ui-field-contain</code> to help visually group it in a longer form.</p>
4646
<div class="warning">
@@ -65,7 +65,7 @@
6565
<p>An example of a select with a long list of options:
6666
<iframe src="/resources/select/example4.html" style="width:100%;height:590px;border:0px"></iframe></p>
6767

68-
<h3>Optgroups</h3>
68+
<h2 id="optgroups">Optgroups</h2>
6969
<p>The following example organizes the options into <code>optgroup</code> elements. Support for this feature in mobile selects is a bit spotty, but is improving.</p>
7070

7171
<pre><code><![CDATA[
@@ -94,7 +94,7 @@
9494

9595
<iframe src="/resources/select/example5.html" style="width:100%;height:390px;border:0px"></iframe>
9696

97-
<h3>Vertically grouped select inputs</h3>
97+
<h2 id="vertically-grouped-select-inputs">Vertically grouped select inputs</h2>
9898

9999
<p>To create a grouped set of select inputs, first add <code>select</code> and a corresponding <code>label</code>. Set the <code>for</code> attribute of the <code>label</code> to match the <code>id</code> of the <code>select</code> so they are semantically associated.</p>
100100

@@ -133,7 +133,7 @@
133133

134134
<iframe src="/resources/select/example6.html" style="width:100%;height:390px;border:0px"></iframe>
135135

136-
<h3>Horizontally grouped select inputs</h3>
136+
<h2 id="horizontally-grouped-select-inputs">Horizontally grouped select inputs</h2>
137137
<p>Select inputs can also be used for grouped sets with more than one related selections. To make a horizontal button set, add the <code>data-type="horizontal"</code> to the fieldset. Note that the buttons which trigger the select will resize depending on the currently selected option’s value.</p>
138138

139139
<pre><code><![CDATA[
@@ -142,13 +142,13 @@
142142

143143
<iframe src="/resources/select/example7.html" style="width:100%;height:190px;border:0px"></iframe>
144144

145-
<h3>Theming selects</h3>
145+
<h2 id="theming-selects">Theming selects</h2>
146146

147147
<p>You can specify any jQuery Mobile button <code>data-</code> attribute on a select element, too. In this example, we're setting the theme, icon and inline properties:
148148
<iframe src="/resources/select/example8.html" style="width:100%;height:190px;border:0px"></iframe>
149149
</p>
150150

151-
<h2>Custom select menus</h2>
151+
<h2 id="custom-select-menus">Custom select menus</h2>
152152
<p>The framework is capable of building a custom menu based on the <code>select</code> element's list of options. We recommend using a custom menu when multiple selections are required, or when the menu itself must be styled with CSS.</p>
153153

154154
<p>You can optionally use custom-styled select menus instead of the native OS menu. The custom menu supports disabled options and multiple selection (whereas native mobile OS support for both is inconsistent), adds an elegant way to handle placeholder values, and restores missing functionality on certain platforms such as <code>optgroup</code> support on Android (all explained below). In addition, the framework applies the custom button's theme to the menu to better match the look and feel and provide visual consistency across platforms. Lastly, custom menus often look better on desktop browsers because native desktop menus are smaller than their mobile counterparts and tend to look disproportionate.</p>
@@ -170,13 +170,13 @@ $(document).on( "mobileinit", function() {
170170
<iframe src="/resources/select/example10.html" style="width:100%;height:590px;border:0px"></iframe></p>
171171
<p class="warning"><strong>Note:</strong> The behavior whereby the custom select menu creates a new page when the list of options is long is deprecated as of jQuery Mobile 1.4.0. Starting with 1.5.0, the custom select menu will fall back to utilizing the select menu's native behavior when the list of options is too long.</p>
172172

173-
<h3>Disabled options</h3>
173+
<h2 id="disabled-options">Disabled options</h2>
174174

175175
<p>jQuery Mobile will automatically disable and style option tags with the <code>disabled</code> attribute. In the demo below, the second option &quot;Rush: 3 days&quot; has been set to disabled.
176176

177177
<iframe src="/resources/select/example11.html" style="width:100%;height:270px;border:0px"></iframe></p>
178178

179-
<h3>Placeholder options</h3>
179+
<h2 id="placeholder-options">Placeholder options</h2>
180180
<p>It's common for developers to include a &quot;null&quot; option in their select element to force a user to choose an option. If a placeholder option is present in your markup, jQuery Mobile will hide them in the overlay menu, showing only valid choices to the user, and display the placeholder text inside the menu as a header. A placeholder option is added when the framework finds:</p>
181181
<ul>
182182
<li>An option with no value attribute</li>
@@ -194,7 +194,7 @@ $.mobile.selectmenu.prototype.options.hidePlaceholderMenuItems = false;
194194
<p>Examples of various placeholder options:
195195
<iframe src="/resources/select/example12.html" style="width:100%;height:390px;border:0px"></iframe></p>
196196

197-
<h3>Multiple selects</h3>
197+
<h2 id="multiple-selects">Multiple selects</h2>
198198

199199
<p>If the <code>multiple</code> attribute is present in your markup, jQuery Mobile will enhance the element with a few extra considerations:</p>
200200

@@ -215,12 +215,12 @@ $.mobile.selectmenu.prototype.options.hidePlaceholderMenuItems = false;
215215

216216
<iframe src="/resources/select/example14.html" style="width:100%;height:590px;border:0px"></iframe></p>
217217

218-
<h3>Optgroup support</h3>
218+
<h2 id="optgroup-support">Optgroup support</h2>
219219

220220
<p>If a select menu contains <code>optgroup</code> elements, jQuery Mobile will create a divider &amp; group items based on the <code>label</code> attribute's text:
221221
<iframe src="/resources/select/example15.html" style="width:100%;height:500px;border:0px"></iframe></p>
222222

223-
<h3>Theming selects</h3>
223+
<h2 id="theming-selects">Theming selects</h2>
224224

225225
<p>You can specify any jQuery Mobile button <code>data-</code> attribute on a select element, too. In this example, we're setting the theme, icon and inline properties:
226226
<iframe src="/resources/select/example16.html" style="width:100%;height:310px;border:0px"></iframe></p>
@@ -230,12 +230,79 @@ $.mobile.selectmenu.prototype.options.hidePlaceholderMenuItems = false;
230230
<iframe src="/resources/select/example17.html" style="width:100%;height:290px;border:0px"></iframe></p>
231231
<p><iframe src="/resources/select/example18.html" style="width:100%;height:590px;border:0px"></iframe></p>
232232

233-
<h3>Calling the select menu plugin</h3>
233+
<h2 id="calling-the-select-menu-plugin">Calling the select menu plugin</h2>
234234

235235
<p>The select menu plugin will auto initialize on any page that contains a select menu, without any need for a <code>data-role</code> attribute in the markup. However, you can directly call the select menu plugin on any selector, just like any normal jQuery plugin:</p>
236236

237237
<pre><code><![CDATA[
238238
$( "select" ).selectmenu();
239+
]]></code></pre>
240+
241+
<h2 id="id-generation">ID generation</h2>
242+
243+
<p>The <placeholder name="name"/> widget adds an ID to the elements it generates. If it doesn't itself have an ID, it will use a prefix consisting of <code>select-</code> and a unique number for the elements. If it does have an ID, it will use its ID as the prefix. The ID for the various elements generated by the <placeholder name="name"/> widget is then constructed as follows:</p>
244+
<dl>
245+
<dt>button</dt>
246+
<dd>
247+
<code><strong><![CDATA[<prefix>]]></strong><![CDATA[-button]]></code>
248+
</dd>
249+
<dt>popup</dt>
250+
<dd>
251+
<code><strong><![CDATA[<prefix>]]></strong><![CDATA[-listbox]]></code>
252+
<p>This id is only assigned to an element when the <placeholder name="name"/> widget is constructed with the option <code>nativeMenu</code> set to <code>false</code>.</p>
253+
<p>Since the menu is implemented as a popup it will assign IDs to its generated elements. See the popup widget's <a href="/popup/#id-generation">id generation</a> for details.</p>
254+
</dd>
255+
<dt>listview</dt>
256+
<dd>
257+
<code><strong><![CDATA[<prefix>]]></strong><![CDATA[-menu]]></code>
258+
<p>This id is only assigned to an element when the <placeholder name="name"/> widget is constructed with the option <code>nativeMenu</code> set to <code>false</code>.</p>
259+
</dd>
260+
</dl>
261+
<p>For example, creating a non-native <placeholder name="name"/> with</p>
262+
<pre><code><![CDATA[
263+
<select id="choose-city" data-native-menu="false">
264+
<option>Caracas</option>
265+
<option>Warszawa</option>
266+
<option>Yekaterinburg</option>
267+
<option>Pretoria</option>
268+
</select>
269+
]]></code></pre>
270+
<p>will result in the following markup:</p>
271+
<pre><code><![CDATA[
272+
<div class="ui-select">
273+
<a id="choose-city-button" href="#" role="button" aria-haspopup="true" class="ui-btn ui-icon-carat-d ui-btn-icon-right ui-corner-all ui-shadow" data-rel="popup">
274+
<span>Caracas</span>
275+
</a>
276+
<select id="choose-city" data-native-menu="false" tabindex="-1">
277+
<option>Caracas</option>
278+
<option>Warszawa</option>
279+
<option>Yekaterinburg</option>
280+
<option>Pretoria</option>
281+
</select>
282+
<div id="choose-city-listbox-placeholder" style="display: hidden;"></div>
283+
</div>
284+
<div id="choose-city-listbox-screen" class="ui-popup-screen ui-screen-hidden ui-overlay-inherit"></div>
285+
<div id="choose-city-listbox-popup" class="ui-popup-container ui-popup-hidden ui-popup-truncate">
286+
<div id="choose-city-listbox" class="ui-selectmenu ui-popup ui-body-inherit ui-overlay-shadow ui-corner-all">
287+
<div class="ui-header" ui-bar-inherit ui-screen-hidden">
288+
<h1 class="ui-title"></h1>
289+
</div>
290+
<ul id="choose-city-menu" class="ui-selectmenu-list ui-listview" role="listbox" aria-labelledby="choose-city-button">
291+
<li data-option-index="0" data-icon="false" class="ui-first-child" role="option" aria-selected="true">
292+
<a href="#" tabindex="-1" class="ui-btn ui-btn-active">Caracas</a>
293+
</li>
294+
<li data-option-index="0" data-icon="false" role="option" aria-selected="false">
295+
<a href="#" tabindex="-1" class="ui-btn ui-btn-active">Warszawa</a>
296+
</li>
297+
<li data-option-index="0" data-icon="false" role="option" aria-selected="false">
298+
<a href="#" tabindex="-1" class="ui-btn ui-btn-active">Yekaterinburg</a>
299+
</li>
300+
<li data-option-index="0" data-icon="false" class="ui-last-child" role="option" aria-selected="false">
301+
<a href="#" tabindex="-1" class="ui-btn ui-btn-active">Pretoria</a>
302+
</li>
303+
</ul>
304+
</div>
305+
</div>
239306
]]></code></pre>
240307

241308
</longdesc>

0 commit comments

Comments
 (0)