focus-trap: focusIn listener causes issues with outside elements
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.
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Comments: 15 (8 by maintainers)
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.
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):
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)?
Yes, most dynamic UI components that are “popup” in nature attach themselves to the
BODYelement. This is a widely used and common practice amongst front-end frameworks; specifically designed to address the many issues that arise when nesting “popup” components (i.e. hidden overflow, style inheritance/overrides, event bubbling, etc.).Except that
clickOutsideDeactivatesandallowOutsideClickalready opened this “Pandora’s box”. These are options that already exist and are supposedly supported by this project. I created this issue to bring light to a bug with these options wherecheckFocusIndoes not respect these options and steals focus back when it shouldn’t.Nope. It’s literally just adding a few lines of code to check for the existing options inside
checkFocusIn.Similar to how
checkClickdoes it.I’m not trying to sound ungrateful. This package does indeed do 99% of what we need it to do. However, to simply dismiss a legitimate use case just because is “seems” counter-productive to it achieving its primary goal is not a very strong argument.
I’m assuming that is why these options were created in the first place: to give the developer (who has to handle these use cases) the ability to do so. It’s up to them to determine when this option evaluates to true. In our case: it’s when the outside component is a Kendo UI “popup” component; for others, it may be a Select2 instance.
I’m not asking for anything that wasn’t already added. I’m asking for a bug with those options to be fixed.
Believe me, if I could have opted for a “quick and easy” solution, I would have. I really do not enjoy filing issues like this. It usually takes a ton of back and forth for me to try and “convince” someone of a legitimate issue like this.
I was referring to Vue.js Slots. It’s a common practice/pattern for wrapping content in Vue. Essentially, it’s just a way to inject content into a component; it could have easily been called
<content />, but they opted for<slot />instead; IDK, it is confusing at times.From the codesandbox example above, the main contents of the dialog (including the DatePicker) are in the
App.vuecomponent while theDialog.vuecomponent just wraps the provided content (denoted using<slot />) with additional structure relative to the component; in this case, a Kendo UI Dialog.This allows us to effectively create a single Dialog component that has additional features (focus-trap for example) that can be reused across the codebase. It also allows the contents of the Dialog to live with the implementation which also provides context. If we didn’t follow this pattern, we’d have to implement a custom Dialog for each implementation thus duplicating a bunch of code.
No; not applicable
The issue here is that the DatePicker is a component nested inside a slot of a custom Dialog component (wrapper around Kendo UI’s); it has no reference of the parent Dialog where the focus trap is. Also, it would require event handlers to be placed on all Kendo UI components that do this, which adds tech debt and code parity issues.
Unfortunately, due to keyboard power users, this is not an option. When the Dialog closes, the focus must be returned to the component (button/link) that opened it.
Sure! https://codesandbox.io/s/hardcore-joji-zm0ghh
Yes. By default, the Kendo UI DatePicker always attaches itself to the
BODYelement (as with many other similar components).Technically, it is possible via the
popupSettingsprop. However, the DatePicker cannot be inside the Dialog because it scrolls any overflow; thus hiding the DatePicker if it’s attached inside the dialog where the focus-trap is. This is true of many dynamic UI elements that require positioning its element near or close to the container of the dialog; this is why they’re attached to theBODYin the first place.