fix: (beta) double esc after file-show+menu didn't bring back to page
Massimo Melina committed
Mar 23, 2024 at 16:19 UTC
62332f6e56b5b3baf259d94ee430b15183356f6a
1 file changed
+3
shared/dialogs.ts
+3
@@ -25,6 +25,7 @@ export interface DialogOptions {
25
}
26
27
const dialogs = proxy<DialogOptions[]>([])
28
+const focusBak: (Element | null)[] = []
29
30
export const dialogsDefaults: Partial<DialogOptions> = {
31
closableProps: { children: 'x', 'aria-label': "Close", },
@@ -160,6 +161,7 @@ export function newDialog(options: DialogOptions) {
161
const ts = performance.now()
162
options.$id = $id // object identity is not working because of the proxy. This is a possible workaround
163
options.ts = ts
164
+ focusBak.push(document.activeElement) // saving this inside options object doesn't work (didn't dig enough to say why)
165
options = objSameKeys(options, x => isValidElement(x) ? ref(x) : x) as typeof options // encapsulate elements as react will try to write, but valtio makes them readonly
166
dialogs.push(options)
167
if (options.closable !== false)
@@ -191,5 +193,6 @@ export function closeDialog(v?:any, skipHistory=false) {
193
194
function closeDialogAt(i: number, value?: any) {
195
const [d] = dialogs.splice(i,1)
196
+ ;(focusBak.pop() as any)?.focus?.() // if element is not HTMLElement, it doesn't have focus method
197
return d?.onClose?.(value)
198
}
\ No newline at end of file