Просмотр исходного кода

tui: fix dialog replacement to prevent nested dialogs from showing simultaneously

Dax Raad 2 месяцев назад
Родитель
Сommit
416a919c6d
1 измененных файлов с 8 добавлено и 1 удалено
  1. 8 1
      packages/ui/src/context/dialog.tsx

+ 8 - 1
packages/ui/src/context/dialog.tsx

@@ -22,6 +22,7 @@ const Context = createContext<ReturnType<typeof init>>()
 function init() {
   const [store, setStore] = createSignal<
     {
+      id: string
       element: DialogElement
       onClose?: () => void
       owner: Owner
@@ -45,11 +46,13 @@ function init() {
       for (const item of store()) {
         item.onClose?.()
       }
+      const id = Math.random().toString(36)
       setStore([
         {
+          id,
           element: () =>
             runWithOwner(owner, () => (
-              <Show when={result.stack.at(-1)?.owner === owner}>
+              <Show when={result.stack.at(-1)?.id === id}>
                 <Kobalte
                   modal
                   defaultOpen
@@ -79,11 +82,15 @@ function init() {
       setStore([])
     },
   }
+
   return result
 }
 
 export function DialogProvider(props: ParentProps) {
   const ctx = init()
+  createEffect(() => {
+    console.log("store", ctx.stack.length)
+  })
   return (
     <Context.Provider value={ctx}>
       {props.children}