Skip to content

Commit

Permalink
Dynamic tabs: use buttons rather than links (backport to v4) (#33163)
Browse files Browse the repository at this point in the history
* 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 <alpa.muc@gmail.com>
Co-authored-by: Mark Otto <markd.otto@gmail.com>
Co-authored-by: Mark Otto <markdotto@gmail.com>
  • Loading branch information
4 people committed May 24, 2022
1 parent e4dc2e9 commit 7d57d9a
Show file tree
Hide file tree
Showing 6 changed files with 181 additions and 184 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
# Ignore docs files
/_site/
# Hugo folders
# Hugo files
/resources/
/.hugo_build.lock

# Numerous always-ignore extensions
*.diff
Expand Down
3 changes: 2 additions & 1 deletion js/src/tab.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@ class Tab {
if (this._element.parentNode &&
this._element.parentNode.nodeType === Node.ELEMENT_NODE &&
$(this._element).hasClass(CLASS_NAME_ACTIVE) ||
$(this._element).hasClass(CLASS_NAME_DISABLED)) {
$(this._element).hasClass(CLASS_NAME_DISABLED) ||
this._element.hasAttribute('disabled')) {
return
}

Expand Down
211 changes: 102 additions & 109 deletions js/tests/unit/tab.js

Large diffs are not rendered by default.

57 changes: 27 additions & 30 deletions js/tests/visual/tab.html
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,16 @@ <h4>Tabs without fade</h4>

<ul class="nav nav-tabs" role="tablist">
<li class="nav-item" role="presentation">
<a class="nav-link active" data-toggle="tab" href="#home" role="tab">Home</a>
<button type="button" class="nav-link active" data-toggle="tab" data-target="#home" role="tab" aria-selected="true">Home</button>
</li>
<li class="nav-item" role="presentation">
<a class="nav-link" data-toggle="tab" href="#profile" role="tab">Profile</a>
<button type="button" class="nav-link" data-toggle="tab" data-target="#profile" role="tab">Profile</button>
</li>
<li class="nav-item" role="presentation">
<a class="nav-link" data-toggle="tab" href="#fat" role="tab">@fat</a>
<button type="button" class="nav-link" data-toggle="tab" data-target="#fat" role="tab">@fat</button>
</li>
<li class="nav-item" role="presentation">
<a class="nav-link" data-toggle="tab" href="#mdo" role="tab">@mdo</a>
<button type="button" class="nav-link" data-toggle="tab" data-target="#mdo" role="tab">@mdo</button>
</li>
</ul>

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

<ul class="nav nav-tabs" role="tablist">
<li class="nav-item" role="presentation">
<a class="nav-link active" data-toggle="tab" href="#home2" role="tab">Home</a>
<button type="button" class="nav-link active" data-toggle="tab" data-target="#home2" role="tab" aria-selected="true">Home</button>
</li>
<li class="nav-item" role="presentation">
<a class="nav-link" data-toggle="tab" href="#profile2" role="tab">Profile</a>
<button type="button" class="nav-link" data-toggle="tab" data-target="#profile2" role="tab">Profile</button>
</li>
<li class="nav-item" role="presentation">
<a class="nav-link" data-toggle="tab" href="#fat2" role="tab">@fat</a>
<button type="button" class="nav-link" data-toggle="tab" data-target="#fat2" role="tab">@fat</button>
</li>
<li class="nav-item" role="presentation">
<a class="nav-link" data-toggle="tab" href="#mdo2" role="tab">@mdo</a>
<button type="button" class="nav-link" data-toggle="tab" data-target="#mdo2" role="tab">@mdo</button>
</li>
</ul>

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

<ul class="nav nav-tabs" role="tablist">
<li class="nav-item" role="presentation">
<a class="nav-link" data-toggle="tab" href="#home3" role="tab">Home</a>
<button type="button" class="nav-link" data-toggle="tab" data-target="#home3" role="tab">Home</button>
</li>
<li class="nav-item" role="presentation">
<a class="nav-link" data-toggle="tab" href="#profile3" role="tab">Profile</a>
<button type="button" class="nav-link" data-toggle="tab" data-target="#profile3" role="tab">Profile</button>
</li>
<li class="nav-item" role="presentation">
<a class="nav-link" data-toggle="tab" href="#fat3" role="tab">@fat</a>
<button type="button" class="nav-link" data-toggle="tab" data-target="#fat3" role="tab">@fat</button>
</li>
<li class="nav-item" role="presentation">
<a class="nav-link" data-toggle="tab" href="#mdo3" role="tab">@mdo</a>
<button type="button" class="nav-link" data-toggle="tab" data-target="#mdo3" role="tab">@mdo</button>
</li>
</ul>

Expand Down Expand Up @@ -159,26 +159,23 @@ <h4>Tabs with fade (no initially active pane)</h4>
</div>
</div>

<h4>Tabs with nav (with fade)</h4>
<nav class="nav nav-pills">
<a class="nav-link nav-item active" data-toggle="tab" href="#home5">Home</a>
<a class="nav-link nav-item" data-toggle="tab" href="#profile5">Profile</a>
<div class="nav-item dropdown">
<a class="nav-link dropdown-toggle" href="#" id="dropdown5" data-toggle="dropdown" aria-expanded="false">Dropdown</a>
<div class="dropdown-menu" aria-labelledby="dropdown5">
<a class="dropdown-item" data-toggle="tab" href="#fat5">@fat</a>
<a class="dropdown-item" data-toggle="tab" href="#mdo5">@mdo</a>
</div>
<h4>Tabs with nav and using links (with fade)</h4>
<nav>
<div class="nav nav-pills" id="nav-tab" role="tablist">
<a class="nav-link nav-item active" role="tab" data-toggle="tab" href="#home5">Home</a>
<a class="nav-link nav-item" role="tab" data-toggle="tab" href="#profile5">Profile</a>
<a class="nav-link nav-item" role="tab" data-toggle="tab" href="#fat5">@fat</a>
<a class="nav-link nav-item" role="tab" data-toggle="tab" href="#mdo5">@mdo</a>
<a class="nav-link nav-item disabled" role="tab" href="#">Disabled</a>
</div>
<a class="nav-link nav-item disabled" href="#">Disabled</a>
</nav>

<div class="tab-content" role="tabpanel">
<div role="tabpanel" class="tab-pane fade show active" id="home5">
<div class="tab-content">
<div class="tab-pane fade show active" id="home5" role="tabpanel">
<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>
<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>
</div>
<div role="tabpanel" class="tab-pane fade" id="profile5">
<div class="tab-pane fade" id="profile5" role="tabpanel">
<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>
<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>
</div>
Expand All @@ -196,10 +193,10 @@ <h4>Tabs with list-group (with fade)</h4>
<div class="row">
<div class="col-4">
<div class="list-group" id="list-tab" role="tablist">
<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>
<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>
<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>
<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>
<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>
<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>
<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>
<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>
</div>
</div>
<div class="col-8">
Expand Down
5 changes: 5 additions & 0 deletions scss/_nav.scss
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,13 @@

.nav-link {
margin-bottom: -$nav-tabs-border-width;
background-color: transparent;
border: $nav-tabs-border-width solid transparent;
@include border-top-radius($nav-tabs-border-radius);

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

Expand Down Expand Up @@ -73,6 +76,8 @@

.nav-pills {
.nav-link {
background: none;
border: 0;
@include border-radius($nav-pills-border-radius);
}

Expand Down

0 comments on commit 7d57d9a

Please sign in to comment.