@nationalarchives/frontend 0.1.9-prerelease → 0.1.11-prerelease
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/README.md +3 -3
- package/govuk-prototype-kit.config.json +0 -3
- package/nationalarchives/_features.scss +4 -0
- package/nationalarchives/all.css +1 -1
- package/nationalarchives/all.css.map +1 -1
- package/nationalarchives/all.js +1 -1
- package/nationalarchives/all.js.map +1 -1
- package/nationalarchives/all.mjs +54 -3
- package/nationalarchives/all.scss +8 -4
- package/nationalarchives/assets/images/footer/facebook.svg +11 -0
- package/nationalarchives/assets/images/footer/flickr.svg +11 -0
- package/nationalarchives/assets/images/footer/instagram.svg +17 -0
- package/nationalarchives/assets/images/footer/rss.svg +13 -0
- package/nationalarchives/assets/images/footer/twitter.svg +14 -0
- package/nationalarchives/assets/images/footer/youtube.svg +12 -0
- package/nationalarchives/assets/images/tna-square-logo.svg +5 -24
- package/nationalarchives/components/_index.scss +13 -0
- package/nationalarchives/components/breadcrumbs/_index.scss +28 -6
- package/nationalarchives/components/breadcrumbs/breadcrumbs.stories.js +1 -2
- package/nationalarchives/components/breadcrumbs/fixtures.json +1 -1
- package/nationalarchives/components/breadcrumbs/macro.njk +1 -1
- package/nationalarchives/components/breadcrumbs/template.njk +14 -13
- package/nationalarchives/components/button/_index.scss +23 -11
- package/nationalarchives/components/button/button.stories.js +1 -2
- package/nationalarchives/components/button/fixtures.json +5 -5
- package/nationalarchives/components/button/macro.njk +1 -1
- package/nationalarchives/components/card/_index.scss +51 -7
- package/nationalarchives/components/card/card.js +2 -0
- package/nationalarchives/components/card/card.js.map +1 -0
- package/nationalarchives/components/card/card.mjs +45 -0
- package/nationalarchives/components/card/card.stories.js +18 -15
- package/nationalarchives/components/card/fixtures.json +14 -12
- package/nationalarchives/components/card/macro-options.json +18 -0
- package/nationalarchives/components/card/macro.njk +1 -1
- package/nationalarchives/components/card/template.njk +9 -4
- package/nationalarchives/components/filters/filters.stories.js +1 -2
- package/nationalarchives/components/filters/macro.njk +1 -1
- package/nationalarchives/components/filters/template.njk +2 -2
- package/nationalarchives/components/footer/_index.scss +68 -13
- package/nationalarchives/components/footer/fixtures.json +1 -1
- package/nationalarchives/components/footer/footer.stories.js +20 -23
- package/nationalarchives/components/footer/macro-options.json +12 -6
- package/nationalarchives/components/footer/macro.njk +1 -1
- package/nationalarchives/components/footer/template.njk +26 -16
- package/nationalarchives/components/grid/_index.scss +10 -12
- package/nationalarchives/components/grid/fixtures.json +12 -12
- package/nationalarchives/components/grid/grid.stories.js +56 -3
- package/nationalarchives/components/grid/macro-options.json +30 -0
- package/nationalarchives/components/grid/macro.njk +1 -1
- package/nationalarchives/components/grid/template.njk +17 -1
- package/nationalarchives/components/header/_index.scss +269 -60
- package/nationalarchives/components/header/header.js +1 -1
- package/nationalarchives/components/header/header.js.map +1 -1
- package/nationalarchives/components/header/header.mjs +7 -12
- package/nationalarchives/components/header/header.stories.js +156 -6
- package/nationalarchives/components/header/macro-options.json +83 -5
- package/nationalarchives/components/header/macro.njk +1 -1
- package/nationalarchives/components/header/template.njk +45 -36
- package/nationalarchives/components/hero/_index.scss +36 -6
- package/nationalarchives/components/hero/fixtures.json +16 -1
- package/nationalarchives/components/hero/hero.stories.js +32 -16
- package/nationalarchives/components/hero/macro-options.json +14 -2
- package/nationalarchives/components/hero/macro.njk +1 -1
- package/nationalarchives/components/hero/template.njk +7 -5
- package/nationalarchives/components/phase-banner/_index.scss +60 -0
- package/nationalarchives/components/phase-banner/fixtures.json +81 -0
- package/nationalarchives/components/phase-banner/macro-options.json +26 -0
- package/nationalarchives/components/phase-banner/macro.njk +3 -0
- package/nationalarchives/components/phase-banner/phase-banner.stories.js +64 -0
- package/nationalarchives/components/phase-banner/template.njk +16 -0
- package/nationalarchives/components/picture/_index.scss +77 -0
- package/nationalarchives/components/picture/fixtures.json +4 -0
- package/nationalarchives/components/picture/macro-options.json +88 -0
- package/nationalarchives/components/picture/macro.njk +3 -0
- package/nationalarchives/components/picture/picture.js +2 -0
- package/nationalarchives/components/picture/picture.js.map +1 -0
- package/nationalarchives/components/picture/picture.mjs +57 -0
- package/nationalarchives/components/picture/picture.stories.js +63 -0
- package/nationalarchives/components/picture/template.njk +42 -0
- package/nationalarchives/components/profile/_index.scss +2 -0
- package/nationalarchives/components/profile/fixtures.json +4 -0
- package/nationalarchives/components/profile/macro-options.json +14 -0
- package/nationalarchives/components/profile/macro.njk +3 -0
- package/nationalarchives/components/profile/profile.stories.js +32 -0
- package/nationalarchives/components/profile/template.njk +15 -0
- package/nationalarchives/components/sensitive-image/fixtures.json +3 -3
- package/nationalarchives/components/sensitive-image/macro.njk +1 -1
- package/nationalarchives/components/sensitive-image/sensitive-image.stories.js +1 -2
- package/nationalarchives/components/tabs/_index.scss +148 -0
- package/nationalarchives/components/tabs/fixtures.json +4 -0
- package/nationalarchives/components/tabs/macro-options.json +52 -0
- package/nationalarchives/components/tabs/macro.njk +3 -0
- package/nationalarchives/components/tabs/tabs.js +2 -0
- package/nationalarchives/components/tabs/tabs.js.map +1 -0
- package/nationalarchives/components/tabs/tabs.mjs +214 -0
- package/nationalarchives/components/tabs/tabs.stories.js +302 -0
- package/nationalarchives/components/tabs/template.njk +20 -0
- package/nationalarchives/patterns/_index.scss +1 -0
- package/nationalarchives/patterns/featured-collection/_index.scss +13 -0
- package/nationalarchives/patterns/featured-collection/featured-collection.stories.js +35 -0
- package/nationalarchives/patterns/featured-collection/macro-options.json +20 -0
- package/nationalarchives/patterns/featured-collection/macro.njk +3 -0
- package/nationalarchives/patterns/featured-collection/template.njk +96 -0
- package/nationalarchives/stories/development/contributing.mdx +39 -0
- package/nationalarchives/stories/development/dependencies.mdx +2 -0
- package/nationalarchives/stories/development/technologies.mdx +65 -0
- package/nationalarchives/stories/utilities/colour.stories.js +189 -0
- package/nationalarchives/stories/utilities/typography.mdx +1 -0
- package/nationalarchives/stories/utilities/typography.stories.js +15 -0
- package/nationalarchives/templates/layouts/_generic.njk +1 -1
- package/nationalarchives/tools/_assets.scss +5 -0
- package/nationalarchives/tools/_colour.scss +129 -0
- package/nationalarchives/tools/_grid.scss +2 -2
- package/nationalarchives/tools/_index.scss +5 -0
- package/nationalarchives/tools/_media.scss +12 -11
- package/nationalarchives/tools/_typography.scss +15 -0
- package/nationalarchives/utilities/_debug.scss +11 -0
- package/nationalarchives/utilities/_global.scss +120 -3
- package/nationalarchives/utilities/_index.scss +3 -0
- package/nationalarchives/utilities/_typography.scss +155 -111
- package/nationalarchives/variables/_assets.scss +1 -0
- package/nationalarchives/variables/_colour.scss +120 -11
- package/nationalarchives/variables/{_all.scss → _index.scss} +1 -0
- package/nationalarchives/variables/_media.scss +39 -11
- package/nationalarchives/variables/_typography.scss +1 -1
- package/package.json +18 -15
- package/nationalarchives/components/_all.scss +0 -7
- package/nationalarchives/stories/development/structure.mdx +0 -7
- package/nationalarchives/tools/_all.scss +0 -3
- package/nationalarchives/utilities/_all.scss +0 -2
@@ -0,0 +1,14 @@
|
|
1
|
+
[
|
2
|
+
{
|
3
|
+
"name": "classes",
|
4
|
+
"type": "string",
|
5
|
+
"required": false,
|
6
|
+
"description": "Classes to add to the profile."
|
7
|
+
},
|
8
|
+
{
|
9
|
+
"name": "attributes",
|
10
|
+
"type": "object",
|
11
|
+
"required": false,
|
12
|
+
"description": "HTML attributes (for example data attributes) to add to the profile."
|
13
|
+
}
|
14
|
+
]
|
@@ -0,0 +1,32 @@
|
|
1
|
+
import Profile from "./template.njk";
|
2
|
+
import macroOptions from "./macro-options.json";
|
3
|
+
|
4
|
+
const argTypes = {
|
5
|
+
classes: { control: "text" },
|
6
|
+
attributes: { control: "object" },
|
7
|
+
};
|
8
|
+
|
9
|
+
Object.keys(argTypes).forEach((argType) => {
|
10
|
+
argTypes[argType].description = macroOptions.find(
|
11
|
+
(option) => option.name === argType,
|
12
|
+
)?.description;
|
13
|
+
});
|
14
|
+
|
15
|
+
export default {
|
16
|
+
title: "Work in progress/Components/Profile",
|
17
|
+
argTypes,
|
18
|
+
};
|
19
|
+
|
20
|
+
const Template = ({ classes, attributes }) => {
|
21
|
+
return Profile({
|
22
|
+
params: {
|
23
|
+
classes,
|
24
|
+
attributes,
|
25
|
+
},
|
26
|
+
});
|
27
|
+
};
|
28
|
+
|
29
|
+
export const Standard = Template.bind({});
|
30
|
+
Standard.args = {
|
31
|
+
classes: "tna-profile--demo",
|
32
|
+
};
|
@@ -0,0 +1,15 @@
|
|
1
|
+
{%- set containerClasses = [params.classes] if params.classes else [] -%}
|
2
|
+
<div class="tna-profile tna-container {{ containerClasses | join(' ') }}" {%- for attribute, value in params.attributes %} {{ attribute }}="{{ value }}"{% endfor %}>
|
3
|
+
<div class="tna-column tna-column--order-2">
|
4
|
+
<img src="https://avatar.iran.liara.run/public" width="200" height="200" />
|
5
|
+
</div>
|
6
|
+
<div class="tna-column tna-column--flex-1 tna-column--full-small tna-column--full-tiny tna-column--order-1 tna-column--order-3-small tna-column--order-3-tiny">
|
7
|
+
<hgroup class="tna-hgroup tna-hgroup--xl">
|
8
|
+
<p class="tna-hgroup__supertitle">Profile</p>
|
9
|
+
<h1 class="tna-hgroup__title tna-heading">Max Smith</h1>
|
10
|
+
</hgroup>
|
11
|
+
<p>
|
12
|
+
Master of Documents
|
13
|
+
</p>
|
14
|
+
</div>
|
15
|
+
</div>
|
@@ -13,7 +13,7 @@
|
|
13
13
|
"warning": "This is a gory photo",
|
14
14
|
"action": "Show me the gory photo"
|
15
15
|
},
|
16
|
-
"html": "<div class=\"tna-sensitive-image \" data-module=\"tna-sensitive-image\" style=\"--sensitive-image: url('https://picsum.photos/id/237/800/600'); --sensitive-image-width: 800; --sensitive-image-height: 600\"
|
16
|
+
"html": "<div class=\"tna-sensitive-image \" data-module=\"tna-sensitive-image\" style=\"--sensitive-image: url('https://picsum.photos/id/237/800/600'); --sensitive-image-width: 800; --sensitive-image-height: 600\"><p class=\"tna-sensitive-image__warning\">This is a gory photo</p><details class=\"tna-sensitive-image__details\"><summary class=\"tna-sensitive-image__show\" data-action=\"Show me the gory photo\">Show me the gory photo</summary><div class=\"tna-sensitive-image__container\"><img src=\"https://picsum.photos/id/237/800/600\" alt=\"A placeholder image\" class=\"tna-sensitive-image__image\" /></div></details></div>",
|
17
17
|
"hidden": false
|
18
18
|
},
|
19
19
|
{
|
@@ -29,7 +29,7 @@
|
|
29
29
|
"action": "Show me the gory photo",
|
30
30
|
"classes": "sensitive-image__test-class"
|
31
31
|
},
|
32
|
-
"html": "<div class=\"tna-sensitive-image sensitive-image__test-class\" data-module=\"tna-sensitive-image\" style=\"--sensitive-image: url('https://picsum.photos/id/237/800/600'); --sensitive-image-width: 800; --sensitive-image-height: 600\"
|
32
|
+
"html": "<div class=\"tna-sensitive-image sensitive-image__test-class\" data-module=\"tna-sensitive-image\" style=\"--sensitive-image: url('https://picsum.photos/id/237/800/600'); --sensitive-image-width: 800; --sensitive-image-height: 600\"><p class=\"tna-sensitive-image__warning\">This is a gory photo</p><details class=\"tna-sensitive-image__details\"><summary class=\"tna-sensitive-image__show\" data-action=\"Show me the gory photo\">Show me the gory photo</summary><div class=\"tna-sensitive-image__container\"><img src=\"https://picsum.photos/id/237/800/600\" alt=\"A placeholder image\" class=\"tna-sensitive-image__image\" /></div></details></div>",
|
33
33
|
"hidden": false
|
34
34
|
},
|
35
35
|
{
|
@@ -47,7 +47,7 @@
|
|
47
47
|
"data-testattribute": "foobar"
|
48
48
|
}
|
49
49
|
},
|
50
|
-
"html": "<div class=\"tna-sensitive-image \" data-module=\"tna-sensitive-image\" style=\"--sensitive-image: url('https://picsum.photos/id/237/800/600'); --sensitive-image-width: 800; --sensitive-image-height: 600\" data-testattribute=\"foobar\"
|
50
|
+
"html": "<div class=\"tna-sensitive-image \" data-module=\"tna-sensitive-image\" style=\"--sensitive-image: url('https://picsum.photos/id/237/800/600'); --sensitive-image-width: 800; --sensitive-image-height: 600\" data-testattribute=\"foobar\"><p class=\"tna-sensitive-image__warning\">This is a gory photo</p><details class=\"tna-sensitive-image__details\"><summary class=\"tna-sensitive-image__show\" data-action=\"Show me the gory photo\">Show me the gory photo</summary><div class=\"tna-sensitive-image__container\"><img src=\"https://picsum.photos/id/237/800/600\" alt=\"A placeholder image\" class=\"tna-sensitive-image__image\" /></div></details></div>",
|
51
51
|
"hidden": false
|
52
52
|
}
|
53
53
|
]
|
@@ -1,5 +1,4 @@
|
|
1
1
|
import SensitiveImage from "./template.njk";
|
2
|
-
import "./_index.scss";
|
3
2
|
import macroOptions from "./macro-options.json";
|
4
3
|
import { expect } from "@storybook/jest";
|
5
4
|
import { within, userEvent } from "@storybook/testing-library";
|
@@ -20,7 +19,7 @@ Object.keys(argTypes).forEach((argType) => {
|
|
20
19
|
});
|
21
20
|
|
22
21
|
export default {
|
23
|
-
title: "Experimental/Sensitive image",
|
22
|
+
title: "Experimental/Components/Sensitive image",
|
24
23
|
argTypes,
|
25
24
|
};
|
26
25
|
|
@@ -0,0 +1,148 @@
|
|
1
|
+
@use "../../tools/colour";
|
2
|
+
|
3
|
+
.tna-tabs {
|
4
|
+
margin-bottom: 1rem;
|
5
|
+
|
6
|
+
&__list {
|
7
|
+
margin: 0 0 1rem;
|
8
|
+
padding: 0;
|
9
|
+
|
10
|
+
display: flex;
|
11
|
+
align-items: stretch;
|
12
|
+
|
13
|
+
list-style: none;
|
14
|
+
}
|
15
|
+
|
16
|
+
&__list-item {
|
17
|
+
display: inline-flex;
|
18
|
+
|
19
|
+
& + & {
|
20
|
+
margin-left: 1rem;
|
21
|
+
}
|
22
|
+
}
|
23
|
+
|
24
|
+
&__list-item-link {
|
25
|
+
padding: 0.5rem 0;
|
26
|
+
|
27
|
+
display: flex;
|
28
|
+
|
29
|
+
align-items: center;
|
30
|
+
position: relative;
|
31
|
+
|
32
|
+
@include colour.colour-font("font-dark");
|
33
|
+
font-size: inherit;
|
34
|
+
font-family: inherit;
|
35
|
+
font-weight: 700;
|
36
|
+
text-decoration: none;
|
37
|
+
line-height: 1.5;
|
38
|
+
text-align: center;
|
39
|
+
|
40
|
+
background: transparent;
|
41
|
+
|
42
|
+
border: none;
|
43
|
+
|
44
|
+
cursor: pointer;
|
45
|
+
|
46
|
+
& + & {
|
47
|
+
margin-left: 1.5rem;
|
48
|
+
}
|
49
|
+
|
50
|
+
&::after {
|
51
|
+
height: 0;
|
52
|
+
|
53
|
+
position: absolute;
|
54
|
+
right: 0;
|
55
|
+
bottom: 0;
|
56
|
+
left: 0;
|
57
|
+
|
58
|
+
@include colour.colour-background("keyline-dark");
|
59
|
+
|
60
|
+
content: "";
|
61
|
+
}
|
62
|
+
|
63
|
+
&:hover,
|
64
|
+
&--selected,
|
65
|
+
&--selected:hover {
|
66
|
+
&::after {
|
67
|
+
height: 0.25rem;
|
68
|
+
}
|
69
|
+
}
|
70
|
+
|
71
|
+
.tna-template--js-enabled & {
|
72
|
+
@include colour.colour-font("font-light");
|
73
|
+
|
74
|
+
&:hover {
|
75
|
+
&::after {
|
76
|
+
height: 0.125rem;
|
77
|
+
}
|
78
|
+
}
|
79
|
+
|
80
|
+
&--selected {
|
81
|
+
@include colour.colour-font("font-dark");
|
82
|
+
|
83
|
+
&::after,
|
84
|
+
&:hover::after {
|
85
|
+
height: 0.25rem;
|
86
|
+
}
|
87
|
+
}
|
88
|
+
}
|
89
|
+
}
|
90
|
+
|
91
|
+
&__items {
|
92
|
+
// &:not(:target-within) {
|
93
|
+
// .tna-tabs__item:first-child {
|
94
|
+
// display: block;
|
95
|
+
// }
|
96
|
+
// }
|
97
|
+
}
|
98
|
+
|
99
|
+
&__item {
|
100
|
+
display: none;
|
101
|
+
|
102
|
+
&:first-child {
|
103
|
+
display: block;
|
104
|
+
}
|
105
|
+
|
106
|
+
&:has(~ :target) {
|
107
|
+
display: none;
|
108
|
+
}
|
109
|
+
|
110
|
+
&:target {
|
111
|
+
display: block;
|
112
|
+
}
|
113
|
+
|
114
|
+
.tna-template--js-enabled & {
|
115
|
+
display: block;
|
116
|
+
|
117
|
+
&[hidden] {
|
118
|
+
display: none;
|
119
|
+
}
|
120
|
+
}
|
121
|
+
|
122
|
+
.tna-template--clicked &:focus {
|
123
|
+
outline: none;
|
124
|
+
}
|
125
|
+
}
|
126
|
+
|
127
|
+
@mixin high-contrast {
|
128
|
+
&__list-item-link {
|
129
|
+
padding-right: 1rem;
|
130
|
+
padding-left: 1rem;
|
131
|
+
|
132
|
+
overflow: hidden;
|
133
|
+
|
134
|
+
border: 1px transparent solid;
|
135
|
+
@include colour.colour-border("keyline-dark");
|
136
|
+
}
|
137
|
+
}
|
138
|
+
|
139
|
+
.tna-template--high-contrast-theme & {
|
140
|
+
@include high-contrast;
|
141
|
+
}
|
142
|
+
|
143
|
+
@media (prefers-contrast: more) {
|
144
|
+
.tna-template--system-theme & {
|
145
|
+
@include high-contrast;
|
146
|
+
}
|
147
|
+
}
|
148
|
+
}
|
@@ -0,0 +1,52 @@
|
|
1
|
+
[
|
2
|
+
{
|
3
|
+
"name": "title",
|
4
|
+
"type": "string",
|
5
|
+
"required": true,
|
6
|
+
"description": ""
|
7
|
+
},
|
8
|
+
{
|
9
|
+
"name": "items",
|
10
|
+
"type": "array",
|
11
|
+
"required": true,
|
12
|
+
"description": "",
|
13
|
+
"params": [
|
14
|
+
{
|
15
|
+
"name": "id",
|
16
|
+
"type": "string",
|
17
|
+
"required": true,
|
18
|
+
"description": ""
|
19
|
+
},
|
20
|
+
{
|
21
|
+
"name": "title",
|
22
|
+
"type": "string",
|
23
|
+
"required": true,
|
24
|
+
"description": ""
|
25
|
+
},
|
26
|
+
{
|
27
|
+
"name": "body",
|
28
|
+
"type": "string",
|
29
|
+
"required": true,
|
30
|
+
"description": ""
|
31
|
+
}
|
32
|
+
]
|
33
|
+
},
|
34
|
+
{
|
35
|
+
"name": "sticky",
|
36
|
+
"type": "boolean",
|
37
|
+
"required": false,
|
38
|
+
"description": ""
|
39
|
+
},
|
40
|
+
{
|
41
|
+
"name": "classes",
|
42
|
+
"type": "string",
|
43
|
+
"required": false,
|
44
|
+
"description": "Classes to add to the tabs."
|
45
|
+
},
|
46
|
+
{
|
47
|
+
"name": "attributes",
|
48
|
+
"type": "object",
|
49
|
+
"required": false,
|
50
|
+
"description": "HTML attributes (for example data attributes) to add to the tabs."
|
51
|
+
}
|
52
|
+
]
|
@@ -0,0 +1,2 @@
|
|
1
|
+
!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define("TNAFrontend",[],e):"object"==typeof exports?exports.TNAFrontend=e():(t.TNAFrontend=t.TNAFrontend||{},t.TNAFrontend["components/tabs/tabs"]=e())}(self,(()=>(()=>{"use strict";var t={d:(e,i)=>{for(var n in i)t.o(i,n)&&!t.o(e,n)&&Object.defineProperty(e,n,{enumerable:!0,get:i[n]})},o:(t,e)=>Object.prototype.hasOwnProperty.call(t,e),r:t=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})}},e={};function i(t){return i="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},i(t)}function n(t){return function(t){if(Array.isArray(t))return r(t)}(t)||function(t){if("undefined"!=typeof Symbol&&null!=t[Symbol.iterator]||null!=t["@@iterator"])return Array.from(t)}(t)||function(t,e){if(t){if("string"==typeof t)return r(t,e);var i=Object.prototype.toString.call(t).slice(8,-1);return"Object"===i&&t.constructor&&(i=t.constructor.name),"Map"===i||"Set"===i?Array.from(t):"Arguments"===i||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(i)?r(t,e):void 0}}(t)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function r(t,e){(null==e||e>t.length)&&(e=t.length);for(var i=0,n=new Array(e);i<e;i++)n[i]=t[i];return n}function s(t,e){for(var n=0;n<e.length;n++){var r=e[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(t,(void 0,s=function(t,e){if("object"!==i(t)||null===t)return t;var n=t[Symbol.toPrimitive];if(void 0!==n){var r=n.call(t,"string");if("object"!==i(r))return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(t)}(r.key),"symbol"===i(s)?s:String(s)),r)}var s}t.r(e),t.d(e,{Tabs:()=>a});var a=function(){function t(e){!function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,t),this.$module=e,this.$tabList=e&&e.querySelector(".tna-tabs__list"),this.$tabListItemLinks=e&&this.$tabList&&e.querySelectorAll(".tna-tabs__list-item-link"),this.$tabItems=e&&e.querySelectorAll(".tna-tabs__item")}var e,i;return e=t,(i=[{key:"init",value:function(){var t=this;if(this.$module&&this.$tabList&&this.$tabListItemLinks&&this.$tabItems&&this.$tabListItemLinks.length===this.$tabItems.length){this.sticky=this.$module.classList.contains("tna-tabs--sticky");var e=window.location.hash.replace(/^#/,"");this.$newTabList=document.createElement("div"),this.$newTabList.setAttribute("role","tablist"),this.$newTabList.setAttribute("class",this.$tabList.getAttribute("class")),this.$tabItems.forEach((function(t,i){t.setAttribute("role","tabpanel"),t.setAttribute("aria-labelledby","".concat(t.getAttribute("id"),"-tab")),t.setAttribute("tabindex","0"),(e&&t.getAttribute("id")!==e||!e&&i>0)&&t.setAttribute("hidden",!0)})),this.$tabListItemLinks.forEach((function(e){var i=document.createElement("button");i.innerText=e.innerText,i.setAttribute("class",e.getAttribute("class")),i.setAttribute("role","tab"),i.setAttribute("id",e.getAttribute("id")),i.setAttribute("aria-controls",e.getAttribute("href").replace(/^#/,"")),i.setAttribute("tabindex","-1"),t.$newTabList.appendChild(i)})),this.$tabList.replaceWith(this.$newTabList),this.$tabListItemLinks=this.$module.querySelectorAll(".tna-tabs__list-item-link"),this.$tabListItemLinks.forEach((function(i,n){e&&i.getAttribute("aria-controls")==="".concat(e)||!e&&0===n?(i.classList.add("tna-tabs__list-item-link--selected"),i.setAttribute("aria-selected",!0),i.setAttribute("tabindex","0")):i.setAttribute("aria-selected",!1),i.addEventListener("keydown",(function(e){return t.handleItemLinkKeyDown(e)}),!0),i.addEventListener("click",(function(e){return t.handleItemLinkClick(e)}),!0)}))}}},{key:"handleItemLinkClick",value:function(t){t.preventDefault();var e=t.currentTarget.getAttribute("aria-controls");this.switchTab(e)}},{key:"handleItemLinkKeyDown",value:function(t){var e=t.currentTarget,i=!1;switch(t.key){case"ArrowLeft":this.setSelectedToPreviousTab(e),i=!0;break;case"ArrowRight":this.setSelectedToNextTab(e),i=!0;break;case"Home":this.switchTab(this.$tabListItemLinks[0].getAttribute("aria-controls")),i=!0;break;case"End":this.switchTab(this.$tabListItemLinks[this.$tabListItemLinks.length-1].getAttribute("aria-controls")),i=!0}i&&(t.stopPropagation(),t.preventDefault())}},{key:"setSelectedToNextTab",value:function(t){console.log("setSelectedToNextTab",t);var e,i=n(this.$tabListItemLinks).findIndex((function(e){return e.getAttribute("id")===t.getAttribute("id")}));e=i<this.$tabListItemLinks.length-1?i+1:0,console.log(i,e),this.switchTab(this.$tabListItemLinks[e].getAttribute("aria-controls"))}},{key:"setSelectedToPreviousTab",value:function(t){console.log("setSelectedToPreviousTab",t);var e,i=n(this.$tabListItemLinks).findIndex((function(e){return e.getAttribute("id")===t.getAttribute("id")}));e=i>=1?i-1:this.$tabListItemLinks.length-1,console.log(i,e),this.switchTab(this.$tabListItemLinks[e].getAttribute("aria-controls"))}},{key:"switchTab",value:function(t){this.$tabListItemLinks.forEach((function(e){e.getAttribute("aria-controls")===t?(e.classList.add("tna-tabs__list-item-link--selected"),e.setAttribute("aria-selected",!0),e.setAttribute("tabindex","0"),e.focus()):(e.classList.remove("tna-tabs__list-item-link--selected"),e.setAttribute("aria-selected",!1),e.setAttribute("tabindex","-1"))})),this.$tabItems.forEach((function(e){e.getAttribute("id")===t?(e.removeAttribute("hidden"),e.setAttribute("tabindex","0")):(e.setAttribute("hidden",!0),e.setAttribute("tabindex","-1"))})),this.sticky&&(history.replaceState?history.replaceState(null,null,"#".concat(t)):location.hash="#".concat(t))}}])&&s(e.prototype,i),Object.defineProperty(e,"prototype",{writable:!1}),t}();return e})()));
|
2
|
+
//# sourceMappingURL=tabs.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"components/tabs/tabs.js","mappings":"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","sources":["webpack://TNAFrontend/webpack/universalModuleDefinition","webpack://TNAFrontend/webpack/bootstrap","webpack://TNAFrontend/webpack/runtime/define property getters","webpack://TNAFrontend/webpack/runtime/hasOwnProperty shorthand","webpack://TNAFrontend/webpack/runtime/make namespace object","webpack://TNAFrontend/./src/nationalarchives/components/tabs/tabs.mjs"],"sourcesContent":["(function webpackUniversalModuleDefinition(root, factory) {\n\tif(typeof exports === 'object' && typeof module === 'object')\n\t\tmodule.exports = factory();\n\telse if(typeof define === 'function' && define.amd)\n\t\tdefine(\"TNAFrontend\", [], factory);\n\telse if(typeof exports === 'object')\n\t\texports[\"TNAFrontend\"] = factory();\n\telse\n\t\troot[\"TNAFrontend\"] = root[\"TNAFrontend\"] || {}, root[\"TNAFrontend\"][\"components/tabs/tabs\"] = factory();\n})(self, () => {\nreturn ","// The require scope\nvar __webpack_require__ = {};\n\n","// define getter functions for harmony exports\n__webpack_require__.d = (exports, definition) => {\n\tfor(var key in definition) {\n\t\tif(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {\n\t\t\tObject.defineProperty(exports, key, { enumerable: true, get: definition[key] });\n\t\t}\n\t}\n};","__webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))","// define __esModule on exports\n__webpack_require__.r = (exports) => {\n\tif(typeof Symbol !== 'undefined' && Symbol.toStringTag) {\n\t\tObject.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });\n\t}\n\tObject.defineProperty(exports, '__esModule', { value: true });\n};","export class Tabs {\n constructor($module) {\n this.$module = $module;\n this.$tabList = $module && $module.querySelector(\".tna-tabs__list\");\n this.$tabListItemLinks =\n $module &&\n this.$tabList &&\n $module.querySelectorAll(\".tna-tabs__list-item-link\");\n this.$tabItems = $module && $module.querySelectorAll(\".tna-tabs__item\");\n }\n\n init() {\n if (\n !this.$module ||\n !this.$tabList ||\n !this.$tabListItemLinks ||\n !this.$tabItems ||\n this.$tabListItemLinks.length !== this.$tabItems.length\n ) {\n return;\n }\n\n this.sticky = this.$module.classList.contains(\"tna-tabs--sticky\");\n\n const startingTarget = window.location.hash.replace(/^#/, \"\");\n\n this.$newTabList = document.createElement(\"div\");\n this.$newTabList.setAttribute(\"role\", \"tablist\");\n this.$newTabList.setAttribute(\"class\", this.$tabList.getAttribute(\"class\"));\n\n this.$tabItems.forEach(($tabItem, index) => {\n $tabItem.setAttribute(\"role\", \"tabpanel\");\n $tabItem.setAttribute(\n \"aria-labelledby\",\n `${$tabItem.getAttribute(\"id\")}-tab`,\n );\n $tabItem.setAttribute(\"tabindex\", \"0\");\n if (\n (startingTarget && $tabItem.getAttribute(\"id\") !== startingTarget) ||\n (!startingTarget && index > 0)\n ) {\n $tabItem.setAttribute(\"hidden\", true);\n }\n });\n\n this.$tabListItemLinks.forEach(($tabListItemLink) => {\n const $replacementButton = document.createElement(\"button\");\n $replacementButton.innerText = $tabListItemLink.innerText;\n $replacementButton.setAttribute(\n \"class\",\n $tabListItemLink.getAttribute(\"class\"),\n );\n $replacementButton.setAttribute(\"role\", \"tab\");\n $replacementButton.setAttribute(\n \"id\",\n $tabListItemLink.getAttribute(\"id\"),\n );\n $replacementButton.setAttribute(\n \"aria-controls\",\n $tabListItemLink.getAttribute(\"href\").replace(/^#/, \"\"),\n );\n $replacementButton.setAttribute(\"tabindex\", \"-1\");\n this.$newTabList.appendChild($replacementButton);\n });\n\n this.$tabList.replaceWith(this.$newTabList);\n\n this.$tabListItemLinks = this.$module.querySelectorAll(\n \".tna-tabs__list-item-link\",\n );\n\n this.$tabListItemLinks.forEach(($tabListItemLink, index) => {\n if (\n (startingTarget &&\n $tabListItemLink.getAttribute(\"aria-controls\") ===\n `${startingTarget}`) ||\n (!startingTarget && index === 0)\n ) {\n $tabListItemLink.classList.add(\"tna-tabs__list-item-link--selected\");\n $tabListItemLink.setAttribute(\"aria-selected\", true);\n $tabListItemLink.setAttribute(\"tabindex\", \"0\");\n } else {\n $tabListItemLink.setAttribute(\"aria-selected\", false);\n }\n\n $tabListItemLink.addEventListener(\n \"keydown\",\n (e) => this.handleItemLinkKeyDown(e),\n true,\n );\n $tabListItemLink.addEventListener(\n \"click\",\n (e) => this.handleItemLinkClick(e),\n true,\n );\n });\n }\n\n handleItemLinkClick(itemLinkClickEvent) {\n itemLinkClickEvent.preventDefault();\n const targetItem =\n itemLinkClickEvent.currentTarget.getAttribute(\"aria-controls\");\n\n this.switchTab(targetItem);\n }\n\n handleItemLinkKeyDown(itemLinkKeyDownEvent) {\n const targetItem = itemLinkKeyDownEvent.currentTarget;\n let overwriteKeyAction = false;\n\n switch (itemLinkKeyDownEvent.key) {\n case \"ArrowLeft\":\n this.setSelectedToPreviousTab(targetItem);\n overwriteKeyAction = true;\n break;\n\n case \"ArrowRight\":\n this.setSelectedToNextTab(targetItem);\n overwriteKeyAction = true;\n break;\n\n case \"Home\":\n this.switchTab(this.$tabListItemLinks[0].getAttribute(\"aria-controls\"));\n overwriteKeyAction = true;\n break;\n\n case \"End\":\n this.switchTab(\n this.$tabListItemLinks[\n this.$tabListItemLinks.length - 1\n ].getAttribute(\"aria-controls\"),\n );\n overwriteKeyAction = true;\n break;\n\n default:\n break;\n }\n\n if (overwriteKeyAction) {\n itemLinkKeyDownEvent.stopPropagation();\n itemLinkKeyDownEvent.preventDefault();\n }\n }\n\n setSelectedToNextTab(targetItem) {\n console.log(\"setSelectedToNextTab\", targetItem);\n const currentIndex = [...this.$tabListItemLinks].findIndex(\n ($tabListItemLink) =>\n $tabListItemLink.getAttribute(\"id\") === targetItem.getAttribute(\"id\"),\n );\n let newIndex;\n if (currentIndex < this.$tabListItemLinks.length - 1) {\n newIndex = currentIndex + 1;\n } else {\n newIndex = 0;\n }\n console.log(currentIndex, newIndex);\n this.switchTab(\n this.$tabListItemLinks[newIndex].getAttribute(\"aria-controls\"),\n );\n }\n\n setSelectedToPreviousTab(targetItem) {\n console.log(\"setSelectedToPreviousTab\", targetItem);\n const currentIndex = [...this.$tabListItemLinks].findIndex(\n ($tabListItemLink) =>\n $tabListItemLink.getAttribute(\"id\") === targetItem.getAttribute(\"id\"),\n );\n let newIndex;\n if (currentIndex >= 1) {\n newIndex = currentIndex - 1;\n } else {\n newIndex = this.$tabListItemLinks.length - 1;\n }\n console.log(currentIndex, newIndex);\n this.switchTab(\n this.$tabListItemLinks[newIndex].getAttribute(\"aria-controls\"),\n );\n }\n\n switchTab(targetId) {\n this.$tabListItemLinks.forEach(($tabListItemLink) => {\n if ($tabListItemLink.getAttribute(\"aria-controls\") === targetId) {\n $tabListItemLink.classList.add(\"tna-tabs__list-item-link--selected\");\n $tabListItemLink.setAttribute(\"aria-selected\", true);\n $tabListItemLink.setAttribute(\"tabindex\", \"0\");\n $tabListItemLink.focus();\n } else {\n $tabListItemLink.classList.remove(\"tna-tabs__list-item-link--selected\");\n $tabListItemLink.setAttribute(\"aria-selected\", false);\n $tabListItemLink.setAttribute(\"tabindex\", \"-1\");\n }\n });\n\n this.$tabItems.forEach(($tabItem) => {\n if ($tabItem.getAttribute(\"id\") === targetId) {\n $tabItem.removeAttribute(\"hidden\");\n $tabItem.setAttribute(\"tabindex\", \"0\");\n } else {\n $tabItem.setAttribute(\"hidden\", true);\n $tabItem.setAttribute(\"tabindex\", \"-1\");\n }\n });\n\n if (this.sticky) {\n if (history.replaceState) {\n history.replaceState(null, null, `#${targetId}`);\n } else {\n location.hash = `#${targetId}`;\n }\n }\n }\n}\n"],"names":["root","factory","exports","module","define","amd","self","__webpack_require__","definition","key","o","Object","defineProperty","enumerable","get","obj","prop","prototype","hasOwnProperty","call","Symbol","toStringTag","value","Tabs","$module","_classCallCheck","this","$tabList","querySelector","$tabListItemLinks","querySelectorAll","$tabItems","_this","length","sticky","classList","contains","startingTarget","window","location","hash","replace","$newTabList","document","createElement","setAttribute","getAttribute","forEach","$tabItem","index","concat","$tabListItemLink","$replacementButton","innerText","appendChild","replaceWith","add","addEventListener","e","handleItemLinkKeyDown","handleItemLinkClick","itemLinkClickEvent","preventDefault","targetItem","currentTarget","switchTab","itemLinkKeyDownEvent","overwriteKeyAction","setSelectedToPreviousTab","setSelectedToNextTab","stopPropagation","console","log","newIndex","currentIndex","_toConsumableArray","findIndex","targetId","focus","remove","removeAttribute","history","replaceState"],"sourceRoot":""}
|
@@ -0,0 +1,214 @@
|
|
1
|
+
export class Tabs {
|
2
|
+
constructor($module) {
|
3
|
+
this.$module = $module;
|
4
|
+
this.$tabList = $module && $module.querySelector(".tna-tabs__list");
|
5
|
+
this.$tabListItemLinks =
|
6
|
+
$module &&
|
7
|
+
this.$tabList &&
|
8
|
+
$module.querySelectorAll(".tna-tabs__list-item-link");
|
9
|
+
this.$tabItems = $module && $module.querySelectorAll(".tna-tabs__item");
|
10
|
+
}
|
11
|
+
|
12
|
+
init() {
|
13
|
+
if (
|
14
|
+
!this.$module ||
|
15
|
+
!this.$tabList ||
|
16
|
+
!this.$tabListItemLinks ||
|
17
|
+
!this.$tabItems ||
|
18
|
+
this.$tabListItemLinks.length !== this.$tabItems.length
|
19
|
+
) {
|
20
|
+
return;
|
21
|
+
}
|
22
|
+
|
23
|
+
this.sticky = this.$module.classList.contains("tna-tabs--sticky");
|
24
|
+
|
25
|
+
const startingTarget = window.location.hash.replace(/^#/, "");
|
26
|
+
|
27
|
+
this.$newTabList = document.createElement("div");
|
28
|
+
this.$newTabList.setAttribute("role", "tablist");
|
29
|
+
this.$newTabList.setAttribute("class", this.$tabList.getAttribute("class"));
|
30
|
+
|
31
|
+
this.$tabItems.forEach(($tabItem, index) => {
|
32
|
+
$tabItem.setAttribute("role", "tabpanel");
|
33
|
+
$tabItem.setAttribute(
|
34
|
+
"aria-labelledby",
|
35
|
+
`${$tabItem.getAttribute("id")}-tab`,
|
36
|
+
);
|
37
|
+
$tabItem.setAttribute("tabindex", "0");
|
38
|
+
if (
|
39
|
+
(startingTarget && $tabItem.getAttribute("id") !== startingTarget) ||
|
40
|
+
(!startingTarget && index > 0)
|
41
|
+
) {
|
42
|
+
$tabItem.setAttribute("hidden", true);
|
43
|
+
}
|
44
|
+
});
|
45
|
+
|
46
|
+
this.$tabListItemLinks.forEach(($tabListItemLink) => {
|
47
|
+
const $replacementButton = document.createElement("button");
|
48
|
+
$replacementButton.innerText = $tabListItemLink.innerText;
|
49
|
+
$replacementButton.setAttribute(
|
50
|
+
"class",
|
51
|
+
$tabListItemLink.getAttribute("class"),
|
52
|
+
);
|
53
|
+
$replacementButton.setAttribute("role", "tab");
|
54
|
+
$replacementButton.setAttribute(
|
55
|
+
"id",
|
56
|
+
$tabListItemLink.getAttribute("id"),
|
57
|
+
);
|
58
|
+
$replacementButton.setAttribute(
|
59
|
+
"aria-controls",
|
60
|
+
$tabListItemLink.getAttribute("href").replace(/^#/, ""),
|
61
|
+
);
|
62
|
+
$replacementButton.setAttribute("tabindex", "-1");
|
63
|
+
this.$newTabList.appendChild($replacementButton);
|
64
|
+
});
|
65
|
+
|
66
|
+
this.$tabList.replaceWith(this.$newTabList);
|
67
|
+
|
68
|
+
this.$tabListItemLinks = this.$module.querySelectorAll(
|
69
|
+
".tna-tabs__list-item-link",
|
70
|
+
);
|
71
|
+
|
72
|
+
this.$tabListItemLinks.forEach(($tabListItemLink, index) => {
|
73
|
+
if (
|
74
|
+
(startingTarget &&
|
75
|
+
$tabListItemLink.getAttribute("aria-controls") ===
|
76
|
+
`${startingTarget}`) ||
|
77
|
+
(!startingTarget && index === 0)
|
78
|
+
) {
|
79
|
+
$tabListItemLink.classList.add("tna-tabs__list-item-link--selected");
|
80
|
+
$tabListItemLink.setAttribute("aria-selected", true);
|
81
|
+
$tabListItemLink.setAttribute("tabindex", "0");
|
82
|
+
} else {
|
83
|
+
$tabListItemLink.setAttribute("aria-selected", false);
|
84
|
+
}
|
85
|
+
|
86
|
+
$tabListItemLink.addEventListener(
|
87
|
+
"keydown",
|
88
|
+
(e) => this.handleItemLinkKeyDown(e),
|
89
|
+
true,
|
90
|
+
);
|
91
|
+
$tabListItemLink.addEventListener(
|
92
|
+
"click",
|
93
|
+
(e) => this.handleItemLinkClick(e),
|
94
|
+
true,
|
95
|
+
);
|
96
|
+
});
|
97
|
+
}
|
98
|
+
|
99
|
+
handleItemLinkClick(itemLinkClickEvent) {
|
100
|
+
itemLinkClickEvent.preventDefault();
|
101
|
+
const targetItem =
|
102
|
+
itemLinkClickEvent.currentTarget.getAttribute("aria-controls");
|
103
|
+
|
104
|
+
this.switchTab(targetItem);
|
105
|
+
}
|
106
|
+
|
107
|
+
handleItemLinkKeyDown(itemLinkKeyDownEvent) {
|
108
|
+
const targetItem = itemLinkKeyDownEvent.currentTarget;
|
109
|
+
let overwriteKeyAction = false;
|
110
|
+
|
111
|
+
switch (itemLinkKeyDownEvent.key) {
|
112
|
+
case "ArrowLeft":
|
113
|
+
this.setSelectedToPreviousTab(targetItem);
|
114
|
+
overwriteKeyAction = true;
|
115
|
+
break;
|
116
|
+
|
117
|
+
case "ArrowRight":
|
118
|
+
this.setSelectedToNextTab(targetItem);
|
119
|
+
overwriteKeyAction = true;
|
120
|
+
break;
|
121
|
+
|
122
|
+
case "Home":
|
123
|
+
this.switchTab(this.$tabListItemLinks[0].getAttribute("aria-controls"));
|
124
|
+
overwriteKeyAction = true;
|
125
|
+
break;
|
126
|
+
|
127
|
+
case "End":
|
128
|
+
this.switchTab(
|
129
|
+
this.$tabListItemLinks[
|
130
|
+
this.$tabListItemLinks.length - 1
|
131
|
+
].getAttribute("aria-controls"),
|
132
|
+
);
|
133
|
+
overwriteKeyAction = true;
|
134
|
+
break;
|
135
|
+
|
136
|
+
default:
|
137
|
+
break;
|
138
|
+
}
|
139
|
+
|
140
|
+
if (overwriteKeyAction) {
|
141
|
+
itemLinkKeyDownEvent.stopPropagation();
|
142
|
+
itemLinkKeyDownEvent.preventDefault();
|
143
|
+
}
|
144
|
+
}
|
145
|
+
|
146
|
+
setSelectedToNextTab(targetItem) {
|
147
|
+
console.log("setSelectedToNextTab", targetItem);
|
148
|
+
const currentIndex = [...this.$tabListItemLinks].findIndex(
|
149
|
+
($tabListItemLink) =>
|
150
|
+
$tabListItemLink.getAttribute("id") === targetItem.getAttribute("id"),
|
151
|
+
);
|
152
|
+
let newIndex;
|
153
|
+
if (currentIndex < this.$tabListItemLinks.length - 1) {
|
154
|
+
newIndex = currentIndex + 1;
|
155
|
+
} else {
|
156
|
+
newIndex = 0;
|
157
|
+
}
|
158
|
+
console.log(currentIndex, newIndex);
|
159
|
+
this.switchTab(
|
160
|
+
this.$tabListItemLinks[newIndex].getAttribute("aria-controls"),
|
161
|
+
);
|
162
|
+
}
|
163
|
+
|
164
|
+
setSelectedToPreviousTab(targetItem) {
|
165
|
+
console.log("setSelectedToPreviousTab", targetItem);
|
166
|
+
const currentIndex = [...this.$tabListItemLinks].findIndex(
|
167
|
+
($tabListItemLink) =>
|
168
|
+
$tabListItemLink.getAttribute("id") === targetItem.getAttribute("id"),
|
169
|
+
);
|
170
|
+
let newIndex;
|
171
|
+
if (currentIndex >= 1) {
|
172
|
+
newIndex = currentIndex - 1;
|
173
|
+
} else {
|
174
|
+
newIndex = this.$tabListItemLinks.length - 1;
|
175
|
+
}
|
176
|
+
console.log(currentIndex, newIndex);
|
177
|
+
this.switchTab(
|
178
|
+
this.$tabListItemLinks[newIndex].getAttribute("aria-controls"),
|
179
|
+
);
|
180
|
+
}
|
181
|
+
|
182
|
+
switchTab(targetId) {
|
183
|
+
this.$tabListItemLinks.forEach(($tabListItemLink) => {
|
184
|
+
if ($tabListItemLink.getAttribute("aria-controls") === targetId) {
|
185
|
+
$tabListItemLink.classList.add("tna-tabs__list-item-link--selected");
|
186
|
+
$tabListItemLink.setAttribute("aria-selected", true);
|
187
|
+
$tabListItemLink.setAttribute("tabindex", "0");
|
188
|
+
$tabListItemLink.focus();
|
189
|
+
} else {
|
190
|
+
$tabListItemLink.classList.remove("tna-tabs__list-item-link--selected");
|
191
|
+
$tabListItemLink.setAttribute("aria-selected", false);
|
192
|
+
$tabListItemLink.setAttribute("tabindex", "-1");
|
193
|
+
}
|
194
|
+
});
|
195
|
+
|
196
|
+
this.$tabItems.forEach(($tabItem) => {
|
197
|
+
if ($tabItem.getAttribute("id") === targetId) {
|
198
|
+
$tabItem.removeAttribute("hidden");
|
199
|
+
$tabItem.setAttribute("tabindex", "0");
|
200
|
+
} else {
|
201
|
+
$tabItem.setAttribute("hidden", true);
|
202
|
+
$tabItem.setAttribute("tabindex", "-1");
|
203
|
+
}
|
204
|
+
});
|
205
|
+
|
206
|
+
if (this.sticky) {
|
207
|
+
if (history.replaceState) {
|
208
|
+
history.replaceState(null, null, `#${targetId}`);
|
209
|
+
} else {
|
210
|
+
location.hash = `#${targetId}`;
|
211
|
+
}
|
212
|
+
}
|
213
|
+
}
|
214
|
+
}
|