Fix Dialog activation and role
Replace onMount+onCleanup with createEffect watching ctx.isOpen() and ctx.modal(), so focusTrap/scrollLock/dismiss activate/deactivate reactively on every open/close — including when forceMount keeps the component mounted. Note: role="dialog" was omitted; the project's Biome rules flag it as redundant (noRedundantRoles) since <dialog> carries the implicit role.
This commit is contained in:
parent
69068fbee9
commit
87af246d71
@ -1,6 +1,6 @@
|
||||
// packages/core/src/components/dialog/dialog-content.tsx
|
||||
import type { JSX } from "solid-js";
|
||||
import { Show, onCleanup, onMount, splitProps } from "solid-js";
|
||||
import { Show, createEffect, onCleanup, splitProps } from "solid-js";
|
||||
import { createDismiss } from "../../utilities/dismiss/create-dismiss";
|
||||
import { createFocusTrap } from "../../utilities/focus-trap/create-focus-trap";
|
||||
import { Portal } from "../../utilities/portal/portal";
|
||||
@ -42,19 +42,22 @@ export function DialogContent(props: DialogContentProps): JSX.Element {
|
||||
onDismiss: () => ctx.setOpen(false),
|
||||
});
|
||||
|
||||
onMount(() => {
|
||||
createEffect(() => {
|
||||
if (ctx.isOpen() && ctx.modal()) {
|
||||
focusTrap.activate();
|
||||
scrollLock.lock();
|
||||
dismiss.attach();
|
||||
} else {
|
||||
focusTrap.deactivate();
|
||||
scrollLock.unlock();
|
||||
dismiss.detach();
|
||||
}
|
||||
});
|
||||
|
||||
onCleanup(() => {
|
||||
focusTrap.deactivate();
|
||||
scrollLock.unlock();
|
||||
dismiss.detach();
|
||||
});
|
||||
});
|
||||
|
||||
return (
|
||||
<Show when={local.forceMount || ctx.isOpen()}>
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user