Skip to content

Commit 2798d7b

Browse files
authored
joh/rainy weasel (microsoft#184582)
* add tooltip (plain text) to static items, re microsoft#183772 * support accessibilityInformation for static static bar contribs, microsoft#183772
1 parent d8dcdb9 commit 2798d7b

File tree

7 files changed

+50
-7
lines changed

7 files changed

+50
-7
lines changed

extensions/vscode-api-tests/package.json

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,12 @@
199199
"alignment": "right",
200200
"priority": 17,
201201
"name": "My Static Item",
202-
"text": "Hello $(globe)"
202+
"text": "Hello $(globe)",
203+
"tooltip": "Hover World",
204+
"accessibilityInformation": {
205+
"label": "Hello World",
206+
"role": "button"
207+
}
203208
}
204209
},
205210
"scripts": {

extensions/vscode-api-tests/src/singlefolder-tests/window.test.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1045,6 +1045,8 @@ suite('vscode API - window', () => {
10451045
assert.strictEqual(item.priority, 17);
10461046
assert.strictEqual(item.name, 'My Static Item');
10471047
assert.strictEqual(item.text, 'Hello $(globe)');
1048+
assert.strictEqual(item.tooltip, 'Hover World');
1049+
assert.deepStrictEqual(item.accessibilityInformation, { label: 'Hello World', role: 'button' });
10481050

10491051
item.dispose();
10501052
});

src/vs/platform/accessibility/common/accessibility.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,3 +40,9 @@ export interface IAccessibilityInformation {
4040
label: string;
4141
role?: string;
4242
}
43+
44+
export function isAccessibilityInformation(obj: any): obj is IAccessibilityInformation {
45+
return obj && typeof obj === 'object'
46+
&& typeof obj.label === 'string'
47+
&& (typeof obj.role === 'undefined' || typeof obj.role === 'string');
48+
}

src/vs/workbench/api/browser/mainThreadStatusBar.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,11 @@ export class MainThreadStatusBar implements MainThreadStatusBarShape {
4343
entryId,
4444
name: item.entry.name,
4545
text: item.entry.text,
46+
tooltip: item.entry.tooltip as string | undefined,
4647
command: typeof item.entry.command === 'string' ? item.entry.command : typeof item.entry.command === 'object' ? item.entry.command.id : undefined,
4748
priority: item.priority,
48-
alignLeft: item.alignment === StatusbarAlignment.LEFT
49+
alignLeft: item.alignment === StatusbarAlignment.LEFT,
50+
accessibilityInformation: item.entry.ariaLabel ? { label: item.entry.ariaLabel, role: item.entry.role } : undefined
4951
};
5052
}
5153
}

src/vs/workbench/api/browser/statusBarExtensionPoint.ts

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import { ExtensionsRegistry } from 'vs/workbench/services/extensions/common/exte
1212
import { IStatusbarService, StatusbarAlignment as MainThreadStatusBarAlignment, IStatusbarEntryAccessor, IStatusbarEntry, StatusbarAlignment, IStatusbarEntryPriority } from 'vs/workbench/services/statusbar/browser/statusbar';
1313
import { ThemeColor } from 'vs/base/common/themables';
1414
import { Command } from 'vs/editor/common/languages';
15-
import { IAccessibilityInformation } from 'vs/platform/accessibility/common/accessibility';
15+
import { IAccessibilityInformation, isAccessibilityInformation } from 'vs/platform/accessibility/common/accessibility';
1616
import { IMarkdownString } from 'vs/base/common/htmlContent';
1717
import { getCodiconAriaLabel } from 'vs/base/common/iconLabels';
1818
import { hash } from 'vs/base/common/hash';
@@ -157,15 +157,21 @@ interface IUserFriendlyStatusItemEntry {
157157
alignment: 'left' | 'right';
158158
command?: string;
159159
priority?: number;
160+
tooltip?: string;
161+
accessibilityInformation?: IAccessibilityInformation;
160162
}
161163

162-
function isUserFriendlyStatusItemEntry(obj: any): obj is IUserFriendlyStatusItemEntry {
164+
function isUserFriendlyStatusItemEntry(candidate: any): candidate is IUserFriendlyStatusItemEntry {
165+
const obj = candidate as IUserFriendlyStatusItemEntry;
163166
return (typeof obj.id === 'string' && obj.id.length > 0)
164167
&& typeof obj.name === 'string'
165168
&& typeof obj.text === 'string'
166169
&& (obj.alignment === 'left' || obj.alignment === 'right')
167170
&& (obj.command === undefined || typeof obj.command === 'string')
168-
&& (obj.priority === undefined || typeof obj.priority === 'number');
171+
&& (obj.tooltip === undefined || typeof obj.tooltip === 'string')
172+
&& (obj.priority === undefined || typeof obj.priority === 'number')
173+
&& (obj.accessibilityInformation === undefined || isAccessibilityInformation(obj.accessibilityInformation))
174+
;
169175
}
170176

171177
const statusBarItemSchema: IJSONSchema = {
@@ -184,6 +190,10 @@ const statusBarItemSchema: IJSONSchema = {
184190
type: 'string',
185191
description: localize('text', 'The text to show for the entry. You can embed icons in the text by leveraging the `$(<name>)`-syntax, like \'Hello $(globe)!\'')
186192
},
193+
tooltip: {
194+
type: 'string',
195+
description: localize('tooltip', 'The tooltip text for the entry.')
196+
},
187197
command: {
188198
type: 'string',
189199
description: localize('command', 'The command to execute when the status bar entry is clicked.')
@@ -196,6 +206,20 @@ const statusBarItemSchema: IJSONSchema = {
196206
priority: {
197207
type: 'number',
198208
description: localize('priority', 'The priority of the status bar entry. Higher value means the item should be shown more to the left.')
209+
},
210+
accessibilityInformation: {
211+
type: 'object',
212+
description: localize('accessibilityInformation', 'Defines the role and aria label to be used when the status bar entry is focused.'),
213+
properties: {
214+
role: {
215+
type: 'string',
216+
description: localize('accessibilityInformation.role', 'The role of the status bar entry which defines how a screen reader interacts with it. More about aria roles can be found here https://w3c.github.io/aria/#widget_roles')
217+
},
218+
label: {
219+
type: 'string',
220+
description: localize('accessibilityInformation.label', 'The aria label of the status bar entry. Defaults to the entry\'s text.')
221+
}
222+
}
199223
}
200224
}
201225
};
@@ -249,12 +273,12 @@ export class StatusBarItemsExtensionPoint {
249273
ExtensionIdentifier.toKey(entry.description.identifier),
250274
candidate.name ?? entry.description.displayName ?? entry.description.name,
251275
candidate.text,
252-
undefined,
276+
candidate.tooltip,
253277
candidate.command ? { id: candidate.command, title: candidate.name } : undefined,
254278
undefined, undefined,
255279
candidate.alignment === 'left',
256280
candidate.priority,
257-
undefined
281+
candidate.accessibilityInformation
258282
);
259283

260284
contributions.add(toDisposable(() => statusBarItemsService.unsetEntry(fullItemId)));

src/vs/workbench/api/common/extHost.protocol.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -624,7 +624,9 @@ export type StatusBarItemDto = {
624624
priority?: number;
625625
name: string;
626626
text: string;
627+
tooltip?: string;
627628
command?: string;
629+
accessibilityInformation?: IAccessibilityInformation;
628630
};
629631

630632
export interface ExtHostStatusBarShape {

src/vs/workbench/api/common/extHostStatusBar.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,9 @@ export class ExtHostStatusBarEntry implements vscode.StatusBarItem {
7171
this._visible = true;
7272
this.name = item.name;
7373
this.text = item.text;
74+
this.tooltip = item.tooltip;
7475
this.command = item.command;
76+
this.accessibilityInformation = item.accessibilityInformation;
7577
}
7678
} else {
7779
this._entryId = String(ExtHostStatusBarEntry.ID_GEN++);

0 commit comments

Comments
 (0)