Skip to content

Commit

Permalink
cleanup tests
Browse files Browse the repository at this point in the history
  • Loading branch information
huntabyte committed Jul 22, 2024
1 parent 8d7b469 commit f196145
Show file tree
Hide file tree
Showing 43 changed files with 618 additions and 554 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
enabled={present.current}
onEscapeKeydown={(e) => {
onEscapeKeydown(e);
if (e.defaultPrevented) return;
contentState.root.closeDialog();
}}
>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@
contentState.root.closeMenu();
}}
onEscapeKeydown={(e) => {
// TODO: users should be able to cancel this
onEscapeKeydown(e);
if (e.defaultPrevented) return
contentState.root.closeMenu();
}}
onMountAutoFocus={(e) => e.preventDefault()}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@
contentState.parentMenu.onClose();
}}
onEscapeKeydown={(e) => {
// TODO: users should be able to cancel this
onEscapeKeydown(e);
if (e.defaultPrevented) return;
contentState.parentMenu.onClose();
}}
trapped
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
enabled={present.current}
onEscapeKeydown={(e) => {
onEscapeKeydown(e);
if (e.defaultPrevented) return
contentState.root.closeDialog();
}}
>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@
contentState.parentMenu.onClose();
}}
onEscapeKeydown={(e) => {
// TODO: users should be able to cancel this
onEscapeKeydown(e);
if (e.defaultPrevented) return;
contentState.parentMenu.onClose();
}}
trapped
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@
contentState.root.immediateClose();
}}
onEscapeKeydown={(e) => {
// TODO: users should be able to cancel this
onEscapeKeydown?.(e);
if (e.defaultPrevented) return;
contentState.root.immediateClose();
}}
onMountAutoFocus={(e) => e.preventDefault()}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@
contentState.parentMenu.onClose();
}}
onEscapeKeydown={(e) => {
// TODO: users should be able to cancel this
onEscapeKeydown(e);
if (e.defaultPrevented) return;
contentState.parentMenu.onClose();
}}
trapped
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@
onEscapeKeydown={(e) => {
// TODO: users should be able to cancel this
onEscapeKeydown(e);
if (e.defaultPrevented) return;
subContentState.parentMenu.onClose();
}}
onFocusOutside={(e) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@
ref = $bindable(null),
id = useId(),
forceMount = false,
onEscapeKeydown,
onInteractOutside,
onFocusOutside,
...restProps
}: ContentProps = $props();
Expand All @@ -42,13 +45,25 @@
{#snippet presence()}
<EscapeLayer
enabled={contentState.isPresent}
onEscapeKeydown={(e) => contentState.onEscapeKeydown(e)}
onEscapeKeydown={(e) => {
onEscapeKeydown?.(e);
if (e.defaultPrevented) return;
contentState.onEscapeKeydown(e);
}}
>
<DismissableLayer
enabled={contentState.isPresent}
{id}
onInteractOutside={contentState.onInteractOutside}
onFocusOutside={contentState.onFocusOutside}
onInteractOutside={(e) => {
onInteractOutside?.(e);
if (e.defaultPrevented) return;
contentState.onInteractOutside(e);
}}
onFocusOutside={(e) => {
onFocusOutside?.(e);
if (e.defaultPrevented) return;
contentState.onFocusOutside(e);
}}
>
{#snippet children({ props: dismissableProps })}
{#if child}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@
contentState.root.close();
}}
onEscapeKeydown={(e) => {
// TODO: users should be able to cancel this
onEscapeKeydown(e);
if (e.defaultPrevented) return
contentState.root.close();
}}
onDestroyAutoFocus={(e) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@
const contentState = context;
// eslint-disable-next-line unused-imports/no-unused-vars, ts/no-unused-vars
const { children, child, ...restWithoutChildren } = restProps;
const { children: _c, child: _ch, ...restWithoutChildren } = restProps;
</script>

<FocusScope
Expand All @@ -46,8 +45,8 @@
{...restWithoutChildren}
enabled={present}
onEscapeKeydown={(e) => {
// TODO: users should be able to cancel this
onEscapeKeydown(e);
if (e.defaultPrevented) return;
contentState.root.handleClose();
}}
>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@
contentState.root.handleClose();
}}
onEscapeKeydown={(e) => {
// TODO: users should be able to cancel this
onEscapeKeydown?.(e);
if (e.defaultPrevented) return;
contentState.root.handleClose();
}}
onMountAutoFocus={(e) => e.preventDefault()}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,11 @@ export class EscapeLayerState {

#onkeydown = (e: KeyboardEvent) => {
if (e.key !== kbd.ESCAPE || !isResponsibleEscapeLayer(this)) return;
const clonedEvent = new KeyboardEvent(e.type, e);
e.preventDefault();
const behaviorType = this.#behaviorType.current;
if (behaviorType !== "close" && behaviorType !== "defer-otherwise-close") return;
this.#onEscapeProp.current(e);
this.#onEscapeProp.current(clonedEvent);
};
}

Expand Down
Loading

0 comments on commit f196145

Please sign in to comment.