diff --git a/src/vs/base/browser/ui/button/button.ts b/src/vs/base/browser/ui/button/button.ts index 5550ff19c50cf..2e845b684f69a 100644 --- a/src/vs/base/browser/ui/button/button.ts +++ b/src/vs/base/browser/ui/button/button.ts @@ -23,6 +23,7 @@ import { localize } from 'vs/nls'; export interface IButtonOptions extends Partial { readonly title?: boolean | string; + readonly ariaLabel?: boolean | string; readonly supportIcons?: boolean; readonly supportShortLabel?: boolean; readonly secondary?: boolean; @@ -108,6 +109,9 @@ export class Button extends Disposable implements IButton { this._element.classList.add('monaco-text-button-with-short-label'); } + if (typeof options.ariaLabel === 'string') { + this._element.setAttribute('aria-label', options.ariaLabel); + } container.appendChild(this._element); this._register(Gesture.addTarget(this._element)); @@ -238,6 +242,12 @@ export class Button extends Disposable implements IButton { this._element.title = renderStringAsPlaintext(value); } + if (typeof this.options.ariaLabel === 'string') { + this._element.setAttribute('aria-label', this.options.ariaLabel); + } else if (this.options.ariaLabel) { + this._element.setAttribute('aria-label', this._element.title); + } + this._label = value; } diff --git a/src/vs/platform/actions/browser/buttonbar.ts b/src/vs/platform/actions/browser/buttonbar.ts index d8f57e29ebf68..21d4c4c5fc63e 100644 --- a/src/vs/platform/actions/browser/buttonbar.ts +++ b/src/vs/platform/actions/browser/buttonbar.ts @@ -82,11 +82,13 @@ export class WorkbenchButtonBar extends ButtonBar { actionRunner: this._actionRunner, actions: rest, contextMenuProvider: this._contextMenuService, + ariaLabel: action.label }); } else { action = actionOrSubmenu; btn = this.addButton({ secondary: conifgProvider(action)?.isSecondary ?? secondary, + ariaLabel: action.label }); }