@@ -31,6 +31,7 @@ import {
3131 shallowRef ,
3232 watch ,
3333 watchEffect ,
34+ nextTick ,
3435} from 'vue' ;
3536import initDefaultProps from '../_util/props-util/initDefaultProps' ;
3637import type { CheckInfo , DraggableFn } from './props' ;
@@ -246,6 +247,26 @@ export default defineComponent({
246247 const scrollTo : ScrollTo = scroll => {
247248 listRef . value . scrollTo ( scroll ) ;
248249 } ;
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+ ) ;
249270 // =========================== Expanded ===========================
250271 /** Set uncontrolled `expandedKeys`. This will also auto update `flattenNodes`. */
251272 const setExpandedKeys = ( keys : Key [ ] ) => {
@@ -270,16 +291,14 @@ export default defineComponent({
270291 currentMouseOverDroppableNodeKey = null ;
271292 } ;
272293 // 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 ) => {
274295 const { onDragend } = props ;
275296
276297 dragState . dragOverNodeKey = null ;
277298
278299 cleanDragState ( ) ;
279300
280- if ( onDragend && ! outsideTree ) {
281- onDragend ( { event, node : node . eventData } ) ;
282- }
301+ onDragend ?.( { event, node : node . eventData } ) ;
283302
284303 dragNode = null ;
285304 } ;
@@ -552,8 +571,8 @@ export default defineComponent({
552571 dropPosition : dropPosition + Number ( posArr [ posArr . length - 1 ] ) ,
553572 } ;
554573
555- if ( onDrop && ! outsideTree ) {
556- onDrop ( dropResult ) ;
574+ if ( ! outsideTree ) {
575+ onDrop ?. ( dropResult ) ;
557576 }
558577
559578 dragNode = null ;
@@ -865,8 +884,9 @@ export default defineComponent({
865884 if ( activeKey . value === newActiveKey ) {
866885 return ;
867886 }
868-
869- activeKey . value = newActiveKey ;
887+ if ( props . activeKey !== undefined ) {
888+ activeKey . value = newActiveKey ;
889+ }
870890 if ( newActiveKey !== null ) {
871891 scrollTo ( { key : newActiveKey } ) ;
872892 }
0 commit comments