Skip to content

Commit 7d57d9a

Browse files
patrickhlaukealpadevmdo
authored
Dynamic tabs: use buttons rather than links (backport to v4) (#33163)
* Manually backport 32630 Dynamic tabs: use buttons rather than links * Tweak unit test * Tweak unit tests * More tweakage * show() should also bail if `disabled` attribute is set * Tweak tests * Simplify test for relatedTarget * Temporarily remove problematic test (as i can't get local tests to run just noww) * Revert previous * test: fix broken test cases for tab.js * test: fix role=tablist invalid on nav element * test: prefer <div/> over <div></div> * Manually backport 32630 Dynamic tabs: use buttons rather than links * test: fix broken test cases for tab.js * Fixes * Remove and ignore lock file Co-authored-by: alpadev <[email protected]> Co-authored-by: Mark Otto <[email protected]> Co-authored-by: Mark Otto <[email protected]>
1 parent e4dc2e9 commit 7d57d9a

File tree

6 files changed

+181
-184
lines changed

6 files changed

+181
-184
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
# Ignore docs files
22
/_site/
3-
# Hugo folders
3+
# Hugo files
44
/resources/
5+
/.hugo_build.lock
56

67
# Numerous always-ignore extensions
78
*.diff

js/src/tab.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,8 @@ class Tab {
5858
if (this._element.parentNode &&
5959
this._element.parentNode.nodeType === Node.ELEMENT_NODE &&
6060
$(this._element).hasClass(CLASS_NAME_ACTIVE) ||
61-
$(this._element).hasClass(CLASS_NAME_DISABLED)) {
61+
$(this._element).hasClass(CLASS_NAME_DISABLED) ||
62+
this._element.hasAttribute('disabled')) {
6263
return
6364
}
6465

js/tests/unit/tab.js

Lines changed: 102 additions & 109 deletions
Large diffs are not rendered by default.

js/tests/visual/tab.html

Lines changed: 27 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,16 @@ <h4>Tabs without fade</h4>
1919

2020
<ul class="nav nav-tabs" role="tablist">
2121
<li class="nav-item" role="presentation">
22-
<a class="nav-link active" data-toggle="tab" href="#home" role="tab">Home</a>
22+
<button type="button" class="nav-link active" data-toggle="tab" data-target="#home" role="tab" aria-selected="true">Home</button>
2323
</li>
2424
<li class="nav-item" role="presentation">
25-
<a class="nav-link" data-toggle="tab" href="#profile" role="tab">Profile</a>
25+
<button type="button" class="nav-link" data-toggle="tab" data-target="#profile" role="tab">Profile</button>
2626
</li>
2727
<li class="nav-item" role="presentation">
28-
<a class="nav-link" data-toggle="tab" href="#fat" role="tab">@fat</a>
28+
<button type="button" class="nav-link" data-toggle="tab" data-target="#fat" role="tab">@fat</button>
2929
</li>
3030
<li class="nav-item" role="presentation">
31-
<a class="nav-link" data-toggle="tab" href="#mdo" role="tab">@mdo</a>
31+
<button type="button" class="nav-link" data-toggle="tab" data-target="#mdo" role="tab">@mdo</button>
3232
</li>
3333
</ul>
3434

@@ -55,16 +55,16 @@ <h4>Tabs with fade</h4>
5555

5656
<ul class="nav nav-tabs" role="tablist">
5757
<li class="nav-item" role="presentation">
58-
<a class="nav-link active" data-toggle="tab" href="#home2" role="tab">Home</a>
58+
<button type="button" class="nav-link active" data-toggle="tab" data-target="#home2" role="tab" aria-selected="true">Home</button>
5959
</li>
6060
<li class="nav-item" role="presentation">
61-
<a class="nav-link" data-toggle="tab" href="#profile2" role="tab">Profile</a>
61+
<button type="button" class="nav-link" data-toggle="tab" data-target="#profile2" role="tab">Profile</button>
6262
</li>
6363
<li class="nav-item" role="presentation">
64-
<a class="nav-link" data-toggle="tab" href="#fat2" role="tab">@fat</a>
64+
<button type="button" class="nav-link" data-toggle="tab" data-target="#fat2" role="tab">@fat</button>
6565
</li>
6666
<li class="nav-item" role="presentation">
67-
<a class="nav-link" data-toggle="tab" href="#mdo2" role="tab">@mdo</a>
67+
<button type="button" class="nav-link" data-toggle="tab" data-target="#mdo2" role="tab">@mdo</button>
6868
</li>
6969
</ul>
7070

@@ -91,16 +91,16 @@ <h4>Tabs without fade (no initially active pane)</h4>
9191

9292
<ul class="nav nav-tabs" role="tablist">
9393
<li class="nav-item" role="presentation">
94-
<a class="nav-link" data-toggle="tab" href="#home3" role="tab">Home</a>
94+
<button type="button" class="nav-link" data-toggle="tab" data-target="#home3" role="tab">Home</button>
9595
</li>
9696
<li class="nav-item" role="presentation">
97-
<a class="nav-link" data-toggle="tab" href="#profile3" role="tab">Profile</a>
97+
<button type="button" class="nav-link" data-toggle="tab" data-target="#profile3" role="tab">Profile</button>
9898
</li>
9999
<li class="nav-item" role="presentation">
100-
<a class="nav-link" data-toggle="tab" href="#fat3" role="tab">@fat</a>
100+
<button type="button" class="nav-link" data-toggle="tab" data-target="#fat3" role="tab">@fat</button>
101101
</li>
102102
<li class="nav-item" role="presentation">
103-
<a class="nav-link" data-toggle="tab" href="#mdo3" role="tab">@mdo</a>
103+
<button type="button" class="nav-link" data-toggle="tab" data-target="#mdo3" role="tab">@mdo</button>
104104
</li>
105105
</ul>
106106

@@ -159,26 +159,23 @@ <h4>Tabs with fade (no initially active pane)</h4>
159159
</div>
160160
</div>
161161

162-
<h4>Tabs with nav (with fade)</h4>
163-
<nav class="nav nav-pills">
164-
<a class="nav-link nav-item active" data-toggle="tab" href="#home5">Home</a>
165-
<a class="nav-link nav-item" data-toggle="tab" href="#profile5">Profile</a>
166-
<div class="nav-item dropdown">
167-
<a class="nav-link dropdown-toggle" href="#" id="dropdown5" data-toggle="dropdown" aria-expanded="false">Dropdown</a>
168-
<div class="dropdown-menu" aria-labelledby="dropdown5">
169-
<a class="dropdown-item" data-toggle="tab" href="#fat5">@fat</a>
170-
<a class="dropdown-item" data-toggle="tab" href="#mdo5">@mdo</a>
171-
</div>
162+
<h4>Tabs with nav and using links (with fade)</h4>
163+
<nav>
164+
<div class="nav nav-pills" id="nav-tab" role="tablist">
165+
<a class="nav-link nav-item active" role="tab" data-toggle="tab" href="#home5">Home</a>
166+
<a class="nav-link nav-item" role="tab" data-toggle="tab" href="#profile5">Profile</a>
167+
<a class="nav-link nav-item" role="tab" data-toggle="tab" href="#fat5">@fat</a>
168+
<a class="nav-link nav-item" role="tab" data-toggle="tab" href="#mdo5">@mdo</a>
169+
<a class="nav-link nav-item disabled" role="tab" href="#">Disabled</a>
172170
</div>
173-
<a class="nav-link nav-item disabled" href="#">Disabled</a>
174171
</nav>
175172

176-
<div class="tab-content" role="tabpanel">
177-
<div role="tabpanel" class="tab-pane fade show active" id="home5">
173+
<div class="tab-content">
174+
<div class="tab-pane fade show active" id="home5" role="tabpanel">
178175
<p>Raw denim you probably haven't heard of them jean shorts Austin. Nesciunt tofu stumptown aliqua, retro synth master cleanse. Mustache cliche tempor, williamsburg carles vegan helvetica. Reprehenderit butcher retro keffiyeh dreamcatcher synth. Cosby sweater eu banh mi, qui irure terry richardson ex squid. Aliquip placeat salvia cillum iphone. Seitan aliquip quis cardigan american apparel, butcher voluptate nisi qui.</p>
179176
<p>Raw denim you probably haven't heard of them jean shorts Austin. Nesciunt tofu stumptown aliqua, retro synth master cleanse. Mustache cliche tempor, williamsburg carles vegan helvetica. Reprehenderit butcher retro keffiyeh dreamcatcher synth. Cosby sweater eu banh mi, qui irure terry richardson ex squid. Aliquip placeat salvia cillum iphone. Seitan aliquip quis cardigan american apparel, butcher voluptate nisi qui.</p>
180177
</div>
181-
<div role="tabpanel" class="tab-pane fade" id="profile5">
178+
<div class="tab-pane fade" id="profile5" role="tabpanel">
182179
<p>Raw denim you probably haven't heard of them jean shorts Austin. Nesciunt tofu stumptown aliqua, retro synth master cleanse. Mustache cliche tempor, williamsburg carles vegan helvetica. Reprehenderit butcher retro keffiyeh dreamcatcher synth. Cosby sweater eu banh mi, qui irure terry richardson ex squid. Aliquip placeat salvia cillum iphone. Seitan aliquip quis cardigan american apparel, butcher voluptate nisi qui.</p>
183180
<p>Raw denim you probably haven't heard of them jean shorts Austin. Nesciunt tofu stumptown aliqua, retro synth master cleanse. Mustache cliche tempor, williamsburg carles vegan helvetica. Reprehenderit butcher retro keffiyeh dreamcatcher synth. Cosby sweater eu banh mi, qui irure terry richardson ex squid. Aliquip placeat salvia cillum iphone. Seitan aliquip quis cardigan american apparel, butcher voluptate nisi qui.</p>
184181
</div>
@@ -196,10 +193,10 @@ <h4>Tabs with list-group (with fade)</h4>
196193
<div class="row">
197194
<div class="col-4">
198195
<div class="list-group" id="list-tab" role="tablist">
199-
<a class="list-group-item list-group-item-action active" id="list-home-list" data-toggle="tab" href="#list-home" role="tab" aria-controls="list-home">Home</a>
200-
<a class="list-group-item list-group-item-action" id="list-profile-list" data-toggle="tab" href="#list-profile" role="tab" aria-controls="list-profile">Profile</a>
201-
<a class="list-group-item list-group-item-action" id="list-messages-list" data-toggle="tab" href="#list-messages" role="tab" aria-controls="list-messages">Messages</a>
202-
<a class="list-group-item list-group-item-action" id="list-settings-list" data-toggle="tab" href="#list-settings" role="tab" aria-controls="list-settings">Settings</a>
196+
<button type="button" class="list-group-item list-group-item-action active" id="list-home-list" data-toggle="tab" data-target="#list-home" role="tab" aria-controls="list-home" aria-selected="true">Home</button>
197+
<button type="button" class="list-group-item list-group-item-action" id="list-profile-list" data-toggle="tab" data-target="#list-profile" role="tab" aria-controls="list-profile">Profile</button>
198+
<button type="button" class="list-group-item list-group-item-action" id="list-messages-list" data-toggle="tab" data-target="#list-messages" role="tab" aria-controls="list-messages">Messages</button>
199+
<button type="button" class="list-group-item list-group-item-action" id="list-settings-list" data-toggle="tab" data-target="#list-settings" role="tab" aria-controls="list-settings">Settings</button>
203200
</div>
204201
</div>
205202
<div class="col-8">

scss/_nav.scss

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,13 @@
3737

3838
.nav-link {
3939
margin-bottom: -$nav-tabs-border-width;
40+
background-color: transparent;
4041
border: $nav-tabs-border-width solid transparent;
4142
@include border-top-radius($nav-tabs-border-radius);
4243

4344
@include hover-focus() {
45+
// Prevents active .nav-link tab overlapping focus outline of previous/next .nav-link
46+
isolation: isolate;
4447
border-color: $nav-tabs-link-hover-border-color;
4548
}
4649

@@ -73,6 +76,8 @@
7376

7477
.nav-pills {
7578
.nav-link {
79+
background: none;
80+
border: 0;
7681
@include border-radius($nav-pills-border-radius);
7782
}
7883

0 commit comments

Comments
 (0)