Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions src/core/render/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -324,8 +324,12 @@ export function Render(Base) {
this.#addTextAsTitleAttribute('.sidebar-nav a');

if (loadSidebar && activeEl) {
const parent = /** @type {HTMLElement} */ (activeEl.parentElement);
parent.innerHTML += this.compiler.subSidebar(subMaxLevel) || '';
activeEl
.closest('li')
?.insertAdjacentHTML(
'beforeend',
this.compiler.subSidebar(subMaxLevel) || '',
);
} else {
this.compiler.resetToc();
}
Expand Down
2 changes: 1 addition & 1 deletion src/themes/shared/_sidebar.css
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@
}

&.collapse {
> :not(a) {
> :not(a, p:has(> a.page-link)) {
display: none;
}
}
Expand Down
44 changes: 44 additions & 0 deletions test/e2e/sidebar.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,50 @@ test.describe('Sidebar Tests', () => {
await expect(activeLinkElm).toHaveText('Test >');
expect(page.url()).toMatch(/\/test%3Efoo$/);
});

test('keeps a loose-list page link visible when collapsed', async ({
page,
}) => {
await docsifyInit({
config: {
subMaxLevel: 2,
},
markdown: {
homepage: '# Home',
sidebar: `
- Getting started

- [Introduction](introduction.md)

- [Quick start](quickstart.md)
`,
},
routes: {
'/quickstart.md': `
# Quick start

## Installation
`,
},
styleURLs: ['/dist/themes/core.css'],
});

const quickStartLink = page.locator('.sidebar-nav a[href="#/quickstart"]');

await quickStartLink.click();

const quickStartItem = page.locator(
'.sidebar-nav li:has(> p > a[href="#/quickstart"])',
);
const subSidebar = quickStartItem.locator(':scope > .app-sub-sidebar');
await expect(subSidebar).toBeVisible();

await quickStartLink.click();

await expect(quickStartItem).toHaveClass(/collapse/);
await expect(subSidebar).toBeHidden();
await expect(quickStartLink).toBeVisible();
});
});

test.describe('Mobile sidebar toggle', () => {
Expand Down