Skip to content

Commit 618ea67

Browse files
author
Benjamin Pasero
committed
quick input - allow to set aria-label
1 parent 37e042c commit 618ea67

4 files changed

Lines changed: 29 additions & 3 deletions

File tree

src/vs/base/browser/ui/inputbox/inputBox.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,10 @@ export class InputBox extends Widget {
248248
}
249249
}
250250

251+
public getAriaLabel(): string {
252+
return this.ariaLabel;
253+
}
254+
251255
public get mirrorElement(): HTMLElement | undefined {
252256
return this.mirror;
253257
}

src/vs/base/parts/quickinput/browser/quickInput.ts

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -374,9 +374,10 @@ class QuickInput extends Disposable implements IQuickInput {
374374

375375
class QuickPick<T extends IQuickPickItem> extends QuickInput implements IQuickPick<T> {
376376

377-
private static readonly INPUT_BOX_ARIA_LABEL = localize('quickInputBox.ariaLabel', "Type to narrow down results.");
377+
private static readonly DEFAULT_ARIA_LABEL = localize('quickInputBox.ariaLabel', "Type to narrow down results.");
378378

379379
private _value = '';
380+
private _ariaLabel = QuickPick.DEFAULT_ARIA_LABEL;
380381
private _placeholder: string | undefined;
381382
private readonly onDidChangeValueEmitter = this._register(new Emitter<string>());
382383
private readonly onDidAcceptEmitter = this._register(new Emitter<void>());
@@ -419,6 +420,15 @@ class QuickPick<T extends IQuickPickItem> extends QuickInput implements IQuickPi
419420

420421
filterValue = (value: string) => value;
421422

423+
set ariaLabel(ariaLabel: string) {
424+
this._ariaLabel = ariaLabel || QuickPick.DEFAULT_ARIA_LABEL;
425+
this.update();
426+
}
427+
428+
get ariaLabel() {
429+
return this._ariaLabel;
430+
}
431+
422432
get placeholder() {
423433
return this._placeholder;
424434
}
@@ -775,6 +785,9 @@ class QuickPick<T extends IQuickPickItem> extends QuickInput implements IQuickPi
775785
if (this.ui.inputBox.placeholder !== (this.placeholder || '')) {
776786
this.ui.inputBox.placeholder = (this.placeholder || '');
777787
}
788+
if (this.ui.inputBox.ariaLabel !== this.ariaLabel) {
789+
this.ui.inputBox.ariaLabel = this.ariaLabel;
790+
}
778791
if (this.itemsUpdated) {
779792
this.itemsUpdated = false;
780793
this.ui.list.setElements(this.items);
@@ -825,7 +838,6 @@ class QuickPick<T extends IQuickPickItem> extends QuickInput implements IQuickPi
825838
this.ui.list.matchOnLabel = this.matchOnLabel;
826839
this.ui.list.sortByLabel = this.sortByLabel;
827840
this.ui.setComboboxAccessibility(true);
828-
this.ui.inputBox.setAttribute('aria-label', QuickPick.INPUT_BOX_ARIA_LABEL);
829841
}
830842
}
831843

@@ -1383,7 +1395,7 @@ export class QuickInputController extends Disposable {
13831395
ui.list.sortByLabel = true;
13841396
ui.ignoreFocusOut = false;
13851397
this.setComboboxAccessibility(false);
1386-
ui.inputBox.removeAttribute('aria-label');
1398+
ui.inputBox.ariaLabel = '';
13871399

13881400
const backKeybindingLabel = this.options.backKeybindingLabel();
13891401
backButton.tooltip = backKeybindingLabel ? localize('quickInput.backWithKeybinding', "Back ({0})", backKeybindingLabel) : localize('quickInput.back', "Back");

src/vs/base/parts/quickinput/browser/quickInputBox.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,14 @@ export class QuickInputBox extends Disposable {
6666
this.inputBox.setPlaceHolder(placeholder);
6767
}
6868

69+
get ariaLabel() {
70+
return this.inputBox.getAriaLabel();
71+
}
72+
73+
set ariaLabel(ariaLabel: string) {
74+
this.inputBox.setAriaLabel(ariaLabel);
75+
}
76+
6977
get password() {
7078
return this.inputBox.inputElement.type === 'password';
7179
}

src/vs/base/parts/quickinput/common/quickInput.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,8 @@ export interface IQuickPick<T extends IQuickPickItem> extends IQuickInput {
163163
*/
164164
filterValue: (value: string) => string;
165165

166+
ariaLabel: string;
167+
166168
placeholder: string | undefined;
167169

168170
readonly onDidChangeValue: Event<string>;

0 commit comments

Comments
 (0)