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