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 2 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)?
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.