Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

next: fix various floating forceMount issues #844

Merged
merged 6 commits into from
Oct 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/cool-cats-compete.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"bits-ui": patch
---

fix: Combobox `forceMount`
5 changes: 5 additions & 0 deletions .changeset/itchy-drinks-explode.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"bits-ui": patch
---

fix: Tooltip `forceMount`
5 changes: 5 additions & 0 deletions .changeset/olive-ads-enjoy.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"bits-ui": patch
---

fix: DropdownMenu & ContextMenu `forceMount`
5 changes: 5 additions & 0 deletions .changeset/olive-worms-bow.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"bits-ui": patch
---

fix: Select `forceMount`
5 changes: 5 additions & 0 deletions .changeset/stale-weeks-ring.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"bits-ui": patch
---

fix: popover `forceMount`
5 changes: 5 additions & 0 deletions .changeset/wet-beds-hunt.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"bits-ui": patch
---

fix: LinkPreview `forceMount`
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
<script lang="ts">
import { box, mergeProps } from "svelte-toolbelt";
import type { ContextMenuContentStaticProps } from "../types.js";
import type { ContextMenuContentProps } from "../types.js";
import { CONTEXT_MENU_TRIGGER_ATTR, useMenuContent } from "$lib/bits/menu/menu.svelte.js";
import { useId } from "$lib/internal/use-id.js";
import { noop } from "$lib/internal/noop.js";
import PopperLayer from "$lib/bits/utilities/popper-layer/popper-layer.svelte";
import Mounted from "$lib/bits/utilities/mounted.svelte";
import { getFloatingContentCSSVars } from "$lib/internal/floating-svelte/floating-utils.svelte.js";
import PopperLayerForceMount from "$lib/bits/utilities/popper-layer/popper-layer-force-mount.svelte";

let {
id = useId(),
Expand All @@ -20,7 +22,7 @@
onEscapeKeydown = noop,
forceMount = false,
...restProps
}: ContextMenuContentStaticProps = $props();
}: ContextMenuContentProps = $props();

let isMounted = $state(false);

Expand All @@ -35,24 +37,20 @@
});

const mergedProps = $derived(mergeProps(restProps, contentState.props));
</script>

<PopperLayer
isStatic={true}
{...mergedProps}
present={contentState.parentMenu.open.current || forceMount}
{preventScroll}
onInteractOutside={(e) => {
function handleInteractOutside(e: PointerEvent) {
onInteractOutside(e);
if (e.defaultPrevented) return;
contentState.parentMenu.onClose();
}}
onEscapeKeydown={(e) => {
}

function handleEscapeKeydown(e: KeyboardEvent) {
onEscapeKeydown(e);
if (e.defaultPrevented) return;
contentState.parentMenu.onClose();
}}
isValidEvent={(e) => {
}

function isValidEvent(e: PointerEvent) {
if ("button" in e && e.button === 2) {
const target = e.target as HTMLElement;
if (!target) return false;
Expand All @@ -62,17 +60,69 @@
return isAnotherContextTrigger;
}
return false;
}}
{loop}
>
{#snippet popper({ props })}
{#if child}
{@render child({ props, ...contentState.snippetProps })}
{:else}
<div {...props}>
{@render children?.()}
</div>
{/if}
<Mounted bind:isMounted />
{/snippet}
</PopperLayer>
}
</script>

{#if forceMount}
<PopperLayerForceMount
{...mergedProps}
isStatic
side="right"
sideOffset={2}
align="start"
enabled={contentState.parentMenu.open.current}
{preventScroll}
onInteractOutside={handleInteractOutside}
onEscapeKeydown={handleEscapeKeydown}
{isValidEvent}
trapFocus
{loop}
{forceMount}
{id}
>
{#snippet popper({ props })}
{@const finalProps = mergeProps(props, {
style: getFloatingContentCSSVars("context-menu"),
})}
{#if child}
{@render child({ props: finalProps, ...contentState.snippetProps })}
{:else}
<div {...finalProps}>
{@render children?.()}
</div>
{/if}
<Mounted bind:isMounted />
{/snippet}
</PopperLayerForceMount>
{:else if !forceMount}
<PopperLayer
{...mergedProps}
isStatic
side="right"
sideOffset={2}
align="start"
present={contentState.parentMenu.open.current}
{preventScroll}
onInteractOutside={handleInteractOutside}
onEscapeKeydown={handleEscapeKeydown}
{isValidEvent}
trapFocus
{loop}
forceMount={false}
{id}
>
{#snippet popper({ props })}
{@const finalProps = mergeProps(props, {
style: getFloatingContentCSSVars("context-menu"),
})}
{#if child}
{@render child({ props: finalProps, ...contentState.snippetProps })}
{:else}
<div {...finalProps}>
{@render children?.()}
</div>
{/if}
<Mounted bind:isMounted />
{/snippet}
</PopperLayer>
{/if}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import PopperLayer from "$lib/bits/utilities/popper-layer/popper-layer.svelte";
import Mounted from "$lib/bits/utilities/mounted.svelte";
import { getFloatingContentCSSVars } from "$lib/internal/floating-svelte/floating-utils.svelte.js";
import PopperLayerForceMount from "$lib/bits/utilities/popper-layer/popper-layer-force-mount.svelte";

let {
id = useId(),
Expand Down Expand Up @@ -36,26 +37,20 @@
});

const mergedProps = $derived(mergeProps(restProps, contentState.props));
</script>

<PopperLayer
{...mergedProps}
side="right"
sideOffset={2}
align="start"
present={contentState.parentMenu.open.current || forceMount}
{preventScroll}
onInteractOutside={(e) => {
function handleInteractOutside(e: PointerEvent) {
onInteractOutside(e);
if (e.defaultPrevented) return;
contentState.parentMenu.onClose();
}}
onEscapeKeydown={(e) => {
}

function handleEscapeKeydown(e: KeyboardEvent) {
onEscapeKeydown(e);
if (e.defaultPrevented) return;
contentState.parentMenu.onClose();
}}
isValidEvent={(e) => {
}

function isValidEvent(e: PointerEvent) {
if ("button" in e && e.button === 2) {
const target = e.target as HTMLElement;
if (!target) return false;
Expand All @@ -65,21 +60,65 @@
return isAnotherContextTrigger;
}
return false;
}}
trapFocus
{loop}
>
{#snippet popper({ props })}
{@const finalProps = mergeProps(props, {
style: getFloatingContentCSSVars("context-menu"),
})}
{#if child}
{@render child({ props: finalProps, ...contentState.snippetProps })}
{:else}
<div {...finalProps}>
{@render children?.()}
</div>
{/if}
<Mounted bind:isMounted />
{/snippet}
</PopperLayer>
}
</script>

{#if forceMount}
<PopperLayerForceMount
{...mergedProps}
side="right"
sideOffset={2}
align="start"
enabled={contentState.parentMenu.open.current}
{preventScroll}
onInteractOutside={handleInteractOutside}
onEscapeKeydown={handleEscapeKeydown}
{isValidEvent}
trapFocus
{loop}
{id}
>
{#snippet popper({ props })}
{@const finalProps = mergeProps(props, {
style: getFloatingContentCSSVars("context-menu"),
})}
{#if child}
{@render child({ props: finalProps, ...contentState.snippetProps })}
{:else}
<div {...finalProps}>
{@render children?.()}
</div>
{/if}
<Mounted bind:isMounted />
{/snippet}
</PopperLayerForceMount>
{:else if !forceMount}
<PopperLayer
{...mergedProps}
side="right"
sideOffset={2}
align="start"
present={contentState.parentMenu.open.current}
{preventScroll}
onInteractOutside={handleInteractOutside}
onEscapeKeydown={handleEscapeKeydown}
{isValidEvent}
trapFocus
{loop}
{id}
>
{#snippet popper({ props })}
{@const finalProps = mergeProps(props, {
style: getFloatingContentCSSVars("context-menu"),
})}
{#if child}
{@render child({ props: finalProps, ...contentState.snippetProps })}
{:else}
<div {...finalProps}>
{@render children?.()}
</div>
{/if}
<Mounted bind:isMounted />
{/snippet}
</PopperLayer>
{/if}
Loading