tim-janik / anklang

MIDI and Audio Synthesizer and Composer
https://anklang.testbit.eu/
Mozilla Public License 2.0
51 stars 3 forks source link

Focus, shadow DOM, submenus, buttons and input elements #55

Closed tim-janik closed 2 weeks ago

tim-janik commented 4 months ago

Currently we have a number of focus related problems:

Fixing focus/keyboard handling in the web platform is notoriously hard: Managing focus in the shadow DOM Dialogs and shadow DOM We have a lot of complex code in place for focus handling, but don't always catch all cases. The problems with a stuck grab may be related to the move to <dialog/> instead of our own focus/modal shield element, but this can also be caused by the menu items containing a focusable <button/> element.

Issus related to shadow DOM are manyfold.

Here is what we can do:

tim-janik commented 2 weeks ago
* **BUG:** Clicking on menu button and then _outside_ a popup menu causes the menu button to get stuck

FIXED.

* **BLOCKER:** The focus handling complexity is one major reason we do not support submenus yet, this important for plugin selection and some other cases.

WONTFIX, at least for now. We have proper support for trees with collapsible branches in menus now.

* **MINOR:** Arrow keys currently do not cycle through menus across start/end.

FIXED.

* **MINOR:** Using tab inside a focus trap like a modal dialog escapes into the browser chrome.

WONTFIX. We can reopen this in a separate issue if it turns out to be a real accessibility issue.

* Just implement arrow key focussing, based on reducing our current focus logic to just the two functions suggested in the above article series: `element.getNextTabbableElement()` `element.getPreviousTabbableElement()`

The code to figure the current (captured) focus chain (and thus the START/PREV/NEXT/END/LEFT/RIGHT/TOP/BOTTOM focus sibling) is still tedious and brittle, but covers our uses for now. It be best to move this into a community maintained npm module and ideally browser would provide support for this one day...

tim-janik commented 2 weeks ago

Issus related to shadow DOM are manyfold.

* Elements inside shaodow DOM cause issues in case they are focusable. Normally, shadow DOM is **not** an issue when <slot/> re-exposes child elements of a custom component to the light DOM tree. Instead of stashing focusable child elements into the shadowDOM, the component should simply derive from the focusable HTMLElement subclass to be focusable/editable (it just cannot be LitElement that way).

Also, we have moved all focus handling out of shadowDom elements now. And we will keep it that way.