mirror of
https://github.com/docsifyjs/docsify.git
synced 2026-10-18 13:11:11 +08:00
fix: preserve loose-list sidebar links when collapsed (#2787)
This commit is contained in:
@@ -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();
|
||||
}
|
||||
|
||||
@@ -89,7 +89,7 @@
|
||||
}
|
||||
|
||||
&.collapse {
|
||||
> :not(a) {
|
||||
> :not(a, p:has(> a.page-link)) {
|
||||
display: none;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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', () => {
|
||||
|
||||
Reference in New Issue
Block a user