Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Restrict hover focus trap behaviour to Settings indicators #167756

Merged
merged 2 commits into from Nov 30, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -76,7 +76,8 @@ export class SettingsTreeIndicatorsLabel implements IDisposable {
private defaultHoverOptions: Partial<IHoverOptions> = {
hoverPosition: HoverPosition.BELOW,
showPointer: true,
compact: false
compact: false,
addFocusTraps: true
};

private addHoverDisposables(disposables: DisposableStore, element: HTMLElement, showHover: (focus: boolean) => IHoverWidget | undefined) {
Expand Down
6 changes: 6 additions & 0 deletions src/vs/workbench/services/hover/browser/hover.ts
Expand Up @@ -119,6 +119,12 @@ export interface IHoverOptions {
* another in the same group so it looks like the hover is moving from one element to the other.
*/
skipFadeInAnimation?: boolean;

/**
* Whether to add focus traps so that when the hover closes, focus goes to the last focused element,
* and when tabbing, focus stays inside of the hover.
*/
addFocusTraps?: boolean;
rzhao271 marked this conversation as resolved.
Show resolved Hide resolved
}

export interface IHoverAction {
Expand Down
6 changes: 4 additions & 2 deletions src/vs/workbench/services/hover/browser/hoverService.ts
Expand Up @@ -39,8 +39,10 @@ export class HoverService implements IHoverService {
return undefined;
}
this._currentHoverOptions = options;
if (document.activeElement) {
if (options.addFocusTraps && document.activeElement) {
this._lastFocusedElementBeforeOpen = document.activeElement as HTMLElement;
} else {
this._lastFocusedElementBeforeOpen = undefined;
}

const hoverDisposables = new DisposableStore();
Expand Down Expand Up @@ -118,7 +120,7 @@ export class HoverService implements IHoverService {
if (keybinding.getSingleModifierDispatchParts().some(value => !!value) || this._keybindingService.softDispatch(event, event.target)) {
return;
}
if (e.key !== 'Tab') {
if (!this._currentHoverOptions?.addFocusTraps || e.key !== 'Tab') {
this.hideHover();
this._lastFocusedElementBeforeOpen?.focus();
}
Expand Down
6 changes: 5 additions & 1 deletion src/vs/workbench/services/hover/browser/hoverWidget.ts
Expand Up @@ -52,6 +52,7 @@ export class HoverWidget extends Widget {
private _x: number = 0;
private _y: number = 0;
private _isLocked: boolean = false;
private _enableFocusTraps: boolean = false;
private _addedFocusTrap: boolean = false;

get isDisposed(): boolean { return this._isDisposed; }
Expand Down Expand Up @@ -110,6 +111,9 @@ export class HoverWidget extends Widget {
if (options.forcePosition) {
this._forcePosition = true;
}
if (options.addFocusTraps) {
this._enableFocusTraps = true;
}

this._hoverPosition = options.hoverPosition ?? HoverPosition.ABOVE;

Expand Down Expand Up @@ -224,7 +228,7 @@ export class HoverWidget extends Widget {
}

private addFocusTrap() {
if (this._addedFocusTrap) {
if (!this._enableFocusTraps || this._addedFocusTrap) {
return;
}
this._addedFocusTrap = true;
Expand Down