Skip to content
Merged
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
11 changes: 11 additions & 0 deletions src/debug_toolbar/core/assets.py
Original file line number Diff line number Diff line change
Expand Up @@ -1980,13 +1980,23 @@ class DebugToolbar {
addCollapseButton() {
const collapseBtn = this.element.querySelector('.toolbar-collapse-btn');
if (collapseBtn) {
this.updateCollapseButton(collapseBtn);
collapseBtn.addEventListener('click', (e) => {
e.stopPropagation();
this.toggle();
});
}
}

updateCollapseButton(collapseBtn) {
const btn = collapseBtn || this.element.querySelector('.toolbar-collapse-btn');
if (!btn) return;
const label = this.isCollapsed ? 'Expand toolbar' : 'Collapse toolbar';
btn.title = label;
btn.setAttribute('aria-label', label);
btn.setAttribute('aria-expanded', String(!this.isCollapsed));
}

addThemeToggle() {
this.themeBtn = document.createElement('button');
this.themeBtn.className = 'toolbar-theme-btn';
Expand Down Expand Up @@ -2133,6 +2143,7 @@ class DebugToolbar {
this.isCollapsed = !this.isCollapsed;
this.element.classList.toggle('collapsed', this.isCollapsed);
localStorage.setItem('debug-toolbar-collapsed', String(this.isCollapsed));
this.updateCollapseButton();
this.applySize();
}

Expand Down
7 changes: 7 additions & 0 deletions tests/integration/test_litestar_middleware.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,13 @@ def test_does_not_inject_into_text_response(self, client: TestClient) -> None:
assert b"debug-toolbar" not in response.content


class TestCollapseButtonAccessibility:
def test_initial_markup_has_aria_expanded(self, client: TestClient) -> None:
response = client.get("/")
assert b'aria-label="Collapse toolbar"' in response.content
assert b'aria-expanded="true"' in response.content


class TestServerTimingHeader:
def test_adds_server_timing_header_to_html(self, client: TestClient) -> None:
response = client.get("/")
Expand Down
Loading