File tree Expand file tree Collapse file tree 5 files changed +34
-4
lines changed
docs/src/lib/content/api-reference Expand file tree Collapse file tree 5 files changed +34
-4
lines changed Original file line number Diff line number Diff line change 1+ ---
2+ " bits-ui " : minor
3+ ---
4+
5+ feat(Menu): expose ` openDelay ` prop on ` *Menu.SubTrigger ` to control open delay
Original file line number Diff line number Diff line change @@ -59,6 +59,7 @@ import {
5959 defineSimpleDataAttr ,
6060 defineStringProp ,
6161 defineSimplePropSchema ,
62+ defineNumberProp ,
6263} from "../utils.js" ;
6364
6465const sharedItemProps = {
@@ -242,6 +243,11 @@ const subTriggerProps = {
242243 default : false ,
243244 description : "Whether or not the submenu trigger is disabled." ,
244245 } ) ,
246+ openDelay : defineNumberProp ( {
247+ default : 100 ,
248+ description :
249+ "The amount of time in ms from when the mouse enters the subtrigger until the submenu opens." ,
250+ } ) ,
245251 ...omit ( sharedItemProps , "closeOnSelect" ) ,
246252} satisfies PropObj < DropdownMenuSubTriggerPropsWithoutHTML > ;
247253
Original file line number Diff line number Diff line change 1515 children,
1616 child,
1717 onSelect = noop ,
18+ openDelay = 100 ,
1819 ... restProps
1920 }: MenuSubTriggerProps = $props ();
2021
2627 () => ref ,
2728 (v ) => (ref = v )
2829 ),
30+ openDelay: boxWith (() => openDelay ),
2931 });
3032
3133 const mergedProps = $derived (mergeProps (restProps , subTriggerState .props ));
Original file line number Diff line number Diff line change 99 type WritableBoxedValues ,
1010 simpleBox ,
1111 boxWith ,
12+ type ReadableBox ,
1213} from "svelte-toolbelt" ;
1314import { Context , watch } from "runed" ;
1415import {
@@ -609,7 +610,9 @@ export class MenuItemState {
609610
610611interface MenuSubTriggerStateOpts
611612 extends MenuItemSharedStateOpts ,
612- Pick < MenuItemStateOpts , "onSelect" > { }
613+ Pick < MenuItemStateOpts , "onSelect" > {
614+ openDelay : ReadableBox < number > ;
615+ }
613616
614617export class MenuSubTriggerState {
615618 static create ( opts : MenuSubTriggerStateOpts ) {
@@ -664,7 +667,7 @@ export class MenuSubTriggerState {
664667 this . #openTimer = this . content . domContext . setTimeout ( ( ) => {
665668 this . submenu . onOpen ( ) ;
666669 this . #clearOpenTimer( ) ;
667- } , 100 ) ;
670+ } , this . opts . openDelay . current ) ;
668671 }
669672 }
670673
Original file line number Diff line number Diff line change @@ -223,8 +223,22 @@ export type MenuSubContentStaticPropsWithoutHTML = Expand<
223223export type MenuSubContentStaticProps = MenuSubContentStaticPropsWithoutHTML &
224224 Without < BitsPrimitiveDivAttributes , MenuSubContentStaticPropsWithoutHTML > ;
225225
226- export type MenuSubTriggerPropsWithoutHTML = Omit < MenuItemPropsWithoutHTML , "closeOnSelect" > ;
227- export type MenuSubTriggerProps = Omit < MenuItemProps , "closeOnSelect" > ;
226+ export type MenuSubTriggerPropsWithoutHTML = Omit < MenuItemPropsWithoutHTML , "closeOnSelect" > & {
227+ /**
228+ * The amount of time in ms from when the mouse enters the subtrigger until
229+ * the submenu opens. This is useful for preventing the submenu from opening
230+ * as a user is moving their mouse through the menu without a true intention to open that
231+ * submenu.
232+ *
233+ * To disable the behavior, set it to `0`.
234+ *
235+ * @default 100
236+ */
237+ openDelay ?: number ;
238+ } ;
239+
240+ export type MenuSubTriggerProps = MenuSubTriggerPropsWithoutHTML &
241+ Without < BitsPrimitiveDivAttributes , MenuSubTriggerPropsWithoutHTML > ;
228242
229243export type MenuSeparatorPropsWithoutHTML = WithChild ;
230244export type MenuSeparatorProps = MenuSeparatorPropsWithoutHTML &
You can’t perform that action at this time.
0 commit comments