1
- import { provide } from 'vue' ;
1
+ import { provide , reactive , watchEffect } from 'vue' ;
2
2
import BaseMixin from '../../_util/BaseMixin' ;
3
3
import PropTypes from '../../_util/vue-types' ;
4
4
import raf from 'raf' ;
5
5
import KeyCode from './KeyCode' ;
6
- import { getOptionProps } from '../../_util/props-util' ;
7
6
import { cloneElement } from '../../_util/vnode' ;
8
7
import Sentinel from './Sentinel' ;
9
8
import isValid from '../../_util/isValid' ;
@@ -40,43 +39,42 @@ export default {
40
39
tabBarPosition : PropTypes . string . def ( 'top' ) ,
41
40
activeKey : PropTypes . oneOfType ( [ PropTypes . string , PropTypes . number ] ) ,
42
41
defaultActiveKey : PropTypes . oneOfType ( [ PropTypes . string , PropTypes . number ] ) ,
43
- __propsSymbol__ : PropTypes . any ,
44
42
direction : PropTypes . string . def ( 'ltr' ) ,
45
43
tabBarGutter : PropTypes . number ,
46
44
} ,
47
- data ( ) {
48
- provide ( 'sentinelContext' , this ) ;
49
- const props = getOptionProps ( this ) ;
45
+ setup ( props ) {
50
46
let activeKey ;
51
- if ( ' activeKey' in props ) {
47
+ if ( props . activeKey !== undefined ) {
52
48
activeKey = props . activeKey ;
53
- } else if ( ' defaultActiveKey' in props ) {
49
+ } else if ( props . defaultActiveKey !== undefined ) {
54
50
activeKey = props . defaultActiveKey ;
55
51
} else {
56
52
activeKey = getDefaultActiveKey ( props ) ;
57
53
}
54
+ const state = reactive ( {
55
+ _activeKey : activeKey ,
56
+ } ) ;
57
+ watchEffect (
58
+ ( ) => {
59
+ if ( props . activeKey !== undefined ) {
60
+ state . _activeKey = props . activeKey ;
61
+ } else if ( ! activeKeyIsValid ( props , state . _activeKey ) ) {
62
+ // https://github.com/ant-design/ant-design/issues/7093
63
+ state . _activeKey = getDefaultActiveKey ( props ) ;
64
+ }
65
+ } ,
66
+ {
67
+ flush : 'sync' ,
68
+ } ,
69
+ ) ;
70
+ return { state } ;
71
+ } ,
72
+ created ( ) {
58
73
this . panelSentinelStart = undefined ;
59
74
this . panelSentinelEnd = undefined ;
60
75
this . sentinelStart = undefined ;
61
76
this . sentinelEnd = undefined ;
62
- return {
63
- _activeKey : activeKey ,
64
- } ;
65
- } ,
66
- watch : {
67
- __propsSymbol__ ( ) {
68
- const nextProps = getOptionProps ( this ) ;
69
- if ( 'activeKey' in nextProps ) {
70
- this . setState ( {
71
- _activeKey : nextProps . activeKey ,
72
- } ) ;
73
- } else if ( ! activeKeyIsValid ( nextProps , this . $data . _activeKey ) ) {
74
- // https://github.com/ant-design/ant-design/issues/7093
75
- this . setState ( {
76
- _activeKey : getDefaultActiveKey ( nextProps ) ,
77
- } ) ;
78
- }
79
- } ,
77
+ provide ( 'sentinelContext' , this ) ;
80
78
} ,
81
79
beforeUnmount ( ) {
82
80
this . destroy = true ;
@@ -133,20 +131,18 @@ export default {
133
131
} ,
134
132
135
133
setActiveKey ( activeKey ) {
136
- if ( this . $data . _activeKey !== activeKey ) {
137
- const props = getOptionProps ( this ) ;
138
- if ( ! ( 'activeKey' in props ) ) {
139
- this . setState ( {
140
- _activeKey : activeKey ,
141
- } ) ;
134
+ if ( this . state . _activeKey !== activeKey ) {
135
+ const props = this . $props ;
136
+ if ( props . activeKey === undefined ) {
137
+ this . state . _activeKey = activeKey ;
142
138
}
143
139
this . __emit ( 'update:activeKey' , activeKey ) ;
144
140
this . __emit ( 'change' , activeKey ) ;
145
141
}
146
142
} ,
147
143
148
144
getNextActiveKey ( next ) {
149
- const activeKey = this . $data . _activeKey ;
145
+ const activeKey = this . state . _activeKey ;
150
146
const children = [ ] ;
151
147
this . $props . children . forEach ( c => {
152
148
if ( c && ! c . disabled && c . disabled !== '' ) {
@@ -206,7 +202,7 @@ export default {
206
202
navWrapper,
207
203
tabBarPosition,
208
204
panels : props . children ,
209
- activeKey : this . $data . _activeKey ,
205
+ activeKey : this . state . _activeKey ,
210
206
direction,
211
207
tabBarGutter,
212
208
onKeydown : this . onNavKeyDown ,
@@ -216,7 +212,7 @@ export default {
216
212
const tabContent = cloneElement ( renderTabContent ( ) , {
217
213
prefixCls,
218
214
tabBarPosition,
219
- activeKey : this . $data . _activeKey ,
215
+ activeKey : this . state . _activeKey ,
220
216
destroyInactiveTabPane,
221
217
direction,
222
218
onChange : this . setActiveKey ,
0 commit comments