Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 27 additions & 12 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,10 @@ export class KeyboardNavigation {
private widgetDropDownDivFocusOutListener: (e: Event) => void;

/** Event handler run when the toolbox gains focus. */
private toolboxFocusListener: () => void;
private toolboxFocusInListener: (e: Event) => void;

/** Event handler run when the toolbox loses focus. */
private toolboxBlurListener: (e: Event) => void;
private toolboxFocusOutListener: (e: Event) => void;

/** Event handler run when the flyout gains focus. */
private flyoutFocusListener: () => void;
Expand Down Expand Up @@ -112,10 +112,6 @@ export class KeyboardNavigation {
flyoutElement,
workspace.getParentSvg(),
);
// Allow tab to the flyout only when there's no toolbox.
if (workspace.getToolbox() && flyoutElement) {
flyoutElement.tabIndex = -1;
}

// Temporary workaround for #136.
this.oldMarkFocused = workspace.markFocused;
Expand Down Expand Up @@ -179,10 +175,26 @@ export class KeyboardNavigation {
);

const toolboxElement = getToolboxElement(workspace);
this.toolboxFocusListener = () => {
this.toolboxFocusInListener = (e: Event) => {
if (
(e.currentTarget as Element).contains(
(e as FocusEvent).relatedTarget as Node,
)
) {
return;
}

this.navigationController.handleFocusToolbox(workspace);
};
this.toolboxBlurListener = (e: Event) => {
this.toolboxFocusOutListener = (e: Event) => {
if (
(e.currentTarget as Element).contains(
(e as FocusEvent).relatedTarget as Node,
)
) {
return;
}

this.navigationController.handleBlurToolbox(
workspace,
this.shouldCloseFlyoutOnBlur(
Expand All @@ -191,8 +203,8 @@ export class KeyboardNavigation {
),
);
};
toolboxElement?.addEventListener('focus', this.toolboxFocusListener);
toolboxElement?.addEventListener('blur', this.toolboxBlurListener);
toolboxElement?.addEventListener('focusin', this.toolboxFocusInListener);
toolboxElement?.addEventListener('focusout', this.toolboxFocusOutListener);

this.flyoutFocusListener = () => {
this.navigationController.handleFocusFlyout(workspace);
Expand Down Expand Up @@ -238,8 +250,11 @@ export class KeyboardNavigation {
);

const toolboxElement = getToolboxElement(this.workspace);
toolboxElement?.removeEventListener('focus', this.toolboxFocusListener);
toolboxElement?.removeEventListener('blur', this.toolboxBlurListener);
toolboxElement?.removeEventListener('focusin', this.toolboxFocusInListener);
toolboxElement?.removeEventListener(
'focusout',
this.toolboxFocusOutListener,
);

const flyoutElement = getFlyoutElement(this.workspace);
flyoutElement?.removeEventListener('focus', this.flyoutFocusListener);
Expand Down
12 changes: 0 additions & 12 deletions src/navigation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -540,12 +540,6 @@ export class Navigation {
if (!Blockly.Gesture.inProgress()) {
this.defaultFlyoutCursorIfNeeded(workspace);
}

// Prevent shift-tab to the toolbox while the flyout has focus.
const toolboxElement = getToolboxElement(workspace);
if (toolboxElement) {
toolboxElement.tabIndex = -1;
}
}

/**
Expand All @@ -561,12 +555,6 @@ export class Navigation {
workspace.hideChaff();
}
this.getFlyoutCursor(workspace)?.hide();

// Reinstate tab to toolbox.
const toolboxElement = getToolboxElement(workspace);
if (toolboxElement) {
toolboxElement.tabIndex = 0;
}
}

/**
Expand Down
Loading