knyghty / django-admin-keyboard-shortcuts

MIT License
15 stars 0 forks source link

Don't act on shortcuts when an input is focused #13

Closed knyghty closed 5 months ago

knyghty commented 5 months ago

Or something.

Currently any shortcuts can be handled when typing text into an input. This is very annoying and can navigate you to a different page, e.g. if you press g followed by i.

eviljeff commented 5 months ago

Documenting my investigation into using aria role to identify text fields (https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Roles/textbox_role): tl;dr, it's not possible.

Aria roles are not exposed in the DOM to javascript, and although there is a plan to expose accessibility data to the DOM it doesn't appear to be heading to implementation fast - most of the discussions I found started 10 years ago. Firefox and Chromium have some partial support, but both disabled behind a config flag - which are also not heading to being enabled by default any time soon, looks like.

I thought aria roles were more exposed because testing-library allows them to be referenced, but tracing through the testing-library source code eventually leads to hard-coded definitions in aria-query.

Adding aria-query as a dependency doesn't seem justifiable to me, and with no browser support on the horizon I think we're limited to checking tag names and input type.

knyghty commented 5 months ago

Makes sense to me. I also added this in the PR, but belongs here: I think we should also only disable what I'm going to call "raw" shortcuts - those without a modifier. So the alt+something shortcuts should still work.

Still need to think about how this all works if people use alt in a text box to create fancier letters, though.