Skip to content

Commit

Permalink
Do not initialize sidebar multiple times
Browse files Browse the repository at this point in the history
  • Loading branch information
josevalim committed Dec 21, 2024
1 parent ad01652 commit 4698379
Show file tree
Hide file tree
Showing 9 changed files with 83 additions and 78 deletions.
14 changes: 7 additions & 7 deletions assets/css/sidebar.css
Original file line number Diff line number Diff line change
Expand Up @@ -109,25 +109,25 @@
display: none;
}

.sidebar .sidebar-listNav {
.sidebar .sidebar-list-nav {
display: flex;
margin: 0;
padding: 4px 4px 0 4px;
}

.sidebar .sidebar-listNav :is(li, li button) {
.sidebar .sidebar-list-nav :is(li, li button) {
text-transform: uppercase;
letter-spacing: 0.02em;
font-size: 14px;
color: var(--sidebarMuted);
}

.sidebar .sidebar-listNav li {
.sidebar .sidebar-list-nav li {
display: inline-block;
padding: 0;
}

.sidebar .sidebar-listNav li button {
.sidebar .sidebar-list-nav li button {
background: none;
border: 0;
border-radius: 0;
Expand All @@ -142,16 +142,16 @@
transition: all 150ms;
}

.sidebar .sidebar-listNav li:is(.selected) button {
.sidebar .sidebar-list-nav li:is(.selected) button {
background-color: var(--sidebarBackground);
border-top: var(--navTabBorderWidth) solid var(--sidebarLanguageAccentBar);
}

.sidebar .sidebar-listNav li:not(.selected) button {
.sidebar .sidebar-list-nav li:not(.selected) button {
border-top: var(--navTabBorderWidth) solid var(--sidebarHeader);
}

.sidebar .sidebar-listNav li:is(:hover):not(.selected) button {
.sidebar .sidebar-list-nav li:is(:hover):not(.selected) button {
background-color: var(--sidebarInactiveItemMarker);
border-top: var(--navTabBorderWidth) solid var(--sidebarInactiveItemBorder);
color: var(--sidebarAccentMain);
Expand Down
9 changes: 7 additions & 2 deletions assets/js/sidebar/sidebar-list.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@ const SIDEBAR_TYPE = {
tasks: 'tasks'
}

const SIDEBAR_TAB_TYPES = [SIDEBAR_TYPE.extras, SIDEBAR_TYPE.modules, SIDEBAR_TYPE.tasks]
let sidebarInitialized = false

const SIDEBAR_TAB_TYPES = [SIDEBAR_TYPE.extras, SIDEBAR_TYPE.modules, SIDEBAR_TYPE.tasks]
const sidebarNodeListSelector = type => `#${type}-full-list`

/**
Expand All @@ -19,9 +20,13 @@ export function initialize () {
SIDEBAR_TAB_TYPES.forEach(type => {
renderSidebarNodeList(getSidebarNodes(), type)
})

markActiveSidebarTab(getCurrentPageSidebarType())
markCurrentHashInSidebar()
scrollNodeListToCurrentCategory()

if (sidebarInitialized) return
sidebarInitialized = true
addEventListeners()
}

Expand Down Expand Up @@ -191,7 +196,7 @@ function addEventListeners () {
})

// provide left/right arrow navigation for tablist, as required by ARIA authoring practices guide
const tabList = qs('#sidebar-listNav')
const tabList = qs('#sidebar-list-nav')
tabList.addEventListener('keydown', (e) => {
if (e.key !== 'ArrowRight' && e.key !== 'ArrowLeft') { return }

Expand Down
56 changes: 0 additions & 56 deletions formatters/html/dist/html-MQUHN72N.js

This file was deleted.

56 changes: 56 additions & 0 deletions formatters/html/dist/html-XFWJYN4N.js

Large diffs are not rendered by default.

6 changes: 6 additions & 0 deletions formatters/html/dist/html-elixir-4VTRB5LF.css

Large diffs are not rendered by default.

6 changes: 0 additions & 6 deletions formatters/html/dist/html-elixir-BZS65SHR.css

This file was deleted.

6 changes: 0 additions & 6 deletions formatters/html/dist/html-erlang-NQ64IBM7.css

This file was deleted.

6 changes: 6 additions & 0 deletions formatters/html/dist/html-erlang-XHVETOWJ.css

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion lib/ex_doc/formatter/html/templates/sidebar_template.eex
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
</div>
</div>
</div>
<ul id="sidebar-listNav" class="sidebar-listNav" role="tablist">
<ul id="sidebar-list-nav" class="sidebar-list-nav" role="tablist">
<li>
<button id="extras-list-tab-button" role="tab" data-type="extras" aria-controls="extras-tab-panel" aria-selected="true" tabindex="0">
<%= config.extra_section || "Pages" %>
Expand Down

0 comments on commit 4698379

Please sign in to comment.