| 77 | }, [embedded]); |
| 78 | const close = () => { if (pending.current) return; if (count) setConfirmClose(true); else onClose(); }; |
| 79 | const keyDown = (event: KeyboardEvent<HTMLDivElement>) => { |
| 80 | if (event.key === 'Escape') { event.stopPropagation(); close(); } |
| 81 | if (event.key !== 'Tab') return; |
| 82 | const focusable = [...(dialog.current?.querySelectorAll<HTMLElement>('button:not(:disabled), input:not(:disabled), select:not(:disabled), summary, [tabindex="0"]') ?? [])].filter(element => element.getClientRects().length); |
| 83 | const first = focusable[0], last = focusable.at(-1); |
| 84 | if (!first) { event.preventDefault(); return; } |
| 85 | if (event.shiftKey && (document.activeElement === first || document.activeElement === dialog.current)) { event.preventDefault(); last?.focus(); } |
| 86 | else if (!event.shiftKey && document.activeElement === last) { event.preventDefault(); first.focus(); } |
| 87 | }; |
| 88 | const save = async () => { |
| 89 | if (!snapshot || pending.current || !count || invalid) return; |
| 90 | pending.current = true; setSaving(true); setError(''); setNotice(''); |