@@ -39,24 +39,28 @@ export const watchFocusing = (parent: IDropdownRenderlessParams['parent']) => (v
3939}
4040
4141export const show =
42- ( { props, state } : Pick < IDropdownRenderlessParams , 'props' | 'state' > ) =>
42+ ( { props, state, emit } : Pick < IDropdownRenderlessParams , 'props' | 'state' | 'emit '> ) =>
4343 ( ) => {
4444 if ( props . disabled ) {
4545 return
4646 }
4747
48- clearTimeout ( Number ( state . timeout ) )
49-
50- state . timeout = setTimeout (
51- ( ) => {
52- state . visible = true
53- } ,
54- state . trigger === 'click' ? 0 : props . showTimeout
55- )
48+ if ( state . visibleIsBoolean ) {
49+ emit ( 'update:visible' , true )
50+ } else {
51+ clearTimeout ( Number ( state . timeout ) )
52+
53+ state . timeout = setTimeout (
54+ ( ) => {
55+ state . visible = true
56+ } ,
57+ state . trigger === 'click' ? 0 : props . showTimeout
58+ )
59+ }
5660 }
5761
5862export const hide =
59- ( { api, props, state } : Pick < IDropdownRenderlessParams , 'api' | 'props' | 'state' > ) =>
63+ ( { api, props, state, emit } : Pick < IDropdownRenderlessParams , 'api' | 'props' | 'state' | 'emit '> ) =>
6064 ( ) => {
6165 if ( props . disabled ) {
6266 return
@@ -68,14 +72,18 @@ export const hide =
6872 api . resetTabindex ( state . triggerElm )
6973 }
7074
71- clearTimeout ( Number ( state . timeout ) )
72-
73- state . timeout = setTimeout (
74- ( ) => {
75- state . visible = false
76- } ,
77- state . trigger === 'click' ? 0 : props . hideTimeout
78- )
75+ if ( state . visibleIsBoolean ) {
76+ emit ( 'update:visible' , false )
77+ } else {
78+ clearTimeout ( Number ( state . timeout ) )
79+
80+ state . timeout = setTimeout (
81+ ( ) => {
82+ state . visible = false
83+ } ,
84+ state . trigger === 'click' ? 0 : props . hideTimeout
85+ )
86+ }
7987 }
8088
8189export const handleClick =
@@ -85,9 +93,12 @@ export const handleClick =
8593 return
8694 }
8795
88- emit ( 'handle-click' , state . visible )
89-
90- state . visible ? api . hide ( ) : api . show ( )
96+ if ( state . visibleIsBoolean ) {
97+ emit ( 'handle-click' , props . visible )
98+ } else {
99+ emit ( 'handle-click' , state . visible )
100+ state . visible ? api . hide ( ) : api . show ( )
101+ }
91102 }
92103
93104export const handleTriggerKeyDown =
@@ -112,7 +123,7 @@ export const handleTriggerKeyDown =
112123 }
113124
114125export const handleItemKeyDown =
115- ( { api, props, state } : Pick < IDropdownRenderlessParams , 'api' | 'props' | 'state' > ) =>
126+ ( { api, props, state, emit } : Pick < IDropdownRenderlessParams , 'api' | 'props' | 'state' | 'emit '> ) =>
116127 ( event : KeyboardEvent ) => {
117128 const keyCode = event . keyCode
118129 const target = event . target
@@ -199,6 +210,10 @@ export const initEvent =
199210 on ( state . triggerElm , 'click' , api . toggleFocusOnFalse )
200211 }
201212
213+ if ( state . visibleIsBoolean ) {
214+ return
215+ }
216+
202217 if ( state . trigger === 'hover' ) {
203218 on ( state . triggerElm , 'mouseenter' , api . show )
204219 on ( state . triggerElm , 'mouseleave' , api . hide )
@@ -262,7 +277,9 @@ export const mounted =
262277 vm . $on ( 'selected-index' , ( selectedIndex ) => {
263278 broadcast ( 'TinyDropdownMenu' , 'menu-selected-index' , selectedIndex )
264279 } )
265- vm . $on ( 'is-disabled' , api . clickOutside )
280+ if ( ! state . visibleIsBoolean ) {
281+ vm . $on ( 'is-disabled' , api . clickOutside )
282+ }
266283 }
267284
268285export const beforeDistory =
0 commit comments