@@ -69,6 +69,16 @@ export default {
69
69
return false ;
70
70
},
71
71
},
72
+ /**
73
+ * Passing a string value will enable `controlled mode`.
74
+ * In this mode, the `activeTab` is used by the parent component to control which tab is active.
75
+ *
76
+ * When `null`, the component will manage the active tab internally.
77
+ */
78
+ activeTab: {
79
+ type: [String , null ],
80
+ default: null ,
81
+ },
72
82
},
73
83
data () {
74
84
return {
@@ -83,7 +93,11 @@ export default {
83
93
* @param {String} tabId
84
94
*/
85
95
setCurrentTab (tabId ) {
86
- this .currentTab = tabId;
96
+ if (this .activeTab === null ) {
97
+ this .currentTab = tabId;
98
+ } else {
99
+ this .$emit (' update:activeTab' , tabId);
100
+ }
87
101
this .$nextTick (() => {
88
102
$ (this .$refs [' button' + tabId]).focus ();
89
103
this .updateUrl ();
@@ -155,6 +169,14 @@ export default {
155
169
currentTab (newVal , oldVal ) {
156
170
this .tabs .forEach ((tab ) => tab .isActive (tab .id === newVal));
157
171
},
172
+ /**
173
+ * In controlled mode, when the `activeTab` prop changes, update the current tab.
174
+ */
175
+ activeTab (newVal ) {
176
+ if (newVal !== null ) {
177
+ this .currentTab = newVal;
178
+ }
179
+ },
158
180
},
159
181
provide () {
160
182
return {
@@ -176,7 +198,11 @@ export default {
176
198
/**
177
199
* Set the tab to view when loaded
178
200
*/
179
- this .currentTab = this .defaultTab || this .tabs [0 ].id ;
201
+ const initialTab =
202
+ this .activeTab !== null
203
+ ? this .activeTab
204
+ : this .defaultTab || this .tabs [0 ]? .id || ' ' ;
205
+ this .currentTab = initialTab;
180
206
181
207
/**
182
208
* Listen for global 'open-tab' events and open the correct tab when called
0 commit comments