File tree 7 files changed +406
-17
lines changed
7 files changed +406
-17
lines changed Original file line number Diff line number Diff line change
1
+ <script lang =" ts" >
2
+ </script >
Original file line number Diff line number Diff line change
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 }
Original file line number Diff line number Diff line change 15
15
... restProps
16
16
}: NavigationMenuTriggerProps = $props ();
17
17
18
- let focusProxyMounted = $state (false );
19
-
20
18
const triggerState = useNavigationMenuTrigger ({
21
19
id: box .with (() => id ),
22
20
disabled: box .with (() => disabled ?? false ),
23
21
ref: box .with (
24
22
() => ref ,
25
23
(v ) => (ref = v )
26
24
),
27
- focusProxyMounted: box .with (() => focusProxyMounted ),
28
25
});
29
26
30
27
const mergedProps = $derived (mergeProps (restProps , triggerState .props ));
39
36
{/if }
40
37
41
38
{#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 >
46
43
{/if }
47
44
{/if }
Original file line number Diff line number Diff line change @@ -16,4 +16,5 @@ export type {
16
16
NavigationMenuIndicatorProps as IndicatorProps ,
17
17
NavigationMenuContentProps as ContentProps ,
18
18
NavigationMenuLinkProps as LinkProps ,
19
+ NavigationMenuSubProps as SubProps ,
19
20
} from "./types.js" ;
You can’t perform that action at this time.
0 commit comments