Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
microsoft
GitHub Repository: microsoft/vscode
Path: blob/main/src/vs/workbench/contrib/chat/browser/chatDebug/chatDebugCollapsible.ts
13406 views
1
/*---------------------------------------------------------------------------------------------
2
* Copyright (c) Microsoft Corporation. All rights reserved.
3
* Licensed under the MIT License. See License.txt in the project root for license information.
4
*--------------------------------------------------------------------------------------------*/
5
6
import * as DOM from '../../../../../base/browser/dom.js';
7
import { Codicon } from '../../../../../base/common/codicons.js';
8
import { DisposableStore } from '../../../../../base/common/lifecycle.js';
9
import { ThemeIcon } from '../../../../../base/common/themables.js';
10
11
/**
12
* Wire up a collapsible toggle on a chevron+header+content triple.
13
* Handles icon switching and display toggling.
14
*/
15
export function setupCollapsibleToggle(chevron: HTMLElement, header: HTMLElement, contentEl: HTMLElement, disposables: DisposableStore, initiallyCollapsed: boolean = false, scrollable?: { scanDomNode(): void }): void {
16
let collapsed = initiallyCollapsed;
17
18
// Accessibility: make header keyboard-focusable and expose toggle semantics
19
header.tabIndex = 0;
20
header.role = 'button';
21
chevron.setAttribute('aria-hidden', 'true');
22
23
const updateState = () => {
24
DOM.clearNode(chevron);
25
const icon = collapsed ? Codicon.chevronRight : Codicon.chevronDown;
26
chevron.classList.add(...ThemeIcon.asClassName(icon).split(' '));
27
contentEl.style.display = collapsed ? 'none' : 'block';
28
header.style.borderRadius = collapsed ? '' : '3px 3px 0 0';
29
header.setAttribute('aria-expanded', String(!collapsed));
30
};
31
32
updateState();
33
34
disposables.add(DOM.addDisposableListener(header, DOM.EventType.CLICK, () => {
35
collapsed = !collapsed;
36
chevron.className = 'chat-debug-message-section-chevron';
37
updateState();
38
scrollable?.scanDomNode();
39
}));
40
41
disposables.add(DOM.addDisposableListener(header, DOM.EventType.KEY_DOWN, (e: KeyboardEvent) => {
42
if (e.key === 'Enter' || e.key === ' ') {
43
e.preventDefault();
44
header.click();
45
}
46
}));
47
}
48
49