livebook icon indicating copy to clipboard operation
livebook copied to clipboard

Modal buttons have inconsistent behavior with tab + enter/space

Open postpostscript opened this issue 3 years ago • 3 comments

Environment

  • Elixir & Erlang/OTP versions: Elixir 1.14.0, Erlang/OTP 25
  • Operating system: WSL/Ubuntu 18.04
  • How have you started Livebook: mix phx.server
  • Livebook version: 9600a3d3a38b4f20f47af3e7595b712bc5e6ba7f (main)
  • Browsers that reproduce this bug: Firefox/Chrome on Windows

Current behavior

After opening a modal, tabbing to a button and pressing enter or space will close the modal. If you interact with the modal once (clicking) beforehand, it works

Expected behavior

Pressing enter/space should work every time

postpostscript avatar Sep 14 '22 21:09 postpostscript

Removing the phx-click-away event will prevent the modal from being closed, but the first enter/space press still doesn't work. I don't know what the underlying issue is yet, but I'd be happy to try to find a solution later

postpostscript avatar Sep 14 '22 21:09 postpostscript

LiveView v0.18 has a .focus_wrap function component which we can probably use around our modals too.

josevalim avatar Sep 16 '22 06:09 josevalim

We will definitely use focus wrap, but currently the focus already moves to modal when opened, but tabbing into a specific button and hitting enter does close the modal :thinking:

jonatanklosko avatar Sep 16 '22 09:09 jonatanklosko

I have reproduce this only with LiveView. It is likely a phx-click-away bug.

josevalim avatar Oct 04 '22 08:10 josevalim

The issue is that when we open a modal with a click, LV takes a note of which element was clicked, then when we hit enter on a button, we trigger mouseless click and phx-click-away is dispatched based on the previous element.

This has actually been fixed in https://github.com/phoenixframework/phoenix_live_view/commit/37a20e234360a493d914889191c2fee0090e4fcf, so we need to wait for a new LV version and we are good!

jonatanklosko avatar Oct 04 '22 10:10 jonatanklosko