Skip to content

Commit 15e984e

Browse files
committed
Re-vamped the navbar docs to fix incorrect info about icon positioning and theming. Fixes jquery-archive#1858, Fixes jquery-archive#1797, Fixes jquery-archive#2667, Fixes jquery-archive#1180, Fixes jquery-archive#2373
The docs incorrectly stated that the icon position could be set per link, but this is intended as a global setting for the navbar parent. This is working as designed and helps with visual consistency. If icon positioning needs to be be adjusted per link, you will need to manually apply the right classes through JS and may need to tweak CSS because top/bottom and left/right positions have different heights.
1 parent e4834a8 commit 15e984e

File tree

1 file changed

+107
-33
lines changed

1 file changed

+107
-33
lines changed

docs/toolbars/docs-navbar.html

Lines changed: 107 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -24,47 +24,44 @@ <h1>Navbar</h1>
2424
<div class="content-primary">
2525
<h2>Simple navbar</h2>
2626

27-
<p>jQuery Mobile has a very basic navbar widget that is useful for providing up to 5 buttons with optional icons in a bar , typically within a header or footer. </p>
28-
27+
<p>jQuery Mobile has a very basic navbar widget that is useful for providing up to 5 buttons with optional icons in a bar, typically within a header or footer. There is also a <a href="footer-persist-a.html">persistent nav bar</a> variation that works more like a tab bar that stays fixed as you navigate across pages.</p>
2928
<p>A navbar is coded as an unordered list of links wrapped in a container element that has the <code> data-role="navbar"</code> attribute. To set one of links to the active (selected) state, add <code>class="ui-btn-active"</code> to the anchor. In this example, we have a two-button navbar in the footer with the "One" item set to active:</p>
3029

3130
<pre><code>
32-
&lt;div data-role=&quot;footer&quot;&gt;
33-
&lt;div data-role=&quot;navbar&quot;&gt;
34-
&lt;ul&gt;
35-
&lt;li&gt;&lt;a href=&quot;a.html&quot; class=&quot;ui-btn-active&quot;&gt;One&lt;/a&gt;&lt;/li&gt;
36-
&lt;li&gt;&lt;a href=&quot;b.html&quot;&gt;Two&lt;/a&gt;&lt;/li&gt;
37-
&lt;/ul&gt;
38-
&lt;/div&gt;&lt;!-- /navbar --&gt;
39-
&lt;/div&gt;&lt;!-- /footer --&gt;
31+
<strong>&lt;div data-role=&quot;navbar&quot;&gt;</strong>
32+
&lt;ul&gt;
33+
&lt;li&gt;&lt;a href=&quot;a.html&quot; class=&quot;ui-btn-active&quot;&gt;One&lt;/a&gt;&lt;/li&gt;
34+
&lt;li&gt;&lt;a href=&quot;b.html&quot;&gt;Two&lt;/a&gt;&lt;/li&gt;
35+
&lt;/ul&gt;
36+
<strong>&lt;/div&gt;&lt;!-- /navbar --&gt;</strong>
4037
</code></pre>
4138

4239
<p>The navbar items are set to divide the space evenly so in this case, each button is 1/2 the width of the browser window:</p>
4340

44-
<div data-role="footer">
41+
4542
<div data-role="navbar">
4643
<ul>
4744
<li><a href="#" class="ui-btn-active">One</a></li>
4845
<li><a href="#">Two</a></li>
4946
</ul>
5047
</div><!-- /navbar -->
51-
</div><!-- /footer -->
48+
5249

5350
<p>Adding a third item will automatically make each button 1/3 the width of the browser window:</p>
5451

55-
<div data-role="footer">
52+
5653
<div data-role="navbar">
5754
<ul>
5855
<li><a href="#" class="ui-btn-active">One</a></li>
5956
<li><a href="#">Two</a></li>
6057
<li><a href="#">Three</a></li>
6158
</ul>
6259
</div><!-- /navbar -->
63-
</div><!-- /footer -->
60+
6461

6562
<p>Adding a fourth more item will automatically make each button 1/4 the width of the browser window:</p>
6663

67-
<div data-role="footer">
64+
6865
<div data-role="navbar" data-grid="c">
6966
<ul>
7067
<li><a href="#" class="ui-btn-active">One</a></li>
@@ -73,11 +70,11 @@ <h2>Simple navbar</h2>
7370
<li><a href="#">Four</a></li>
7471
</ul>
7572
</div><!-- /navbar -->
76-
</div><!-- /footer -->
73+
7774

7875
<p>The navbar maxes out with 5 items, each 1/5 the width of the browser window:</p>
7976

80-
<div data-role="footer">
77+
8178
<div data-role="navbar" data-grid="d">
8279
<ul>
8380
<li><a href="#" class="ui-btn-active">One</a></li>
@@ -87,11 +84,10 @@ <h2>Simple navbar</h2>
8784
<li><a href="#">Five</a></li>
8885
</ul>
8986
</div><!-- /navbar -->
90-
</div><!-- /footer -->
87+
9188

9289
<p>If more than 5 items are added, the navbar will simply wrap to multiple lines:</p>
9390

94-
<div data-role="footer">
9591
<div data-role="navbar">
9692
<ul>
9793
<li><a href="#" class="ui-btn-active">One</a></li>
@@ -106,17 +102,14 @@ <h2>Simple navbar</h2>
106102
<li><a href="#">Ten</a></li>
107103
</ul>
108104
</div><!-- /navbar -->
109-
</div><!-- /footer -->
110105

111106
<p>As a fallback, navbars with 1 item will simply render as 100%.</p>
112107

113-
<div data-role="footer">
114108
<div data-role="navbar">
115109
<ul>
116110
<li><a href="#" class="ui-btn-active">One</a></li>
117111
</ul>
118112
</div><!-- /navbar -->
119-
</div><!-- /footer -->
120113

121114
<h2>Navbars in headers</h2>
122115

@@ -135,9 +128,33 @@ <h1>I'm a header</h1>
135128
</div><!-- /navbar -->
136129
</div><!-- /header -->
137130

131+
<h2>Navbars in footers</h2>
132+
133+
<p>If you want to add a navbar to the bottom of the page so it acts more like a tab bar, simply wrap the navbar in a container with a <code>data-role="footer"</code></p>
134+
<pre><code>
135+
&lt;div data-role=&quot;footer&quot;&gt;
136+
&lt;div data-role=&quot;navbar&quot;&gt;
137+
&lt;ul&gt;
138+
&lt;li&gt;&lt;a href=&quot;#&quot;&gt;One&lt;/a&gt;&lt;/li&gt;
139+
&lt;li&gt;&lt;a href=&quot;#&quot;&gt;Two&lt;/a&gt;&lt;/li&gt;
140+
&lt;li&gt;&lt;a href=&quot;#&quot;&gt;Three&lt;/a&gt;&lt;/li&gt;
141+
&lt;/ul&gt;
142+
&lt;/div&gt;&lt;!-- /navbar --&gt;
143+
&lt;/div&gt;&lt;!-- /footer --&gt;
144+
</code></pre>
145+
<div data-role="footer">
146+
<div data-role="navbar">
147+
<ul>
148+
<li><a href="#">One</a></li>
149+
<li><a href="#">Two</a></li>
150+
<li><a href="#">Three</a></li>
151+
</ul>
152+
</div><!-- /navbar -->
153+
</div><!-- /footer -->
154+
138155
<h2>Icons in navbars</h2>
139156

140-
<p>Icons can be added to navbar items by adding the <code> data-icon</code> attribute specifying a <a href="../buttons/buttons-icons.html">standard mobile icon</a> to each anchor.</p>
157+
<p>Icons can be added to navbar items by adding the <code> data-icon</code> attribute specifying a <a href="../buttons/buttons-icons.html">standard mobile icon</a> to each anchor. By default icons are added above the text (<code>data-iconpos="top"</code>). The following examples add icons to a navbar in a footer.</p>
141158

142159
<div data-role="footer">
143160
<div data-role="navbar">
@@ -149,14 +166,41 @@ <h2>Icons in navbars</h2>
149166
</div><!-- /navbar -->
150167
</div><!-- /footer -->
151168

152-
<p>Icons can be stacked above the labels by adding the <code> data-iconpos="top"</code> attribute to each anchor.</p>
169+
<p>The icon position is set <em>on the navbar container</em> instead of for individual links within for visual consistency. For example, to place the icons below the labels, add the <code> data-iconpos="bottom"</code> attribute to navbar container.</p>
170+
<pre><code>
171+
&lt;div data-role=&quot;navbar&quot; <strong>data-iconpos=&quot;bottom&quot;</strong>&gt;
172+
</code></pre>
173+
<p>This will result in a bottom icon alignment:</p>
174+
<div data-role="footer">
175+
<div data-role="navbar" data-iconpos="bottom">
176+
<ul>
177+
<li><a href="#" data-icon="grid">Summary</a></li>
178+
<li><a href="#" data-icon="star" class="ui-btn-active">Favs</a></li>
179+
<li><a href="#" data-icon="gear">Setup</a></li>
180+
</ul>
181+
</div><!-- /navbar -->
182+
</div><!-- /footer -->
183+
184+
<p>The icon position can be set to <code>data-iconpos="left"</code>:</p>
153185

154186
<div data-role="footer">
155-
<div data-role="navbar">
187+
<div data-role="navbar" data-iconpos="left">
156188
<ul>
157-
<li><a href="#" data-icon="grid" data-iconpos="top">Summary</a></li>
158-
<li><a href="#" data-icon="star" class="ui-btn-active" data-iconpos="top">Favs</a></li>
159-
<li><a href="#" data-icon="gear" data-iconpos="top">Setup</a></li>
189+
<li><a href="#" data-icon="grid">Summary</a></li>
190+
<li><a href="#" data-icon="star" class="ui-btn-active">Favs</a></li>
191+
<li><a href="#" data-icon="gear">Setup</a></li>
192+
</ul>
193+
</div><!-- /navbar -->
194+
</div><!-- /footer -->
195+
196+
<p>Or the icon position can be set to <code>data-iconpos="right"</code>:</p>
197+
198+
<div data-role="footer">
199+
<div data-role="navbar" data-iconpos="right">
200+
<ul>
201+
<li><a href="#" data-icon="grid">Summary</a></li>
202+
<li><a href="#" data-icon="star" class="ui-btn-active">Favs</a></li>
203+
<li><a href="#" data-icon="gear">Setup</a></li>
160204
</ul>
161205
</div><!-- /navbar -->
162206
</div><!-- /footer -->
@@ -194,14 +238,44 @@ <h2>Using 3rd party icon sets</h2>
194238

195239
<h2>Theming navbars</h2>
196240

197-
<p>Navbars can be set to any theme color by <code> data-theme</code> attribute to the links and specifying any theme swatch.</p>
241+
<p>Navbars inherit the theme swatch from their parent container, just like buttons. If a navbar is placed in header or footer toolbar, it will inherit the default toolbar swatch (A) for bars unless you set this in the markup. </p>
242+
<p>Here are a few examples of navbars in various container swatches automatically inheriting their parent's swatch letter. Note that in these examples, instead of using a <code>data-theme</code> attribute, we're manually adding the swatch classes to apply the body swatch (<code>ui-body-a</code>) and the class to add the standard body padding (ui-body), but the inheritance works the same way:</p>
198243

244+
<div class="ui-body-a ui-body">
245+
<h3>Swatch A</h3>
246+
<div data-role="navbar">
247+
<ul>
248+
<li><a href="#" data-icon="grid">A</a></li>
249+
<li><a href="#" data-icon="star">B</a></li>
250+
<li><a href="#" data-icon="gear">C</a></li>
251+
<li><a href="#" data-icon="arrow-l">D</a></li>
252+
<li><a href="#" data-icon="arrow-r">E</a></li>
253+
</ul>
254+
</div><!-- /navbar -->
255+
</div><!-- /container -->
256+
257+
<div class="ui-body-d ui-body">
258+
<h3>Swatch B</h3>
259+
<div data-role="navbar">
260+
<ul>
261+
<li><a href="#" data-icon="grid">A</a></li>
262+
<li><a href="#" data-icon="star">B</a></li>
263+
<li><a href="#" data-icon="gear">C</a></li>
264+
<li><a href="#" data-icon="arrow-l">D</a></li>
265+
<li><a href="#" data-icon="arrow-r">E</a></li>
266+
</ul>
267+
</div><!-- /navbar -->
268+
</div><!-- /container -->
269+
270+
<p>To set to the theme color for a navbar item, add the <code>data-theme</code> attribute to the individual links and specify a theme swatch. Note that applying a theme swatch at the navbar container is <em>not</em> supported.</p>
199271
<div data-role="footer">
200-
<div data-role="navbar" data-theme="e" >
272+
<div data-role="navbar">
201273
<ul>
202-
<li><a href="#" data-icon="grid" data-iconpos="top" data-theme="b">Summary</a></li>
203-
<li><a href="#" data-icon="star" class="ui-btn-active" data-iconpos="top" data-theme="b">Favs</a></li>
204-
<li><a href="#" data-icon="gear" data-iconpos="top" data-theme="b">Setup</a></li>
274+
<li><a href="#" data-icon="grid"data-theme="a">A</a></li>
275+
<li><a href="#" data-icon="star" data-theme="b">B</a></li>
276+
<li><a href="#" data-icon="gear" data-theme="c">C</a></li>
277+
<li><a href="#" data-icon="arrow-l" data-theme="d">D</a></li>
278+
<li><a href="#" data-icon="arrow-r" data-theme="e">E</a></li>
205279
</ul>
206280
</div><!-- /navbar -->
207281
</div><!-- /footer -->

0 commit comments

Comments
 (0)