@mozaic-ds/vue 0.22.0 → 0.22.1-beta.0

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mozaic-ds/vue",
3
- "version": "0.22.0",
3
+ "version": "0.22.1-beta.0",
4
4
  "description": "Vue.js implementation of Mozaic Design System",
5
5
  "author": "Adeo - Mozaic Design System",
6
6
  "scripts": {
@@ -23,14 +23,8 @@
23
23
  class="mc-tabs__link"
24
24
  role="tab"
25
25
  :aria-selected="tab.active ? 'true' : 'false'"
26
- :class="setActiveClass(tab)"
27
- @click="
28
- manageTabs(
29
- $event.target,
30
- $event,
31
- Object.assign({ index: index }, tab)
32
- )
33
- "
26
+ :class="setLinkClass(tab)"
27
+ @click="onTabClicked($event, tab, index)"
34
28
  >
35
29
  {{ tab.text }}
36
30
  </component>
@@ -111,7 +105,7 @@ export default {
111
105
  activeIndex(newValue) {
112
106
  const tab = this.getTabFromIndex(newValue);
113
107
  if (tab && this.tabs[newValue]) {
114
- this.manageTabs(tab, null, Object.assign({index: newValue}, this.tabs[newValue]));
108
+ this.setTabState(tab);
115
109
  }
116
110
  }
117
111
  },
@@ -124,7 +118,7 @@ export default {
124
118
  if (this.activeIndex) {
125
119
  const tab = this.getTabFromIndex(this.activeIndex);
126
120
  if (tab) {
127
- this.manageTabs(tab);
121
+ this.setTabState(tab);
128
122
  }
129
123
  } else {
130
124
  const isActive = this.tabs.some((tab) =>
@@ -132,7 +126,7 @@ export default {
132
126
  );
133
127
  if (!isActive) {
134
128
  const firstTab = this.tablist.querySelector('.mc-tabs__link');
135
- this.manageTabs(firstTab);
129
+ this.setTabState(firstTab);
136
130
  }
137
131
  }
138
132
  }
@@ -140,18 +134,25 @@ export default {
140
134
  },
141
135
 
142
136
  methods: {
143
- setActiveClass: function (tab) {
144
- const tabClasses = [];
145
-
146
- if (tab.active) {
147
- tabClasses.push('mc-tabs__link--selected');
137
+ setLinkClass: function (tab) {
138
+ return {
139
+ 'mc-tabs__link--selected': tab.active,
140
+ 'mc-tabs__link--disabled': tab.disabled,
141
+ };
142
+ },
143
+ onTabClicked(e, tab, index) {
144
+ if (tab && tab.disabled) {
145
+ return;
148
146
  }
149
147
 
150
- if (tab.disabled) {
151
- tabClasses.push('mc-tabs__link--disabled');
148
+ let selectedTab = this.getTabFromIndex(index);
149
+
150
+ if (this.activeIndex) {
151
+ selectedTab = this.getTabFromIndex(this.activeIndex);
152
152
  }
153
153
 
154
- return tabClasses;
154
+ this.setTabState(selectedTab);
155
+ this.$emit('tab-clicked', e.target, Object.assign({ index: index }, tab));
155
156
  },
156
157
  manageTabs: function (el, e, tab) {
157
158
  if (tab && tab.disabled) {
@@ -169,6 +170,15 @@ export default {
169
170
  el.classList.add('mc-tabs__link--selected');
170
171
  el.setAttribute('aria-selected', 'true');
171
172
  },
173
+ setTabState(tab) {
174
+ this.tablist.querySelectorAll('.mc-tabs__link').forEach((el) => {
175
+ el.classList.remove('mc-tabs__link--selected');
176
+ el.setAttribute('aria-selected', 'false');
177
+ });
178
+
179
+ tab.classList.add('mc-tabs__link--selected');
180
+ tab.setAttribute('aria-selected', 'true');
181
+ },
172
182
  getTabFromIndex: function (index) {
173
183
  if (this.tablist && this.tablist.children[index] && this.tablist.children[index].children[0]) {
174
184
  return this.tablist.children[index].children[0];