@internetstiftelsen/styleguide 3.0.12 → 3.0.13
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/dist/atoms/range/range.js +19 -3
- package/dist/organisms/tabs/tabs.js +16 -14
- package/package.json +1 -1
|
@@ -1,13 +1,17 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
var ranges = document.querySelectorAll('.js-range-wrapper');
|
|
4
|
-
function setValue(range, rangeValue) {
|
|
4
|
+
function setValue(range, rangeValue, rangeInput) {
|
|
5
5
|
var val = range.value;
|
|
6
6
|
var min = range.min ? range.min : 0;
|
|
7
7
|
var max = range.max ? range.max : 100;
|
|
8
8
|
var newVal = Number((val - min) * 100 / (max - min));
|
|
9
9
|
rangeValue.innerHTML = val;
|
|
10
10
|
|
|
11
|
+
if (rangeInput) {
|
|
12
|
+
rangeInput.value = val;
|
|
13
|
+
}
|
|
14
|
+
|
|
11
15
|
// Sorta magic numbers based on size of the native UI thumb
|
|
12
16
|
rangeValue.style.left = 'calc(' + newVal + '% + (' + (8 - newVal * 0.15) + 'px))';
|
|
13
17
|
}
|
|
@@ -15,11 +19,23 @@ function setValue(range, rangeValue) {
|
|
|
15
19
|
ranges.forEach(function (wrap) {
|
|
16
20
|
var range = wrap.querySelector('.js-range');
|
|
17
21
|
var rangeValue = wrap.querySelector('.js-range-value');
|
|
22
|
+
var rangeInput = wrap.querySelector('.js-range-input');
|
|
18
23
|
|
|
19
24
|
range.addEventListener('input', function () {
|
|
20
|
-
setValue(range, rangeValue);
|
|
25
|
+
setValue(range, rangeValue, rangeInput);
|
|
21
26
|
range.focus();
|
|
22
27
|
});
|
|
23
28
|
|
|
24
|
-
|
|
29
|
+
if (rangeInput) {
|
|
30
|
+
rangeInput.addEventListener('input', function () {
|
|
31
|
+
if (rangeInput.value !== '') {
|
|
32
|
+
range.value = rangeInput.value;
|
|
33
|
+
rangeValue.innerHTML = rangeInput.value;
|
|
34
|
+
setValue(range, rangeValue, rangeInput);
|
|
35
|
+
}
|
|
36
|
+
rangeInput.focus();
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
setValue(range, rangeValue, rangeInput);
|
|
25
41
|
});
|
|
@@ -2,6 +2,13 @@
|
|
|
2
2
|
|
|
3
3
|
window.a11yTabs = function tabsComponentIIFE(global, document) {
|
|
4
4
|
var tabInstances = new WeakMap();
|
|
5
|
+
var className = 'o-tab-list';
|
|
6
|
+
var tablistElement = document.querySelector('.js-' + className);
|
|
7
|
+
var updateURLFromHash = void 0;
|
|
8
|
+
|
|
9
|
+
if (tablistElement) {
|
|
10
|
+
updateURLFromHash = tablistElement.getAttribute('data-update-url');
|
|
11
|
+
}
|
|
5
12
|
|
|
6
13
|
/**
|
|
7
14
|
* Instantiates the component
|
|
@@ -13,8 +20,6 @@ window.a11yTabs = function tabsComponentIIFE(global, document) {
|
|
|
13
20
|
return;
|
|
14
21
|
}
|
|
15
22
|
|
|
16
|
-
var className = 'o-tab-list';
|
|
17
|
-
var tablistElement = document.querySelector('.js-' + className);
|
|
18
23
|
var namespace = getComputedStyle(tablistElement, ':before').content.replace(/["']/g, '');
|
|
19
24
|
|
|
20
25
|
var defaults = {
|
|
@@ -46,7 +51,6 @@ window.a11yTabs = function tabsComponentIIFE(global, document) {
|
|
|
46
51
|
|
|
47
52
|
this.tabLinks.forEach(function (item, index) {
|
|
48
53
|
item.setAttribute('role', 'tab');
|
|
49
|
-
// item.setAttribute('id', `tab${index}`);
|
|
50
54
|
|
|
51
55
|
if (index > 0) {
|
|
52
56
|
item.setAttribute('tabindex', '-1');
|
|
@@ -71,14 +75,10 @@ window.a11yTabs = function tabsComponentIIFE(global, document) {
|
|
|
71
75
|
|
|
72
76
|
tabInstances.set(this.element, this);
|
|
73
77
|
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
tabInstances.set(this.element, this);
|
|
79
|
-
|
|
80
|
-
// New line to select the correct tab based on URL hash
|
|
81
|
-
this.selectTabFromHash(); // Call the new method after setup
|
|
78
|
+
// Select the correct tab based on URL hash
|
|
79
|
+
if (updateURLFromHash) {
|
|
80
|
+
this.selectTabFromHash();
|
|
81
|
+
}
|
|
82
82
|
};
|
|
83
83
|
|
|
84
84
|
TabComponent.prototype = {
|
|
@@ -116,16 +116,18 @@ window.a11yTabs = function tabsComponentIIFE(global, document) {
|
|
|
116
116
|
this.tabLinks[newIndex].setAttribute('aria-selected', 'true');
|
|
117
117
|
this.tabItems[newIndex].setAttribute('data-tab-active', '');
|
|
118
118
|
this.tabLinks[newIndex].removeAttribute('tabindex');
|
|
119
|
-
this.tabLinks[newIndex].focus();
|
|
119
|
+
this.tabLinks[newIndex].focus(); // Focus the newly selected tab
|
|
120
120
|
|
|
121
121
|
// update tab panels
|
|
122
122
|
this.tabPanels[currentIndex].setAttribute('hidden', '');
|
|
123
123
|
this.tabPanels[newIndex].removeAttribute('hidden');
|
|
124
124
|
|
|
125
|
-
// After updating tabs and tab panels, add the URL update feature
|
|
126
125
|
// Update the browser's URL hash to reflect the current tab's ID
|
|
127
126
|
var selectedTabId = this.tabLinks[newIndex].id;
|
|
128
|
-
|
|
127
|
+
|
|
128
|
+
if (updateURLFromHash) {
|
|
129
|
+
window.history.pushState(null, '', '#' + selectedTabId);
|
|
130
|
+
}
|
|
129
131
|
|
|
130
132
|
this.currentIndex = newIndex;
|
|
131
133
|
|