Skip to content

Commit 7632435

Browse files
authored
🐛 FIX: tabs with nested content hidden on click (#106)
* Fix tabset dissapearing when nested element clicked * Add focus outline offset * Update linenos test regression for pygments upgrade
1 parent 7490cd6 commit 7632435

File tree

3 files changed

+13
-11
lines changed

3 files changed

+13
-11
lines changed

sphinx_tabs/static/tabs.css

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,18 +25,20 @@
2525
font-weight: 700;
2626
border: 1px solid #a0b3bf;
2727
border-bottom: 1px solid white;
28-
margin-bottom: -1px;
28+
margin: -1px;
2929
background-color: white;
3030
}
3131

3232
.sphinx-tabs-tab:focus {
3333
z-index: 1;
34+
outline-offset: 1px;
3435
}
3536

3637
.sphinx-tabs-panel {
3738
position: relative;
3839
padding: 1rem;
3940
border: 1px solid #a0b3bf;
41+
margin: 0px -1px -1px -1px;
4042
border-radius: 0 0 5px 5px;
4143
border-top: 0;
4244
background: white;

sphinx_tabs/static/tabs.js

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -56,24 +56,24 @@ function keyTabs(e) {
5656
* @param {Node} e the element that was clicked
5757
*/
5858
function changeTabs(e) {
59-
const target = e.target;
60-
const selected = target.getAttribute("aria-selected") === "true";
61-
const positionBefore = target.parentNode.getBoundingClientRect().top;
59+
// Use this instead of the element that was clicked, in case it's a child
60+
const selected = this.getAttribute("aria-selected") === "true";
61+
const positionBefore = this.parentNode.getBoundingClientRect().top;
6262

63-
deselectTabset(target);
63+
deselectTabset(this);
6464

6565
if (!selected) {
66-
selectTab(target);
67-
const name = target.getAttribute("name");
68-
selectGroupedTabs(name, target.id);
66+
selectTab(this);
67+
const name = this.getAttribute("name");
68+
selectGroupedTabs(name, this.id);
6969

70-
if (target.classList.contains("group-tab")) {
70+
if (this.classList.contains("group-tab")) {
7171
// Persist during session
7272
session.setItem('sphinx-tabs-last-selected', name);
7373
}
7474
}
7575

76-
const positionAfter = target.parentNode.getBoundingClientRect().top;
76+
const positionAfter = this.parentNode.getBoundingClientRect().top;
7777
const positionDelta = positionAfter - positionBefore;
7878
// Scroll to offset content resizing
7979
window.scrollTo(0, window.scrollY + positionDelta);

tests/test_build/test_other_with_assets.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
<tr>
1717
<td class="linenos">
1818
<div class="linenodiv">
19-
<pre>1</pre>
19+
<pre><span class="normal">1</span></pre>
2020
</div>
2121
</td>
2222
<td class="code">

0 commit comments

Comments
 (0)