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

feat: remove click handler setting onTabContentFocusIn #1263

Merged
merged 2 commits into from
May 5, 2023
Merged
Changes from 1 commit
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
30 changes: 8 additions & 22 deletions packages/golden-layout/src/controls/Tab.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,11 +83,6 @@ export default class Tab {
this.contentItem.container._contentElement
.on('focusin', this._onTabContentFocusIn)
.on('focusout', this._onTabContentFocusOut);
this.contentItem.container._contentElement[0].addEventListener(
'click',
this._onTabContentFocusIn,
true // capture, so it occurs before onClick from react events
);

this.contentItem.container.tab = this;
this.contentItem.container.emit('tab', this);
Expand Down Expand Up @@ -181,25 +176,16 @@ export default class Tab {

/**
* Callback when the contentItem is focused in
*
* Why [0].focus():
* https://github.com/jquery/jquery/commit/fe5f04de8fde9c69ed48283b99280aa6df3795c7
* From jquery source: "If this is an inner synthetic event for an event with a bubbling surrogate (focus or blur),
* assume that the surrogate already propagated from triggering the native event and prevent that from happening
* again here. This technically gets the ordering wrong w.r.t. to `.trigger()` (in which the bubbling surrogate
* propagates *after* the non-bubbling base), but that seems less bad than duplication."
*/
_onTabContentFocusIn() {
if (
isComponent(this.contentItem) &&
!this.contentItem.container._contentElement[0].contains(
document.activeElement
)
) {
// jquery 3.4.0 and later, jquery method optimizes out the focus from
// happening in proper order. Can use HTMLElement.focus() to avoid.
this.contentItem.container._contentElement[0].focus(); // [0] needed to use dom focus, not jquery method
}
// Ensure only one tab is marked as having focus at a time.
// In Firefox, if the focused element is removed from the DOM,
// the focusout event won't trigger. This can result in two tabs
// being erroneously marked as focused if the user's DOM element
// is removed and they click another tab. To prevent this, we
// remove existing "lm_focusin" classes first.
$('lm_focusin').removeClass('lm_focusin');
dsmmcken marked this conversation as resolved.
Show resolved Hide resolved

this.element.addClass('lm_focusin');
}

Expand Down