tmedwards / sugarcube-2

SugarCube is a free (gratis and libre) story format for Twine/Twee.
https://www.motoslave.net/sugarcube/2/
BSD 2-Clause "Simplified" License
177 stars 41 forks source link

Add a method to make truly modal Dialog elements #281

Open hituro opened 10 months ago

hituro commented 10 months ago

The Dialog element represents a modal, but there is no provision for a dialog that cannot be cancelled out of using the close box, background-click, or keyboard close methods. While it is possible for an author to disable or hide each of these methods for a particular Dialog, it is not trivial, and requires a close handler to restore the disabled functionality.

It would be great to optionally have a given Dialog be "truly modal" and require the user to actually take some action within the dialog to close it (like the HTML <dialog> or alert() but with better styling).

My tentative suggestion would be a Dialog.lock() method that is chainable and does the locking. An alternative would be to add another argument to Dialog.setup()/Dialog.create()to optionally lock it.

tmedwards commented 10 months ago

Preface. This idea specifically, and making Dialog act closer to browser modals in general, is something I've thought of before and I'll probably end up doing something.

That said. You're not actually required to interact with a modal. There are less ways to escape one, however, hitting the Escape key does close modals, both browser built-ins and <dialog>s in modal mode—in non-modals it selects the first non-disabled button. The point is that bringing Dialog into closer parity with browser modal behavior, by removing the title bar close button and overlay (backdrop) interaction closing, isn't going to force users to interact with modals more.

hituro commented 10 months ago

Is esc supposed to close Dialog elements? It doesn't do so for me on Firefox or Chrome (Mac).

tmedwards commented 10 months ago

There's no Escape handling for Dialog at the moment.