Skip to content

Commit

Permalink
allow to set/configure ariaLabel for IButton (#202127)
Browse files Browse the repository at this point in the history
fixes #201527
  • Loading branch information
jrieken authored Jan 10, 2024
1 parent dd7a20d commit ad68ddc
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/vs/base/browser/ui/button/button.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import { localize } from 'vs/nls';

export interface IButtonOptions extends Partial<IButtonStyles> {
readonly title?: boolean | string;
readonly ariaLabel?: boolean | string;
readonly supportIcons?: boolean;
readonly supportShortLabel?: boolean;
readonly secondary?: boolean;
Expand Down Expand Up @@ -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));
Expand Down Expand Up @@ -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;
}

Expand Down
2 changes: 2 additions & 0 deletions src/vs/platform/actions/browser/buttonbar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
});
}

Expand Down

0 comments on commit ad68ddc

Please sign in to comment.