* [PATCH yew-widget-toolkit] widget: dialog: prevent Escape from closing non-closable modals
@ 2026-07-09 13:58 Dominik Csapak
2026-07-09 14:15 ` superseded: " Dominik Csapak
0 siblings, 1 reply; 2+ messages in thread
From: Dominik Csapak @ 2026-07-09 13:58 UTC (permalink / raw)
To: yew-devel
Pressing Escape on a <dialog> triggers the browser's native close
handling regardless of whether our code considers the dialog closable.
When the dialog has no 'on_close' callback (e.g. a Login Window), this
leaves our component state and the native dialog state out of sync: the
browser treats the dialog as closed, while our widget is still rendered
but without the corresponding 'open' CSS class (which hides the
backdrop).
Intercept the KeyDown event and call stop_propagation()/
prevent_default() for Escape whenever the dialog isn't closable,
so the browser never fires its native close in the first place.
Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
---
src/widget/dialog.rs | 12 ++++++++++++
1 file changed, 12 insertions(+)
diff --git a/src/widget/dialog.rs b/src/widget/dialog.rs
index 4afecb2..9ee5e3f 100644
--- a/src/widget/dialog.rs
+++ b/src/widget/dialog.rs
@@ -114,6 +114,7 @@ impl Dialog {
pub enum Msg {
Open,
+ KeyDown(KeyboardEvent),
Close,
PointerDown(PointerEvent),
PointerMove(PointerEvent),
@@ -213,6 +214,14 @@ impl Component for PwtDialog {
}
}
}
+ Msg::KeyDown(event) => {
+ // prevent autoclosing of modal windows that can't be closed
+ if event.key() == "Escape" && (!self.open || props.on_close.is_none()) {
+ log::info!("prevented closing");
+ event.stop_propagation();
+ event.prevent_default();
+ }
+ }
Msg::Close => {
if self.open {
if let Some(on_close) = &props.on_close {
@@ -460,6 +469,8 @@ impl Component for PwtDialog {
Msg::Close
});
+ let onkeydown = link.callback(Msg::KeyDown);
+
let mut panel = Panel::new()
.class("pwt-overflow-auto")
.class("pwt-flex-fill")
@@ -533,6 +544,7 @@ impl Component for PwtDialog {
let dialog = Container::from_tag("dialog")
.class("pwt-outer-dialog")
.onpointerdown(onpointerdown)
+ .onkeydown(onkeydown)
.onclose(onclose)
.ontouchstart(cancel_event.clone())
.ontouchend(cancel_event.clone())
--
2.47.3
^ permalink raw reply related [flat|nested] 2+ messages in thread
* superseded: [PATCH yew-widget-toolkit] widget: dialog: prevent Escape from closing non-closable modals
2026-07-09 13:58 [PATCH yew-widget-toolkit] widget: dialog: prevent Escape from closing non-closable modals Dominik Csapak
@ 2026-07-09 14:15 ` Dominik Csapak
0 siblings, 0 replies; 2+ messages in thread
From: Dominik Csapak @ 2026-07-09 14:15 UTC (permalink / raw)
To: yew-devel
superseded by v2:
https://lore.proxmox.com/yew-devel/20260709141455.623886-1-d.csapak@proxmox.com/T/#u
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-07-09 14:15 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-07-09 13:58 [PATCH yew-widget-toolkit] widget: dialog: prevent Escape from closing non-closable modals Dominik Csapak
2026-07-09 14:15 ` superseded: " Dominik Csapak
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox