question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

focusIn listener causes issues with outside elements

See original GitHub issue

Re: #42

When certain Kendo UI elements are attached to the body outside the focus-trap (i.e. datepicker), it attempts to regain focus in the focusIn listener; even when using allowOutsideClick or clickOutsideDeactivates.

Not sure what the fix needs to be, but from the little time I have spent with this library, I think checking for these options in the focusIn handler is also needed.

Optionally, a new option could be introduced that either takes a string (selector) or a callback that can check if the clicked/focused element is allowed to take focus.

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:15 (8 by maintainers)

github_iconTop GitHub Comments

2reactions
stefcameroncommented, Oct 22, 2022

If anyone else who responded to this issue would still like to have a constructive discussion about a possible solution, I’m happy to. Y’all know where my thoughts are at so far.

1reaction
dstochcommented, Oct 21, 2022

Maybe my use case is not exatly the same as Mark’s, but in general when we are talking about elements added directly to BODY I see two main problems (you’ve described it also eralier):

  1. We cannot control 3rd party components to force them to add elements to some concrete container below body. They often add elements to body tag directly. So we cannot pass specific element below body when constructing focus-trap, we must update it using updateContainers() on the fly. I’ve already implemented this for Select2 using MutationObserver to observe changes in document.body and dynamically update list fo containers in focus-trap. Here possible improvement could be to allow to pass some “dynamic” selector to focus-trap, not concrete elements. But it is probably quite big change in code.
  2. Event if we solved this first problem, the second one still exists: proper tab order (as @stefcameron decribed in last comment). And currently I don’t know how to solve this.

The whole problem comes form HTML/CSS limitations to handle such things like modals, dropdowns, etc. These all hacks with adding elements to body are problematic for operating from the keyboard becuase this braeks natural HTML elements order. Maybe someone knows some applications/websites when these things are properly implemented (eg. some government sites, which often are WCAG compliant)?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Element: focusout event - Web APIs | MDN
The focusout event fires when an element has lost focus, after the blur event. The two events differ in that focusout bubbles, while...
Read more >
Element focus listener not triggered after first ... - Stack Overflow
The focusin event is sent to an element when it, or any element inside of it, gains focus. This is distinct from the...
Read more >
Focusing: focus/blur - The Modern JavaScript Tutorial
The focus event is called on focusing, and blur – when the element loses the focus. Let's use them for validation of an...
Read more >
Bug: Behavior of onFocus event in React 17 is counterintuitive ...
I believe this is happening because React is now listening using a non-capturing focusin listener on the React root rather than a capturing ......
Read more >
Catching the blur event on an element and its children
Recently I implemented a fly out menu in React, and stumbled on the following problem - I had to catch a blur event...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found