Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

quick pick: a11y workaround #212248

Merged
merged 2 commits into from
May 10, 2024
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
18 changes: 17 additions & 1 deletion src/vs/platform/quickinput/browser/quickInputTree.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ import { ThrottledDelayer } from 'vs/base/common/async';
import { isCancellationError } from 'vs/base/common/errors';
import type { IHoverWidget, IUpdatableHoverTooltipMarkdownString } from 'vs/base/browser/ui/hover/hover';
import { QuickPickFocus } from '../common/quickInput';
import { IAccessibilityService } from 'vs/platform/accessibility/common/accessibility';

const $ = dom.$;

Expand Down Expand Up @@ -706,7 +707,8 @@ export class QuickInputTree extends Disposable {
private hoverDelegate: IHoverDelegate,
private linkOpenerDelegate: (content: string) => void,
id: string,
@IInstantiationService instantiationService: IInstantiationService
@IInstantiationService instantiationService: IInstantiationService,
@IAccessibilityService private readonly accessibilityService: IAccessibilityService
) {
super();
this._container = dom.append(this.parent, $('.quick-input-list'));
Expand Down Expand Up @@ -1114,6 +1116,20 @@ export class QuickInputTree extends Disposable {
}
this._tree.setChildren(null, elements);
this._onChangedVisibleCount.fire(visibleCount);

// Accessibility hack, unfortunately on next tick
// https://github.com/microsoft/vscode/issues/211976
if (this.accessibilityService.isScreenReaderOptimized()) {
setTimeout(() => {
const focusedElement = this._tree.getHTMLElement().querySelector(`.monaco-list-row.focused`);
const parent = focusedElement?.parentNode;
if (focusedElement && parent) {
const nextSibling = focusedElement.nextSibling;
parent.removeChild(focusedElement);
parent.insertBefore(focusedElement, nextSibling);
}
}, 0);
}
}

getElementsCount(): number {
Expand Down
3 changes: 3 additions & 0 deletions src/vs/platform/quickinput/test/browser/quickinput.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ import { ContextKeyService } from 'vs/platform/contextkey/browser/contextKeyServ
import { NoMatchingKb } from 'vs/platform/keybinding/common/keybindingResolver';
import { IKeybindingService } from 'vs/platform/keybinding/common/keybinding';
import { ContextViewService } from 'vs/platform/contextview/browser/contextViewService';
import { IAccessibilityService } from 'vs/platform/accessibility/common/accessibility';
import { TestAccessibilityService } from 'vs/platform/accessibility/test/common/testAccessibilityService';

// Sets up an `onShow` listener to allow us to wait until the quick pick is shown (useful when triggering an `accept()` right after launching a quick pick)
// kick this off before you launch the picker and then await the promise returned after you launch the picker.
Expand Down Expand Up @@ -62,6 +64,7 @@ suite('QuickInput', () => { // https://github.com/microsoft/vscode/issues/147543
// Stub the services the quick input controller needs to function
instantiationService.stub(IThemeService, new TestThemeService());
instantiationService.stub(IConfigurationService, new TestConfigurationService());
instantiationService.stub(IAccessibilityService, new TestAccessibilityService());
instantiationService.stub(IListService, store.add(new ListService()));
instantiationService.stub(ILayoutService, { activeContainer: fixture, onDidLayoutContainer: Event.None } as any);
instantiationService.stub(IContextViewService, store.add(instantiationService.createInstance(ContextViewService)));
Expand Down