@nethserver/ns8-ui-lib 0.1.5 → 0.1.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,60 @@
1
+ <script>
2
+ import { CvTabs } from "@carbon/vue";
3
+
4
+ export default {
5
+ name: "NsTabs",
6
+ extends: CvTabs,
7
+ methods: {
8
+ // extend method to fix error on beforeDestroy
9
+ doScrollIntoView(index) {
10
+ const tab = this.$refs.link[index];
11
+
12
+ // fix error on beforeDestroy
13
+ if (!tab) {
14
+ return;
15
+ }
16
+
17
+ const scrollContainer = tab.parentNode ? tab.parentNode.parentNode : null;
18
+ let newScrollLeft;
19
+
20
+ if (tab && scrollContainer) {
21
+ const scrollLeft = scrollContainer.scrollLeft;
22
+ const tabLeft = tab.offsetLeft - scrollContainer.offsetLeft;
23
+
24
+ if (index === 0) {
25
+ newScrollLeft = 0;
26
+ } else if (index === this.$refs.link.length - 1) {
27
+ newScrollLeft =
28
+ scrollContainer.scrollWidth - scrollContainer.offsetWidth;
29
+ } else if (tabLeft < scrollLeft) {
30
+ newScrollLeft = tabLeft;
31
+ } else {
32
+ const rightOfTab =
33
+ tab.offsetLeft - scrollContainer.offsetLeft + tab.offsetWidth;
34
+ if (rightOfTab > scrollContainer.offsetWidth + scrollLeft) {
35
+ newScrollLeft = rightOfTab - scrollContainer.offsetWidth;
36
+
37
+ if (!this.rightOverflowNavButtonHidden) {
38
+ newScrollLeft += this.OVERFLOW_BUTTON_OFFSET;
39
+ }
40
+ }
41
+ }
42
+ }
43
+
44
+ if (newScrollLeft !== undefined) {
45
+ this.skipScroll = true;
46
+ this.leftOverflowNavButtonHidden = newScrollLeft <= 0;
47
+ this.rightOverflowNavButtonHidden =
48
+ newScrollLeft + this.$refs.tablist.clientWidth >=
49
+ this.$refs.tablist.scrollWidth;
50
+
51
+ this.$nextTick(() => {
52
+ // allow left and right nav hide to propegate before setting scroll
53
+ scrollContainer.scrollLeft = newScrollLeft;
54
+ this.skipScroll = false;
55
+ });
56
+ }
57
+ },
58
+ },
59
+ };
60
+ </script>