Skip to content

Commit

Permalink
quick pick: a11y workaround (#212248)
Browse files Browse the repository at this point in the history
* quick pick: a11y workaround

fixes #211976

* fix tests
  • Loading branch information
joaomoreno committed May 10, 2024
1 parent 70e10d6 commit aef6b4c
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
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

0 comments on commit aef6b4c

Please sign in to comment.