Skip to content

Commit 569865d

Browse files
author
Benjamin Pasero
committed
improve focus handling within actionbar
1 parent 0e29fad commit 569865d

1 file changed

Lines changed: 19 additions & 11 deletions

File tree

src/vs/base/browser/ui/actionbar/actionbar.ts

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -440,9 +440,9 @@ export class ActionBar extends EventEmitter implements IActionRunner {
440440
let event = new StandardKeyboardEvent(e);
441441
let eventHandled = true;
442442

443-
if (event.equals(isVertical ? CommonKeybindings.UP_ARROW : CommonKeybindings.LEFT_ARROW)) {
443+
if (event.equals(CommonKeybindings.UP_ARROW) || event.equals(CommonKeybindings.LEFT_ARROW)) {
444444
this.focusPrevious();
445-
} else if (event.equals(isVertical ? CommonKeybindings.DOWN_ARROW : CommonKeybindings.RIGHT_ARROW)) {
445+
} else if (event.equals(CommonKeybindings.DOWN_ARROW) || event.equals(CommonKeybindings.RIGHT_ARROW)) {
446446
this.focusNext();
447447
} else if (event.equals(CommonKeybindings.ESCAPE)) {
448448
this.cancel();
@@ -467,11 +467,17 @@ export class ActionBar extends EventEmitter implements IActionRunner {
467467
$(this.domNode).on(DOM.EventType.KEY_UP, (e: KeyboardEvent) => {
468468
let event = new StandardKeyboardEvent(e);
469469

470+
// Run action on Enter/Space
470471
if (event.equals(CommonKeybindings.ENTER) || event.equals(CommonKeybindings.SPACE)) {
471472
this.doTrigger(event);
472473
event.preventDefault();
473474
event.stopPropagation();
474475
}
476+
477+
// Recompute focused item
478+
else if (event.equals(CommonKeybindings.TAB)) {
479+
this.updateFocusedItem();
480+
}
475481
});
476482

477483
this.focusTracker = DOM.trackFocus(this.domNode);
@@ -482,15 +488,7 @@ export class ActionBar extends EventEmitter implements IActionRunner {
482488
}
483489
});
484490

485-
this.focusTracker.addFocusListener((e: Event) => {
486-
for (let i = 0; i < this.actionsList.children.length; i++) {
487-
let elem = this.actionsList.children[i];
488-
if (DOM.isAncestor(document.activeElement, elem)) {
489-
this.focusedItem = i;
490-
break;
491-
}
492-
}
493-
});
491+
this.focusTracker.addFocusListener(() => this.updateFocusedItem());
494492

495493
this.actionsList = document.createElement('ul');
496494
this.actionsList.className = 'actions-container';
@@ -502,6 +500,16 @@ export class ActionBar extends EventEmitter implements IActionRunner {
502500
container.appendChild(this.domNode);
503501
}
504502

503+
private updateFocusedItem(): void {
504+
for (let i = 0; i < this.actionsList.children.length; i++) {
505+
let elem = this.actionsList.children[i];
506+
if (DOM.isAncestor(document.activeElement, elem)) {
507+
this.focusedItem = i;
508+
break;
509+
}
510+
}
511+
}
512+
505513
public get context(): any {
506514
return this._context;
507515
}

0 commit comments

Comments
 (0)