@@ -31,6 +31,7 @@ import {
31
31
shallowRef ,
32
32
watch ,
33
33
watchEffect ,
34
+ nextTick ,
34
35
} from 'vue' ;
35
36
import initDefaultProps from '../_util/props-util/initDefaultProps' ;
36
37
import type { CheckInfo , DraggableFn } from './props' ;
@@ -246,6 +247,26 @@ export default defineComponent({
246
247
const scrollTo : ScrollTo = scroll => {
247
248
listRef . value . scrollTo ( scroll ) ;
248
249
} ;
250
+ watch (
251
+ ( ) => props . activeKey ,
252
+ ( ) => {
253
+ if ( props . activeKey !== undefined ) {
254
+ activeKey . value = props . activeKey ;
255
+ }
256
+ } ,
257
+ { immediate : true } ,
258
+ ) ;
259
+ watch (
260
+ activeKey ,
261
+ val => {
262
+ nextTick ( ( ) => {
263
+ if ( val !== null ) {
264
+ scrollTo ( { key : val } ) ;
265
+ }
266
+ } ) ;
267
+ } ,
268
+ { immediate : true , flush : 'post' } ,
269
+ ) ;
249
270
// =========================== Expanded ===========================
250
271
/** Set uncontrolled `expandedKeys`. This will also auto update `flattenNodes`. */
251
272
const setExpandedKeys = ( keys : Key [ ] ) => {
@@ -270,16 +291,14 @@ export default defineComponent({
270
291
currentMouseOverDroppableNodeKey = null ;
271
292
} ;
272
293
// if onNodeDragEnd is called, onWindowDragEnd won't be called since stopPropagation() is called
273
- const onNodeDragEnd : NodeDragEventHandler = ( event , node , outsideTree = false ) => {
294
+ const onNodeDragEnd : NodeDragEventHandler = ( event , node ) => {
274
295
const { onDragend } = props ;
275
296
276
297
dragState . dragOverNodeKey = null ;
277
298
278
299
cleanDragState ( ) ;
279
300
280
- if ( onDragend && ! outsideTree ) {
281
- onDragend ( { event, node : node . eventData } ) ;
282
- }
301
+ onDragend ?.( { event, node : node . eventData } ) ;
283
302
284
303
dragNode = null ;
285
304
} ;
@@ -552,8 +571,8 @@ export default defineComponent({
552
571
dropPosition : dropPosition + Number ( posArr [ posArr . length - 1 ] ) ,
553
572
} ;
554
573
555
- if ( onDrop && ! outsideTree ) {
556
- onDrop ( dropResult ) ;
574
+ if ( ! outsideTree ) {
575
+ onDrop ?. ( dropResult ) ;
557
576
}
558
577
559
578
dragNode = null ;
@@ -865,8 +884,9 @@ export default defineComponent({
865
884
if ( activeKey . value === newActiveKey ) {
866
885
return ;
867
886
}
868
-
869
- activeKey . value = newActiveKey ;
887
+ if ( props . activeKey !== undefined ) {
888
+ activeKey . value = newActiveKey ;
889
+ }
870
890
if ( newActiveKey !== null ) {
871
891
scrollTo ( { key : newActiveKey } ) ;
872
892
}
0 commit comments