Skip to content

Fix hover accessible view icons being read as "space" by screen readers #252347

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

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
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
4 changes: 3 additions & 1 deletion src/vs/editor/contrib/hover/browser/hoverAccessibleViews.ts
Original file line number Diff line number Diff line change
Expand Up @@ -216,9 +216,11 @@ export class HoverAccessibleViewProvider extends BaseHoverAccessibleViewProvider
}
const actionLabel = labelForHoverVerbosityAction(this._keybindingService, action);
const actionEnabled = this._hoverController.doesHoverAtIndexSupportVerbosityAction(this._focusedHoverPartIndex, action);
return new Action(accessibleActionId, actionLabel, ThemeIcon.asClassName(actionCodicon), actionEnabled, () => {
const actionInstance = new Action(accessibleActionId, actionLabel, ThemeIcon.asClassName(actionCodicon), actionEnabled, () => {
editor.getAction(actionId)?.run({ index: this._focusedHoverPartIndex, focus: false });
});
actionInstance.tooltip = actionLabel;
return actionInstance;
}

private _initializeOptions(editor: ICodeEditor, hoverController: ContentHoverController): void {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/

import assert from 'assert';
import { Action } from '../../../../../base/common/actions.js';
import { Codicon } from '../../../../../base/common/codicons.js';
import { ThemeIcon } from '../../../../../base/common/themables.js';
import { ensureNoDisposablesAreLeakedInTestSuite } from '../../../../../base/test/common/utils.js';
import { HoverVerbosityAction } from '../../../../common/languages.js';
import { HoverAccessibleViewProvider } from '../../browser/hoverAccessibleViews.js';
import { withTestCodeEditor } from '../../../../test/browser/testCodeEditor.js';
import { ContentHoverController } from '../../browser/contentHoverController.js';
import { IKeybindingService } from '../../../../../platform/keybinding/common/keybinding.js';
import { NullKeybindingService } from '../../../../../platform/keybinding/test/common/nullKeybindingService.js';

suite('Hover Accessible Views', () => {

ensureNoDisposablesAreLeakedInTestSuite();

test('Actions should have proper tooltip for accessibility', () => {
const text = 'just some text';
withTestCodeEditor(text, {}, (editor) => {
const hoverController = editor.getContribution<ContentHoverController>(ContentHoverController.ID);
if (!hoverController) {
assert.fail('ContentHoverController not found');
}

const keybindingService = new NullKeybindingService();
const provider = new HoverAccessibleViewProvider(keybindingService, editor, hoverController);

// Test the _getActionFor method through reflection since it's private
const getActionFor = (provider as any)._getActionFor.bind(provider);

// Test increase action
const increaseAction = getActionFor(editor, HoverVerbosityAction.Increase);
assert.strictEqual(increaseAction.label, 'Increase Hover Verbosity');
assert.strictEqual(increaseAction.tooltip, 'Increase Hover Verbosity');
assert.strictEqual(increaseAction.class, ThemeIcon.asClassName(Codicon.add));

// Test decrease action
const decreaseAction = getActionFor(editor, HoverVerbosityAction.Decrease);
assert.strictEqual(decreaseAction.label, 'Decrease Hover Verbosity');
assert.strictEqual(decreaseAction.tooltip, 'Decrease Hover Verbosity');
assert.strictEqual(decreaseAction.class, ThemeIcon.asClassName(Codicon.remove));
});
});

test('Action tooltip matches label for screen reader accessibility', () => {
// Create a simple action similar to how the hover accessible view does it
const actionLabel = 'Increase Hover Verbosity';
const actionCodicon = Codicon.add;

// Simulate the fixed behavior
const actionInstance = new Action('test', actionLabel, ThemeIcon.asClassName(actionCodicon), true, () => {});
actionInstance.tooltip = actionLabel;

// Verify that tooltip is set correctly
assert.strictEqual(actionInstance.tooltip, actionLabel);
assert.strictEqual(actionInstance.label, actionLabel);
assert.strictEqual(actionInstance.class, ThemeIcon.asClassName(actionCodicon));
});
});