Fixes dialog closing unexpectedly - #286
Conversation
7457ed4 to
bf007c1
Compare
this switches from use_outside_dismiss javascript function to dioxus owned event stack
|
Can you share a reproduction for the issues you were running into with the current implementation? I cannot get the dialog on the component demo to close when clicking on the dialog content on chrome, safari, or firefox. While this fix does work with the current way the component is laid out, we use this hook elsewhere where a similar fix is not applicable, so I would like to fix the general problem if we can |
|
alright so I retested this and the problem is still around, but under certain conditions only. use dioxus::prelude::*;
use crate::components::{dialog::*, tabs::*};
const FAVICON: Asset = asset!("/assets/favicon.ico");
const MAIN_CSS: Asset = asset!("/assets/main.css");
mod components;
fn main() {
dioxus::launch(App);
}
#[component]
fn App() -> Element {
rsx! {
document::Link { rel: "icon", href: FAVICON }
document::Link { rel: "stylesheet", href: MAIN_CSS }
Hero {}
}
}
#[component]
pub fn Hero() -> Element {
let mut open = use_signal(|| false);
rsx! {
Tabs {
default_value: "test".to_string(),
horizontal: false,
TabList {
TabTrigger { value: "test".to_string(), index: 0usize }
TabContent { index: 0usize, value: "test".to_string(),
button { onclick: move |_| open.set(true), "test" }
Dialog { open: open(), on_open_change: move |new| open.set(new),
style: "background-color: blue;",
div {
span { "test" }
}
button {
"test button"
}
}
}
}
}
}
}Where I just created a a bare-bones web project with no additional features and added the dialog and tabs using This behaviour only happens, when the dialog itself is inside the TabContent, so when setting the component up like this: #[component]
pub fn Hero() -> Element {
let mut open = use_signal(|| false);
rsx! {
Tabs {
default_value: "test".to_string(),
horizontal: false,
TabList {
TabTrigger { value: "test".to_string(), index: 0usize }
TabContent { index: 0usize, value: "test".to_string(),
button { onclick: move |_| open.set(true), "test" }
}
}
}
Dialog { open: open(), on_open_change: move |new| open.set(new),
style: "background-color: blue;",
div {
span { "test" }
}
button {
"test button"
}
}
}
}The dialog behaves normally not closing when being clicked inside. I also tried nesting the dialog in just the I am not sure if this is problematic with other primitives/page structures though. |
|
Through LLM help, I found out, that giving the Now the question is, should we set a default tabindex on the |
In the newer versions of dioxus-primitives, dialogs would close when clicking on their internal content such as text and empty space. This PR aims to fix this by using the internal dioxus event implementation instead of javascript. Specifically I removed
use_outside_dismissin theDialogContentand replaced it with an onclick handler on theDialogRootbackdrop.If this implementation doesn't cover all of
use_outside_dismiss's features I'll be happy to add them.