Skip to content

Commit d2314e1

Browse files
committed
more
1 parent 5da705d commit d2314e1

File tree

7 files changed

+406
-17
lines changed

7 files changed

+406
-17
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
<script lang="ts">
2+
</script>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
<script lang="ts">
2+
import { box, mergeProps } from "svelte-toolbelt";
3+
import type { NavigationMenuSubProps } from "../types.js";
4+
import { useNavigationMenuSub } from "../navigation-menu.svelte.js";
5+
import { useId } from "$lib/internal/use-id.js";
6+
import { noop } from "$lib/internal/noop.js";
7+
8+
let {
9+
child,
10+
children,
11+
id = useId(),
12+
ref = $bindable(null),
13+
value = $bindable(""),
14+
onValueChange = noop,
15+
orientation = "horizontal",
16+
controlledValue = false,
17+
...restProps
18+
}: NavigationMenuSubProps = $props();
19+
20+
const rootState = useNavigationMenuSub({
21+
id: box.with(() => id),
22+
value: box.with(
23+
() => value,
24+
(v) => {
25+
if (controlledValue) {
26+
onValueChange(v);
27+
} else {
28+
value = v;
29+
onValueChange(v);
30+
}
31+
}
32+
),
33+
orientation: box.with(() => orientation),
34+
ref: box.with(
35+
() => ref,
36+
(v) => (ref = v)
37+
),
38+
});
39+
40+
const mergedProps = $derived(mergeProps(restProps, rootState.props));
41+
</script>
42+
43+
{#if child}
44+
{@render child({ props: mergedProps })}
45+
{:else}
46+
<div {...mergedProps}>
47+
{@render children?.()}
48+
</div>
49+
{/if}

packages/bits-ui/src/lib/bits/navigation-menu-2/components/navigation-menu-trigger.svelte

+4-7
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,13 @@
1515
...restProps
1616
}: NavigationMenuTriggerProps = $props();
1717
18-
let focusProxyMounted = $state(false);
19-
2018
const triggerState = useNavigationMenuTrigger({
2119
id: box.with(() => id),
2220
disabled: box.with(() => disabled ?? false),
2321
ref: box.with(
2422
() => ref,
2523
(v) => (ref = v)
2624
),
27-
focusProxyMounted: box.with(() => focusProxyMounted),
2825
});
2926
3027
const mergedProps = $derived(mergeProps(restProps, triggerState.props));
@@ -39,9 +36,9 @@
3936
{/if}
4037

4138
{#if triggerState.open}
42-
<Mounted bind:isMounted={focusProxyMounted} />
43-
<VisuallyHidden {...triggerState.visuallyHiddenProps} />
44-
{#if triggerState.menu.viewportNode}
45-
<span aria-owns={triggerState.item.contentNode?.id ?? undefined}></span>
39+
<Mounted onMountedChange={(m) => (triggerState.focusProxyMounted = m)} />
40+
<VisuallyHidden {...triggerState.focusProxyProps} />
41+
{#if triggerState.context.viewportRef.current}
42+
<span aria-owns={triggerState.itemContext.contentId ?? undefined}></span>
4643
{/if}
4744
{/if}

packages/bits-ui/src/lib/bits/navigation-menu-2/exports.ts

+1
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,5 @@ export type {
1616
NavigationMenuIndicatorProps as IndicatorProps,
1717
NavigationMenuContentProps as ContentProps,
1818
NavigationMenuLinkProps as LinkProps,
19+
NavigationMenuSubProps as SubProps,
1920
} from "./types.js";

0 commit comments

Comments
 (0)