Blame view

src/components/tabs/tabs.vue 19.2 KB
871ed4d8   梁灏   init Tabs component
1
  <template>
17f52abf   梁灏   update Tabs
2
3
      <div :class="classes">
          <div :class="[prefixCls + '-bar']">
be3fbd24   marxy   Tabs add scroll
4
              <div :class="[prefixCls + '-nav-right']" v-if="showSlot"><slot name="extra"></slot></div>
7be1069a   Sergio Crisostomo   Add tab navigatio...
5
6
7
8
9
              <div
                  :class="[prefixCls + '-nav-container']"
                  tabindex="0"
                  ref="navContainer"
                  @keydown="handleTabKeyNavigation"
bb6efbaa   Aresn   Update tabs.vue
10
                  @keydown.space.prevent="handleTabKeyboardSelect(false)"
7be1069a   Sergio Crisostomo   Add tab navigatio...
11
              >
67a9c1cc   梁灏   update Tabs
12
                  <div ref="navWrap" :class="[prefixCls + '-nav-wrap', scrollable ? prefixCls + '-nav-scrollable' : '']">
7cd358c0   梁灏   update Tabs
13
14
                      <span :class="[prefixCls + '-nav-prev', scrollable ? '' : prefixCls + '-nav-scroll-disabled']" @click="scrollPrev"><Icon type="ios-arrow-back"></Icon></span>
                      <span :class="[prefixCls + '-nav-next', scrollable ? '' : prefixCls + '-nav-scroll-disabled']" @click="scrollNext"><Icon type="ios-arrow-forward"></Icon></span>
be3fbd24   marxy   Tabs add scroll
15
16
                      <div ref="navScroll" :class="[prefixCls + '-nav-scroll']">
                          <div ref="nav" :class="[prefixCls + '-nav']" class="nav-text"  :style="navStyle">
17f52abf   梁灏   update Tabs
17
                              <div :class="barClasses" :style="barStyle"></div>
30510c3d   梁灏   support Tabs
18
                              <div :class="tabCls(item)" v-for="(item, index) in navList" @click="handleChange(index)">
17f52abf   梁灏   update Tabs
19
                                  <Icon v-if="item.icon !== ''" :type="item.icon"></Icon>
1f974700   Aresn   Tabs support rend...
20
21
                                  <Render v-if="item.labelType === 'function'" :render="item.label"></Render>
                                  <template v-else>{{ item.label }}</template>
e71a795e   梁灏   update Tabs Icons
22
                                  <Icon v-if="showClose(item)" type="ios-close" @click.native.stop="handleRemove(index)"></Icon>
17f52abf   梁灏   update Tabs
23
24
                              </div>
                          </div>
17f52abf   梁灏   update Tabs
25
26
27
28
                      </div>
                  </div>
              </div>
          </div>
7be1069a   Sergio Crisostomo   Add tab navigatio...
29
          <div :class="contentClasses" :style="contentStyle" ref="panes"><slot></slot></div>
17f52abf   梁灏   update Tabs
30
      </div>
871ed4d8   梁灏   init Tabs component
31
32
  </template>
  <script>
17f52abf   梁灏   update Tabs
33
      import Icon from '../icon/icon.vue';
55dbf62d   Aresn   update Tabs render
34
      import Render from '../base/render';
4d8b4016   梁灏   update Tabs metho...
35
      import { oneOf, MutationObserver, findComponentsDownward } from '../../utils/assist';
67c9b1c8   梁灏   fixed #591
36
      import Emitter from '../../mixins/emitter';
be3fbd24   marxy   Tabs add scroll
37
      import elementResizeDetectorMaker from 'element-resize-detector';
17f52abf   梁灏   update Tabs
38
39
  
      const prefixCls = 'ivu-tabs';
7be1069a   Sergio Crisostomo   Add tab navigatio...
40
41
42
43
44
45
      const transitionTime = 300; // from CSS
  
      const getNextTab = (list, activeKey, direction, countDisabledAlso) => {
          const currentIndex = list.findIndex(tab => tab.name === activeKey);
          const nextIndex = (currentIndex + direction + list.length) % list.length;
          const nextTab = list[nextIndex];
45dbc6fd   Sergio Crisostomo   Correct disabled ...
46
          if (nextTab.disabled) return getNextTab(list, nextTab.name, direction, countDisabledAlso);
7be1069a   Sergio Crisostomo   Add tab navigatio...
47
48
49
50
51
          else return nextTab;
      };
  
      const focusFirst = (element, root) => {
          try {element.focus();}
2f40e7ea   Sergio Crisostomo   add eslint-disabl...
52
          catch(err) {} // eslint-disable-line no-empty
7be1069a   Sergio Crisostomo   Add tab navigatio...
53
54
55
56
57
58
59
60
61
  
          if (document.activeElement == element && element !== root) return true;
  
          const candidates = element.children;
          for (let candidate of candidates) {
              if (focusFirst(candidate, root)) return true;
          }
          return false;
      };
17f52abf   梁灏   update Tabs
62
  
871ed4d8   梁灏   init Tabs component
63
      export default {
30510c3d   梁灏   support Tabs
64
          name: 'Tabs',
67c9b1c8   梁灏   fixed #591
65
          mixins: [ Emitter ],
1f974700   Aresn   Tabs support rend...
66
          components: { Icon, Render },
4d8b4016   梁灏   update Tabs metho...
67
68
69
          provide () {
              return { TabsInstance: this };
          },
17f52abf   梁灏   update Tabs
70
          props: {
30510c3d   梁灏   support Tabs
71
              value: {
17f52abf   梁灏   update Tabs
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
                  type: [String, Number]
              },
              type: {
                  validator (value) {
                      return oneOf(value, ['line', 'card']);
                  },
                  default: 'line'
              },
              size: {
                  validator (value) {
                      return oneOf(value, ['small', 'default']);
                  },
                  default: 'default'
              },
              animated: {
                  type: Boolean,
                  default: true
              },
28026b3f   Sergio Crisostomo   Fix 3732 - add pr...
90
91
92
93
              captureFocus: {
                  type: Boolean,
                  default: false
              },
17f52abf   梁灏   update Tabs
94
95
96
              closable: {
                  type: Boolean,
                  default: false
753720d9   梁灏   Tabs add prop bef...
97
98
              },
              beforeRemove: Function,
26b2cfa0   梁灏   fixed #5377
99
100
101
102
              // Tabs 嵌套时,用 name 区分层级
              name: {
                  type: String
              },
17f52abf   梁灏   update Tabs
103
          },
871ed4d8   梁灏   init Tabs component
104
          data () {
17f52abf   梁灏   update Tabs
105
106
107
108
              return {
                  prefixCls: prefixCls,
                  navList: [],
                  barWidth: 0,
30510c3d   梁灏   support Tabs
109
                  barOffset: 0,
c4eb5dcf   H   tabs组件导航区添加右侧slot...
110
                  activeKey: this.value,
7be1069a   Sergio Crisostomo   Add tab navigatio...
111
                  focusedKey: this.value,
be3fbd24   marxy   Tabs add scroll
112
                  showSlot: false,
a730a849   梁灏   update Tabs
113
                  navStyle: {
be3fbd24   marxy   Tabs add scroll
114
115
                      transform: ''
                  },
7be1069a   Sergio Crisostomo   Add tab navigatio...
116
117
                  scrollable: false,
                  transitioning: false,
b0893113   jingsam   :art: add eslint
118
              };
17f52abf   梁灏   update Tabs
119
120
121
122
123
124
125
126
127
128
          },
          computed: {
              classes () {
                  return [
                      `${prefixCls}`,
                      {
                          [`${prefixCls}-card`]: this.type === 'card',
                          [`${prefixCls}-mini`]: this.size === 'small' && this.type === 'line',
                          [`${prefixCls}-no-animation`]: !this.animated
                      }
b0893113   jingsam   :art: add eslint
129
                  ];
17f52abf   梁灏   update Tabs
130
131
132
133
              },
              contentClasses () {
                  return [
                      `${prefixCls}-content`,
77bafb31   梁灏   update Tabs
134
135
136
                      {
                          [`${prefixCls}-content-animated`]: this.animated
                      }
b0893113   jingsam   :art: add eslint
137
                  ];
17f52abf   梁灏   update Tabs
138
139
140
141
              },
              barClasses () {
                  return [
                      `${prefixCls}-ink-bar`,
77bafb31   梁灏   update Tabs
142
143
144
                      {
                          [`${prefixCls}-ink-bar-animated`]: this.animated
                      }
b0893113   jingsam   :art: add eslint
145
                  ];
17f52abf   梁灏   update Tabs
146
147
              },
              contentStyle () {
e45d1bce   Sergio Crisostomo   fix too early vis...
148
                  const x = this.getTabIndex(this.activeKey);
17f52abf   梁灏   update Tabs
149
150
151
152
153
154
                  const p = x === 0 ? '0%' : `-${x}00%`;
  
                  let style = {};
                  if (x > -1) {
                      style = {
                          transform: `translateX(${p}) translateZ(0px)`
b0893113   jingsam   :art: add eslint
155
                      };
17f52abf   梁灏   update Tabs
156
157
158
159
160
                  }
                  return style;
              },
              barStyle () {
                  let style = {
3ce6b446   Sergio Crisostomo   Use visibility in...
161
                      visibility: 'hidden',
77bafb31   梁灏   update Tabs
162
                      width: `${this.barWidth}px`
17f52abf   梁灏   update Tabs
163
                  };
e906d570   Aresn   Update tabs.vue
164
                  if (this.type === 'line') style.visibility = 'visible';
77bafb31   梁灏   update Tabs
165
166
167
168
169
                  if (this.animated) {
                      style.transform = `translate3d(${this.barOffset}px, 0px, 0px)`;
                  } else {
                      style.left = `${this.barOffset}px`;
                  }
17f52abf   梁灏   update Tabs
170
171
172
173
174
175
  
                  return style;
              }
          },
          methods: {
              getTabs () {
4d8b4016   梁灏   update Tabs metho...
176
                  // return this.$children.filter(item => item.$options.name === 'TabPane');
26b2cfa0   梁灏   fixed #5377
177
178
179
180
181
182
183
184
185
186
187
188
189
                  const AllTabPanes = findComponentsDownward(this, 'TabPane');
                  const TabPanes = [];
  
                  AllTabPanes.forEach(item => {
                      if (item.tab && this.name) {
                          if (item.tab === this.name) {
                              TabPanes.push(item);
                          }
                      } else {
                          TabPanes.push(item);
                      }
                  });
  
5b143a2b   梁灏   fixed #5401 , clo...
190
191
192
193
194
195
196
197
                  // 在 TabPane 使用 v-if 时,并不会按照预先的顺序渲染,这时可设置 index,并从小到大排序
                  TabPanes.sort((a, b) => {
                      if (a.index && b.index) {
                          return a.index > b.index ? 1 : -1;
                      } else {
                          return 1;
                      }
                  });
26b2cfa0   梁灏   fixed #5377
198
                  return TabPanes;
17f52abf   梁灏   update Tabs
199
200
201
202
203
              },
              updateNav () {
                  this.navList = [];
                  this.getTabs().forEach((pane, index) => {
                      this.navList.push({
1f974700   Aresn   Tabs support rend...
204
                          labelType: typeof pane.label,
17f52abf   梁灏   update Tabs
205
206
                          label: pane.label,
                          icon: pane.icon || '',
30510c3d   梁灏   support Tabs
207
                          name: pane.currentName || index,
7a737482   梁灏   fixed #206
208
209
                          disabled: pane.disabled,
                          closable: pane.closable
17f52abf   梁灏   update Tabs
210
                      });
30510c3d   梁灏   support Tabs
211
                      if (!pane.currentName) pane.currentName = index;
17f52abf   梁灏   update Tabs
212
                      if (index === 0) {
30510c3d   梁灏   support Tabs
213
                          if (!this.activeKey) this.activeKey = pane.currentName || index;
17f52abf   梁灏   update Tabs
214
215
                      }
                  });
77bafb31   梁灏   update Tabs
216
                  this.updateStatus();
17f52abf   梁灏   update Tabs
217
218
219
220
                  this.updateBar();
              },
              updateBar () {
                  this.$nextTick(() => {
e45d1bce   Sergio Crisostomo   fix too early vis...
221
                      const index = this.getTabIndex(this.activeKey);
2993f4ee   梁灏   update Tab
222
                      if (!this.$refs.nav) return;  // 页面销毁时,这里会报错,为了解决 #2100
30510c3d   梁灏   support Tabs
223
                      const prevTabs = this.$refs.nav.querySelectorAll(`.${prefixCls}-tab`);
17f52abf   梁灏   update Tabs
224
                      const tab = prevTabs[index];
bdfab3b9   梁灏   fixed #1842
225
                      this.barWidth = tab ? parseFloat(tab.offsetWidth) : 0;
17f52abf   梁灏   update Tabs
226
227
228
229
230
  
                      if (index > 0) {
                          let offset = 0;
                          const gutter = this.size === 'small' ? 0 : 16;
                          for (let i = 0; i < index; i++) {
75798f5b   erhuluanzi   getComputedStyle在...
231
                              offset += parseFloat(prevTabs[i].offsetWidth) + gutter;
17f52abf   梁灏   update Tabs
232
233
234
235
236
237
                          }
  
                          this.barOffset = offset;
                      } else {
                          this.barOffset = 0;
                      }
be3fbd24   marxy   Tabs add scroll
238
                      this.updateNavScroll();
17f52abf   梁灏   update Tabs
239
240
                  });
              },
77bafb31   梁灏   update Tabs
241
242
              updateStatus () {
                  const tabs = this.getTabs();
30510c3d   梁灏   support Tabs
243
                  tabs.forEach(tab => tab.show = (tab.currentName === this.activeKey) || this.animated);
77bafb31   梁灏   update Tabs
244
              },
17f52abf   梁灏   update Tabs
245
246
247
248
249
              tabCls (item) {
                  return [
                      `${prefixCls}-tab`,
                      {
                          [`${prefixCls}-tab-disabled`]: item.disabled,
7be1069a   Sergio Crisostomo   Add tab navigatio...
250
251
                          [`${prefixCls}-tab-active`]: item.name === this.activeKey,
                          [`${prefixCls}-tab-focused`]: item.name === this.focusedKey,
17f52abf   梁灏   update Tabs
252
                      }
b0893113   jingsam   :art: add eslint
253
                  ];
17f52abf   梁灏   update Tabs
254
255
              },
              handleChange (index) {
7be1069a   Sergio Crisostomo   Add tab navigatio...
256
257
258
259
260
                  if (this.transitioning) return;
  
                  this.transitioning = true;
                  setTimeout(() => this.transitioning = false, transitionTime);
  
17f52abf   梁灏   update Tabs
261
262
                  const nav = this.navList[index];
                  if (nav.disabled) return;
30510c3d   梁灏   support Tabs
263
264
265
                  this.activeKey = nav.name;
                  this.$emit('input', nav.name);
                  this.$emit('on-click', nav.name);
17f52abf   梁灏   update Tabs
266
              },
7be1069a   Sergio Crisostomo   Add tab navigatio...
267
268
269
270
271
272
              handleTabKeyNavigation(e){
                  if (e.keyCode !== 37 && e.keyCode !== 39) return;
                  const direction = e.keyCode === 39 ? 1 : -1;
                  const nextTab = getNextTab(this.navList, this.focusedKey, direction);
                  this.focusedKey = nextTab.name;
              },
8b410220   Aresn   handleTabKeyboard...
273
274
              handleTabKeyboardSelect(init = false){
                  if (init) return;
38ab7442   Sergio Crisostomo   Correct logic for...
275
                  const focused = this.focusedKey || 0;
e45d1bce   Sergio Crisostomo   fix too early vis...
276
                  const index = this.getTabIndex(focused);
38ab7442   Sergio Crisostomo   Correct logic for...
277
                  this.handleChange(index);
7be1069a   Sergio Crisostomo   Add tab navigatio...
278
              },
17f52abf   梁灏   update Tabs
279
              handleRemove (index) {
753720d9   梁灏   Tabs add prop bef...
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
                  if (!this.beforeRemove) {
                      return this.handleRemoveTab(index);
                  }
  
                  const before = this.beforeRemove(index);
  
                  if (before && before.then) {
                      before.then(() => {
                          this.handleRemoveTab(index);
                      });
                  } else {
                      this.handleRemoveTab(index);
                  }
              },
              handleRemoveTab (index) {
17f52abf   梁灏   update Tabs
295
296
                  const tabs = this.getTabs();
                  const tab = tabs[index];
087ad37d   梁灏   update Tabs
297
                  tab.$destroy();
17f52abf   梁灏   update Tabs
298
  
30510c3d   梁灏   support Tabs
299
                  if (tab.currentName === this.activeKey) {
17f52abf   梁灏   update Tabs
300
301
302
303
304
305
306
307
                      const newTabs = this.getTabs();
                      let activeKey = -1;
  
                      if (newTabs.length) {
                          const leftNoDisabledTabs = tabs.filter((item, itemIndex) => !item.disabled && itemIndex < index);
                          const rightNoDisabledTabs = tabs.filter((item, itemIndex) => !item.disabled && itemIndex > index);
  
                          if (rightNoDisabledTabs.length) {
30510c3d   梁灏   support Tabs
308
                              activeKey = rightNoDisabledTabs[0].currentName;
17f52abf   梁灏   update Tabs
309
                          } else if (leftNoDisabledTabs.length) {
30510c3d   梁灏   support Tabs
310
                              activeKey = leftNoDisabledTabs[leftNoDisabledTabs.length - 1].currentName;
17f52abf   梁灏   update Tabs
311
                          } else {
30510c3d   梁灏   support Tabs
312
                              activeKey = newTabs[0].currentName;
17f52abf   梁灏   update Tabs
313
314
315
                          }
                      }
                      this.activeKey = activeKey;
087ad37d   梁灏   update Tabs
316
                      this.$emit('input', activeKey);
17f52abf   梁灏   update Tabs
317
                  }
30510c3d   梁灏   support Tabs
318
                  this.$emit('on-tab-remove', tab.currentName);
17f52abf   梁灏   update Tabs
319
                  this.updateNav();
7a737482   梁灏   fixed #206
320
321
322
323
324
325
326
327
328
329
330
              },
              showClose (item) {
                  if (this.type === 'card') {
                      if (item.closable !== null) {
                          return item.closable;
                      } else {
                          return this.closable;
                      }
                  } else {
                      return false;
                  }
be3fbd24   marxy   Tabs add scroll
331
332
333
334
335
336
337
338
              },
              scrollPrev() {
                  const containerWidth = this.$refs.navScroll.offsetWidth;
                  const currentOffset = this.getCurrentScrollOffset();
  
                  if (!currentOffset) return;
  
                  let newOffset = currentOffset > containerWidth
a74be22e   Sergio Crisostomo   don't check DOM t...
339
340
                      ? currentOffset - containerWidth
                      : 0;
be3fbd24   marxy   Tabs add scroll
341
342
343
344
345
346
347
348
349
350
  
                  this.setOffset(newOffset);
              },
              scrollNext() {
                  const navWidth = this.$refs.nav.offsetWidth;
                  const containerWidth = this.$refs.navScroll.offsetWidth;
                  const currentOffset = this.getCurrentScrollOffset();
                  if (navWidth - currentOffset <= containerWidth) return;
  
                  let newOffset = navWidth - currentOffset > containerWidth * 2
a74be22e   Sergio Crisostomo   don't check DOM t...
351
352
                      ? currentOffset + containerWidth
                      : (navWidth - containerWidth);
be3fbd24   marxy   Tabs add scroll
353
354
355
356
357
358
  
                  this.setOffset(newOffset);
              },
              getCurrentScrollOffset() {
                  const { navStyle } = this;
                  return navStyle.transform
a74be22e   Sergio Crisostomo   don't check DOM t...
359
360
                      ? Number(navStyle.transform.match(/translateX\(-(\d+(\.\d+)*)px\)/)[1])
                      : 0;
be3fbd24   marxy   Tabs add scroll
361
              },
e45d1bce   Sergio Crisostomo   fix too early vis...
362
363
364
              getTabIndex(name){
                  return this.navList.findIndex(nav => nav.name === name);
              },
be3fbd24   marxy   Tabs add scroll
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
              setOffset(value) {
                  this.navStyle.transform = `translateX(-${value}px)`;
              },
              scrollToActiveTab() {
                  if (!this.scrollable) return;
                  const nav = this.$refs.nav;
                  const activeTab = this.$el.querySelector(`.${prefixCls}-tab-active`);
                  if(!activeTab) return;
  
                  const navScroll = this.$refs.navScroll;
                  const activeTabBounding = activeTab.getBoundingClientRect();
                  const navScrollBounding = navScroll.getBoundingClientRect();
                  const navBounding = nav.getBoundingClientRect();
                  const currentOffset = this.getCurrentScrollOffset();
                  let newOffset = currentOffset;
  
                  if (navBounding.right < navScrollBounding.right) {
                      newOffset = nav.offsetWidth - navScrollBounding.width;
                  }
  
                  if (activeTabBounding.left < navScrollBounding.left) {
                      newOffset = currentOffset - (navScrollBounding.left - activeTabBounding.left);
                  }else if (activeTabBounding.right > navScrollBounding.right) {
                      newOffset = currentOffset + activeTabBounding.right - navScrollBounding.right;
                  }
  
                  if(currentOffset !== newOffset){
                      this.setOffset(Math.max(newOffset, 0));
                  }
              },
              updateNavScroll(){
                  const navWidth = this.$refs.nav.offsetWidth;
                  const containerWidth = this.$refs.navScroll.offsetWidth;
                  const currentOffset = this.getCurrentScrollOffset();
                  if (containerWidth < navWidth) {
                      this.scrollable = true;
                      if (navWidth - currentOffset < containerWidth) {
                          this.setOffset(navWidth - containerWidth);
                      }
                  } else {
                      this.scrollable = false;
                      if (currentOffset > 0) {
                          this.setOffset(0);
                      }
                  }
              },
              handleResize(){
                  this.updateNavScroll();
79885751   Kang Cheng   fix issue #1846
413
414
415
              },
              isInsideHiddenElement () {
                  let parentNode = this.$el.parentNode;
a74be22e   Sergio Crisostomo   don't check DOM t...
416
                  while(parentNode && parentNode !== document.body) {
a90d1a20   yangdan8   解决isInsideHiddenE...
417
                      if (parentNode.style && parentNode.style.display === 'none') {
79885751   Kang Cheng   fix issue #1846
418
419
420
421
422
                          return parentNode;
                      }
                      parentNode = parentNode.parentNode;
                  }
                  return false;
e45d1bce   Sergio Crisostomo   fix too early vis...
423
424
              },
              updateVisibility(index){
4d8b4016   梁灏   update Tabs metho...
425
                  [...this.$refs.panes.querySelectorAll(`.${prefixCls}-tabpane`)].forEach((el, i) => {
e45d1bce   Sergio Crisostomo   fix too early vis...
426
                      if (index === i) {
a3682c91   梁灏   close #4296 #4052
427
                          [...el.children].filter(child=> child.classList.contains(`${prefixCls}-tabpane`)).forEach(child => child.style.visibility = 'visible');
28026b3f   Sergio Crisostomo   Fix 3732 - add pr...
428
                          if (this.captureFocus) setTimeout(() => focusFirst(el, el), transitionTime);
e45d1bce   Sergio Crisostomo   fix too early vis...
429
430
                      } else {
                          setTimeout(() => {
a3682c91   梁灏   close #4296 #4052
431
                              [...el.children].filter(child=> child.classList.contains(`${prefixCls}-tabpane`)).forEach(child => child.style.visibility = 'hidden');
e45d1bce   Sergio Crisostomo   fix too early vis...
432
433
434
                          }, transitionTime);
                      }
                  });
17f52abf   梁灏   update Tabs
435
436
              }
          },
17f52abf   梁灏   update Tabs
437
          watch: {
30510c3d   梁灏   support Tabs
438
439
              value (val) {
                  this.activeKey = val;
7be1069a   Sergio Crisostomo   Add tab navigatio...
440
                  this.focusedKey = val;
30510c3d   梁灏   support Tabs
441
              },
7be1069a   Sergio Crisostomo   Add tab navigatio...
442
443
              activeKey (val) {
                  this.focusedKey = val;
17f52abf   梁灏   update Tabs
444
                  this.updateBar();
0c5e01f1   梁灏   fixed #185
445
                  this.updateStatus();
67c9b1c8   梁灏   fixed #591
446
                  this.broadcast('Table', 'on-visible-change', true);
a730a849   梁灏   update Tabs
447
                  this.$nextTick(() => {
be3fbd24   marxy   Tabs add scroll
448
449
                      this.scrollToActiveTab();
                  });
38ab7442   Sergio Crisostomo   Correct logic for...
450
451
  
                  // update visibility
e45d1bce   Sergio Crisostomo   fix too early vis...
452
453
                  const nextIndex = Math.max(this.getTabIndex(this.focusedKey), 0);
                  this.updateVisibility(nextIndex);
17f52abf   梁灏   update Tabs
454
              }
c4eb5dcf   H   tabs组件导航区添加右侧slot...
455
          },
8e4f708f   梁灏   update Tabs
456
457
          mounted () {
              this.showSlot = this.$slots.extra !== undefined;
be3fbd24   marxy   Tabs add scroll
458
459
              this.observer = elementResizeDetectorMaker();
              this.observer.listenTo(this.$refs.navWrap, this.handleResize);
79885751   Kang Cheng   fix issue #1846
460
461
462
  
              const hiddenParentNode = this.isInsideHiddenElement();
              if (hiddenParentNode) {
3be0aa12   Kang Cheng   Import custom Mut...
463
                  this.mutationObserver = new MutationObserver(() => {
79885751   Kang Cheng   fix issue #1846
464
465
                      if (hiddenParentNode.style.display !== 'none') {
                          this.updateBar();
3be0aa12   Kang Cheng   Import custom Mut...
466
                          this.mutationObserver.disconnect();
79885751   Kang Cheng   fix issue #1846
467
468
469
                      }
                  });
  
3be0aa12   Kang Cheng   Import custom Mut...
470
                  this.mutationObserver.observe(hiddenParentNode, { attributes: true, childList: true, characterData: true, attributeFilter: ['style'] });
79885751   Kang Cheng   fix issue #1846
471
              }
45dbc6fd   Sergio Crisostomo   Correct disabled ...
472
  
8b410220   Aresn   handleTabKeyboard...
473
              this.handleTabKeyboardSelect(true);
e45d1bce   Sergio Crisostomo   fix too early vis...
474
              this.updateVisibility(this.getTabIndex(this.activeKey));
be3fbd24   marxy   Tabs add scroll
475
476
477
          },
          beforeDestroy() {
              this.observer.removeListener(this.$refs.navWrap, this.handleResize);
9b6f316e   梁灏   fixed Tabs bug
478
              if (this.mutationObserver) this.mutationObserver.disconnect();
17f52abf   梁灏   update Tabs
479
          }
b0893113   jingsam   :art: add eslint
480
481
      };
  </script>