@ons/design-system 53.1.1 → 55.0.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/components/accordion/_macro.njk +2 -3
- package/components/accordion/_macro.spec.js +3 -40
- package/components/accordion/accordion.dom.js +19 -0
- package/components/{collapsible/collapsible.group.js → accordion/accordion.js} +12 -5
- package/components/accordion/accordion.spec.js +56 -51
- package/components/autosuggest/_autosuggest.scss +4 -4
- package/components/autosuggest/autosuggest.spec.js +12 -2
- package/components/autosuggest/autosuggest.ui.js +4 -7
- package/components/button/_button.scss +28 -7
- package/components/button/_macro.njk +1 -1
- package/components/button/_macro.spec.js +2 -2
- package/components/checkboxes/_checkbox.scss +50 -17
- package/components/collapsible/_collapsible.scss +59 -85
- package/components/collapsible/_macro.njk +6 -39
- package/components/collapsible/_macro.spec.js +0 -53
- package/components/collapsible/collapsible.dom.js +3 -12
- package/components/collapsible/collapsible.js +3 -45
- package/components/collapsible/collapsible.spec.js +6 -139
- package/components/cookies-banner/_cookies-banner.scss +15 -7
- package/components/cookies-banner/_macro.njk +66 -22
- package/components/cookies-banner/_macro.spec.js +172 -114
- package/components/cookies-banner/cookies-banner.js +35 -13
- package/components/cookies-banner/cookies-banner.spec.js +58 -54
- package/components/document-list/document-list.scss +2 -0
- package/components/download-resources/download-resources.js +19 -0
- package/components/download-resources/download-resources.spec.js +95 -0
- package/components/external-link/_macro.njk +1 -1
- package/components/external-link/_macro.spec.js +2 -2
- package/components/fieldset/_fieldset.scss +11 -1
- package/components/fieldset/_macro.njk +9 -8
- package/components/fieldset/_macro.spec.js +27 -5
- package/components/footer/_footer.scss +1 -0
- package/components/header/_macro.njk +2 -5
- package/components/header/_macro.spec.js +0 -16
- package/components/hero/_macro.njk +1 -1
- package/components/hero/_macro.spec.js +1 -1
- package/components/icons/_macro.njk +1 -1
- package/components/input/_input-type.scss +37 -3
- package/components/input/_input.scss +28 -9
- package/components/input/_macro.njk +17 -14
- package/components/input/_macro.spec.js +56 -0
- package/components/label/_label.scss +1 -1
- package/components/label/_macro.njk +27 -15
- package/components/label/_macro.spec.js +31 -0
- package/components/lists/_macro.njk +1 -1
- package/components/lists/_macro.spec.js +2 -2
- package/components/message/_message.scss +1 -0
- package/components/modal/_macro.njk +2 -2
- package/components/modal/_modal.scss +10 -9
- package/components/mutually-exclusive/mutually-exclusive.duration.spec.js +2 -0
- package/components/mutually-exclusive/mutually-exclusive.number.spec.js +1 -0
- package/components/navigation/_macro.njk +0 -1
- package/components/navigation/_macro.spec.js +0 -1
- package/components/pagination/_pagination.scss +1 -0
- package/components/panel/_macro.njk +6 -7
- package/components/panel/_macro.spec.js +23 -20
- package/components/panel/_panel.scss +13 -5
- package/components/phase-banner/_phase-banner.scss +1 -0
- package/components/radios/_radio.scss +16 -4
- package/components/relationships/_relationships.scss +2 -2
- package/components/reply/_macro.njk +2 -2
- package/components/skip-to-content/_skip.scss +2 -1
- package/components/table/_macro.njk +3 -2
- package/components/table/_macro.spec.js +0 -27
- package/components/table/_table.scss +15 -7
- package/components/table/sortable-table.js +1 -0
- package/components/tabs/_tabs.scss +57 -34
- package/components/tabs/tabs.js +4 -2
- package/components/upload/_upload.scss +2 -2
- package/css/census.css +1 -1
- package/css/ids.css +1 -1
- package/css/main.css +1 -1
- package/js/main.js +1 -0
- package/layout/_template.njk +8 -8
- package/package.json +1 -1
- package/scripts/main.es5.js +1 -1
- package/scripts/main.js +2 -2
- package/scss/base/_global.scss +1 -0
- package/scss/objects/_page.scss +1 -1
- package/scss/overrides/hcm.scss +205 -46
- package/scss/patternlib.scss +1 -56
- package/scss/vars/_colors.scss +2 -1
|
@@ -9,12 +9,11 @@ $checkbox-padding: 11px;
|
|
|
9
9
|
|
|
10
10
|
&__input {
|
|
11
11
|
appearance: none;
|
|
12
|
-
background:
|
|
13
|
-
|
|
14
|
-
background-size: 0;
|
|
15
|
-
border: 2px solid $color-input;
|
|
12
|
+
background-color: $color-input-bg;
|
|
13
|
+
border: 2px solid $color-input-border;
|
|
16
14
|
border-radius: 0.2rem;
|
|
17
15
|
box-sizing: border-box;
|
|
16
|
+
cursor: pointer;
|
|
18
17
|
height: $checkbox-input-width;
|
|
19
18
|
left: $checkbox-padding;
|
|
20
19
|
position: absolute;
|
|
@@ -22,13 +21,30 @@ $checkbox-padding: 11px;
|
|
|
22
21
|
width: $checkbox-input-width;
|
|
23
22
|
z-index: 1;
|
|
24
23
|
|
|
24
|
+
// Check icon
|
|
25
|
+
&::after {
|
|
26
|
+
border: solid $color-input-border;
|
|
27
|
+
border-radius: 1px;
|
|
28
|
+
border-top-color: $color-input-bg;
|
|
29
|
+
border-width: 0 0 3px 3px;
|
|
30
|
+
box-sizing: border-box;
|
|
31
|
+
content: '';
|
|
32
|
+
height: 7px;
|
|
33
|
+
left: 2px;
|
|
34
|
+
opacity: 0;
|
|
35
|
+
position: absolute;
|
|
36
|
+
top: 4px;
|
|
37
|
+
transform: rotate(-45deg);
|
|
38
|
+
width: 14px;
|
|
39
|
+
}
|
|
40
|
+
|
|
25
41
|
&:focus,
|
|
26
42
|
&:checked {
|
|
27
43
|
outline: none;
|
|
28
44
|
}
|
|
29
45
|
|
|
30
|
-
&:checked {
|
|
31
|
-
|
|
46
|
+
&:checked::after {
|
|
47
|
+
opacity: 1;
|
|
32
48
|
}
|
|
33
49
|
|
|
34
50
|
&:disabled {
|
|
@@ -36,9 +52,24 @@ $checkbox-padding: 11px;
|
|
|
36
52
|
cursor: not-allowed;
|
|
37
53
|
}
|
|
38
54
|
|
|
39
|
-
&:disabled
|
|
40
|
-
color: $color-
|
|
55
|
+
&:disabled:checked::after {
|
|
56
|
+
border-color: $color-border-disabled;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
&:disabled + .ons-checkbox__label,
|
|
60
|
+
&:disabled:checked + .ons-checkbox__label {
|
|
61
|
+
color: $color-border-disabled;
|
|
41
62
|
cursor: not-allowed;
|
|
63
|
+
|
|
64
|
+
&::before {
|
|
65
|
+
border: 1px solid $color-border-disabled;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
&:disabled:checked + .ons-checkbox__label {
|
|
70
|
+
&::before {
|
|
71
|
+
box-shadow: 0 0 0 1px $color-border-disabled;
|
|
72
|
+
}
|
|
42
73
|
}
|
|
43
74
|
}
|
|
44
75
|
|
|
@@ -47,9 +78,9 @@ $checkbox-padding: 11px;
|
|
|
47
78
|
padding: 0 0 0 1.85rem;
|
|
48
79
|
|
|
49
80
|
&::before {
|
|
50
|
-
background: none;
|
|
51
|
-
border: none;
|
|
52
|
-
box-shadow: none;
|
|
81
|
+
background: none !important;
|
|
82
|
+
border: none !important;
|
|
83
|
+
box-shadow: none !important;
|
|
53
84
|
}
|
|
54
85
|
|
|
55
86
|
& > .ons-checkbox__label--with-description {
|
|
@@ -69,11 +100,12 @@ $checkbox-padding: 11px;
|
|
|
69
100
|
background: none;
|
|
70
101
|
border: none;
|
|
71
102
|
box-shadow: none;
|
|
103
|
+
outline: none;
|
|
72
104
|
}
|
|
73
105
|
}
|
|
74
106
|
|
|
75
107
|
&:focus {
|
|
76
|
-
|
|
108
|
+
@extend %ons-input-focus;
|
|
77
109
|
}
|
|
78
110
|
}
|
|
79
111
|
|
|
@@ -101,7 +133,7 @@ $checkbox-padding: 11px;
|
|
|
101
133
|
}
|
|
102
134
|
|
|
103
135
|
&:focus {
|
|
104
|
-
|
|
136
|
+
@extend %ons-input-focus;
|
|
105
137
|
}
|
|
106
138
|
|
|
107
139
|
& + .ons-checkbox__label {
|
|
@@ -122,7 +154,7 @@ $checkbox-padding: 11px;
|
|
|
122
154
|
|
|
123
155
|
&::before {
|
|
124
156
|
background: $color-white;
|
|
125
|
-
border: 1px solid $color-input;
|
|
157
|
+
border: 1px solid $color-input-border;
|
|
126
158
|
border-radius: 3px;
|
|
127
159
|
bottom: 0;
|
|
128
160
|
content: '';
|
|
@@ -152,7 +184,8 @@ $checkbox-padding: 11px;
|
|
|
152
184
|
|
|
153
185
|
&__input:checked + &__label::before {
|
|
154
186
|
background: $color-grey-5;
|
|
155
|
-
box-shadow: 0 0 0 1px $color-input;
|
|
187
|
+
box-shadow: 0 0 0 1px $color-input-border;
|
|
188
|
+
outline: 1px solid transparent; // Add transparent outline because Windows High Contrast Mode doesn't show box-shadows
|
|
156
189
|
}
|
|
157
190
|
|
|
158
191
|
.ons-panel--error .ons-radio__input:checked ~ &__other > .ons-input--text:required:not(:focus) {
|
|
@@ -176,10 +209,10 @@ $checkbox-padding: 11px;
|
|
|
176
209
|
&--toggle & {
|
|
177
210
|
&__input {
|
|
178
211
|
left: 0;
|
|
179
|
-
top: 0.
|
|
212
|
+
top: 0.2rem;
|
|
180
213
|
|
|
181
214
|
&:focus {
|
|
182
|
-
|
|
215
|
+
@extend %ons-input-focus;
|
|
183
216
|
}
|
|
184
217
|
}
|
|
185
218
|
|
|
@@ -1,106 +1,82 @@
|
|
|
1
1
|
$collapsible-caret-width: 1.5rem;
|
|
2
2
|
|
|
3
3
|
.ons-collapsible {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
4
|
+
&__heading {
|
|
5
|
+
color: $color-text-link;
|
|
6
|
+
cursor: pointer;
|
|
7
|
+
display: inline-block;
|
|
8
|
+
outline: none;
|
|
9
|
+
padding: 0 0 0 $collapsible-caret-width;
|
|
10
|
+
pointer-events: initial;
|
|
11
|
+
position: relative;
|
|
12
|
+
|
|
13
|
+
&::marker,
|
|
14
|
+
&::-webkit-details-marker {
|
|
15
|
+
display: none;
|
|
16
|
+
}
|
|
17
17
|
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
}
|
|
25
|
-
.ons-collapsible__icon .ons-svg-icon {
|
|
26
|
-
fill: $color-text-link-focus;
|
|
27
|
-
}
|
|
18
|
+
&:focus {
|
|
19
|
+
.ons-collapsible__title {
|
|
20
|
+
@extend %a-focus;
|
|
21
|
+
// extend collapsible focus background behind caret
|
|
22
|
+
margin-left: -$collapsible-caret-width;
|
|
23
|
+
padding-left: $collapsible-caret-width;
|
|
28
24
|
}
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
color: $color-text-link-hover;
|
|
32
|
-
.ons-collapsible__icon {
|
|
33
|
-
fill: $color-text-link-hover;
|
|
34
|
-
}
|
|
35
|
-
.ons-collapsible__title {
|
|
36
|
-
text-decoration: underline solid $color-text-link-hover 2px;
|
|
37
|
-
}
|
|
25
|
+
.ons-collapsible__icon .ons-svg-icon {
|
|
26
|
+
fill: $color-text-link-focus;
|
|
38
27
|
}
|
|
39
28
|
}
|
|
40
29
|
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
30
|
+
&:hover:not(:focus) {
|
|
31
|
+
color: $color-text-link-hover;
|
|
32
|
+
.ons-collapsible__icon {
|
|
33
|
+
fill: $color-text-link-hover;
|
|
34
|
+
}
|
|
35
|
+
.ons-collapsible__title {
|
|
36
|
+
text-decoration: underline solid $color-text-link-hover 2px;
|
|
37
|
+
}
|
|
49
38
|
}
|
|
39
|
+
}
|
|
50
40
|
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
41
|
+
&__icon {
|
|
42
|
+
display: inline-block;
|
|
43
|
+
fill: $color-text-link;
|
|
44
|
+
height: $collapsible-caret-width;
|
|
45
|
+
left: -0.15rem;
|
|
46
|
+
position: absolute;
|
|
47
|
+
top: -0.2rem;
|
|
48
|
+
width: $collapsible-caret-width;
|
|
49
|
+
}
|
|
59
50
|
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
51
|
+
&__title {
|
|
52
|
+
display: inline-block;
|
|
53
|
+
font-size: 1rem;
|
|
54
|
+
font-weight: $font-weight-bold;
|
|
55
|
+
margin-bottom: 0;
|
|
56
|
+
text-underline-position: under;
|
|
57
|
+
transform: translateY(-1px);
|
|
63
58
|
}
|
|
64
59
|
|
|
65
|
-
&
|
|
66
|
-
|
|
60
|
+
&__content {
|
|
61
|
+
border-left: 4px solid $color-borders-indent;
|
|
62
|
+
display: block;
|
|
63
|
+
margin: 1rem 0 0;
|
|
64
|
+
padding: 0 0 0 1.3em;
|
|
67
65
|
}
|
|
68
66
|
|
|
69
|
-
|
|
67
|
+
&[open] & {
|
|
70
68
|
&__icon {
|
|
71
69
|
left: -0.1rem;
|
|
72
|
-
top: 0.
|
|
70
|
+
top: 0.2rem;
|
|
73
71
|
transform: rotate(90deg);
|
|
74
72
|
}
|
|
75
|
-
|
|
76
|
-
&__content {
|
|
77
|
-
border-left: 4px solid $color-borders-indent;
|
|
78
|
-
display: block;
|
|
79
|
-
margin: 1rem 0 0;
|
|
80
|
-
padding: 0 0 0 1.3em;
|
|
81
|
-
|
|
82
|
-
.ons-btn {
|
|
83
|
-
margin-bottom: 0.5rem;
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
&--accordion {
|
|
89
|
-
margin: 0;
|
|
90
|
-
&.ons-collapsible--open {
|
|
91
|
-
.ons-svg-icon {
|
|
92
|
-
left: 0.4rem;
|
|
93
|
-
position: absolute;
|
|
94
|
-
top: 0.25rem;
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
73
|
}
|
|
98
74
|
|
|
99
75
|
&--accordion & {
|
|
100
76
|
&__heading {
|
|
101
77
|
border-top: 1px solid $color-borders;
|
|
102
78
|
margin: 0;
|
|
103
|
-
padding-bottom:
|
|
79
|
+
padding-bottom: 0.9rem;
|
|
104
80
|
padding-top: 1rem;
|
|
105
81
|
width: 100%;
|
|
106
82
|
|
|
@@ -115,10 +91,6 @@ $collapsible-caret-width: 1.5rem;
|
|
|
115
91
|
|
|
116
92
|
&__icon {
|
|
117
93
|
top: 0.8rem;
|
|
118
|
-
|
|
119
|
-
@include mq(s) {
|
|
120
|
-
top: 1.15rem;
|
|
121
|
-
}
|
|
122
94
|
}
|
|
123
95
|
|
|
124
96
|
&__controls {
|
|
@@ -138,10 +110,12 @@ $collapsible-caret-width: 1.5rem;
|
|
|
138
110
|
padding: 0;
|
|
139
111
|
}
|
|
140
112
|
}
|
|
113
|
+
}
|
|
141
114
|
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
115
|
+
.ons-collapsible--accordion {
|
|
116
|
+
&[open] {
|
|
117
|
+
.ons-collapsible__icon {
|
|
118
|
+
top: 1.2rem;
|
|
145
119
|
}
|
|
146
120
|
}
|
|
147
121
|
}
|
|
@@ -1,21 +1,16 @@
|
|
|
1
1
|
{% macro onsCollapsible(params) %}
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
<div
|
|
2
|
+
<details
|
|
5
3
|
id="{{ params.id }}"
|
|
6
|
-
class="ons-collapsible ons-js-collapsible{% if params.isAccordion is defined and params.isAccordion %} ons-collapsible--accordion{% endif %}{% if params.classes is defined and params.classes %} {{ params.classes }}{% endif %}
|
|
7
|
-
{% if params.button is defined and params.button and params.button.close is defined and params.button.close %} data-btn-close="{{ params.button.close }}"{% endif %}
|
|
4
|
+
class="ons-collapsible ons-js-collapsible{% if params.isAccordion is defined and params.isAccordion %} ons-collapsible--accordion{% endif %}{% if params.classes is defined and params.classes %} {{ params.classes }}{% endif %}"
|
|
8
5
|
{% if params.group is defined and params.group %} data-group="{{ params.group }}"{% endif %}
|
|
9
6
|
{% if params.attributes is defined and params.attributes %}{% for attribute, value in (params.attributes.items() if params.attributes is mapping and params.attributes.items else params.attributes) %}{{ attribute }}{% if value is defined and value %}="{{ value }}"{% endif %} {% endfor %}{% endif %}
|
|
10
7
|
{% if params.saveState is defined and params.saveState %} data-save-state="true"{% endif %}
|
|
11
8
|
{% if params.open is defined and params.open %} data-open="true"{% endif %}
|
|
12
9
|
>
|
|
13
|
-
<
|
|
10
|
+
<summary
|
|
14
11
|
class="ons-collapsible__heading ons-js-collapsible-heading"
|
|
15
12
|
{% if params.headingAttributes is defined and params.headingAttributes %}{% for attribute, value in (params.headingAttributes.items() if params.headingAttributes is mapping and params.headingAttributes.items else params.headingAttributes) %}{{ attribute }}{% if value is defined and value %}="{{ value }}"{% endif %} {% endfor %}{% endif %}
|
|
16
13
|
>
|
|
17
|
-
{# Required to use display flex on Safari as it's not currently supported: https://bugs.webkit.org/show_bug.cgi?id=167111 #}
|
|
18
|
-
<div class="ons-collapsible__controls">
|
|
19
14
|
{% set titleTag = params.titleTag | default("h2") %}
|
|
20
15
|
<{{ titleTag }} class="ons-collapsible__title">{{ params.title }}</{{ titleTag }}>
|
|
21
16
|
<span class="ons-collapsible__icon">
|
|
@@ -25,39 +20,11 @@
|
|
|
25
20
|
"iconType": "chevron"
|
|
26
21
|
})
|
|
27
22
|
}}</span>
|
|
28
|
-
|
|
29
|
-
{{
|
|
30
|
-
onsButton({
|
|
31
|
-
"type": "button",
|
|
32
|
-
"text": params.button.open,
|
|
33
|
-
"classes": "ons-collapsible__btn ons-js-collapsible-button ons-u-d-no ons-u-d-no@xxs@s",
|
|
34
|
-
"innerClasses": "ons-js-collapsible-button-inner",
|
|
35
|
-
"variants": ["secondary", "small"],
|
|
36
|
-
"attributes": params.button.attributes
|
|
37
|
-
})
|
|
38
|
-
}}
|
|
39
|
-
{% endif %}
|
|
40
|
-
</div>
|
|
41
|
-
</div>
|
|
23
|
+
</summary>
|
|
42
24
|
<div id="{{ params.id }}-content" class="ons-collapsible__content ons-js-collapsible-content"
|
|
43
25
|
{% if params.contentAttributes is defined and params.contentAttributes %}{% for attribute, value in (params.contentAttributes.items() if params.contentAttributes is mapping and params.contentAttributes.items else params.contentAttributes) %}{{ attribute }}{% if value is defined and value %}="{{ value }}"{% endif %} {% endfor %}{% endif %}
|
|
44
26
|
>
|
|
45
|
-
{
|
|
46
|
-
{{ params.content | safe }}{{ caller() if caller }}
|
|
47
|
-
{% else %}
|
|
48
|
-
{{ params.content | safe }}{{ caller() if caller }}
|
|
49
|
-
{{
|
|
50
|
-
onsButton({
|
|
51
|
-
"type": "button",
|
|
52
|
-
"text": params.button.close | default ('Hide this'),
|
|
53
|
-
"buttonContext": (params.button.context | default(params.title)) + " " + params.button.contextSuffix | default("content"),
|
|
54
|
-
"classes": "ons-js-collapsible-button ons-u-d-no " + (params.button.classes | default("ons-btn--secondary")),
|
|
55
|
-
"innerClasses": "ons-js-collapsible-button-inner",
|
|
56
|
-
"variants": "small",
|
|
57
|
-
"attributes": params.button.attributes
|
|
58
|
-
})
|
|
59
|
-
}}
|
|
60
|
-
{% endif %}
|
|
27
|
+
{{ params.content | safe }}{{ caller() if caller }}
|
|
61
28
|
</div>
|
|
62
|
-
</
|
|
29
|
+
</details>
|
|
63
30
|
{% endmacro %}
|
|
@@ -37,18 +37,6 @@ describe('macro: collapsible', () => {
|
|
|
37
37
|
expect($('.ons-collapsible').hasClass('another-extra-class')).toBe(true);
|
|
38
38
|
});
|
|
39
39
|
|
|
40
|
-
it('has provided variant style classes', () => {
|
|
41
|
-
const $ = cheerio.load(
|
|
42
|
-
renderComponent('collapsible', {
|
|
43
|
-
...EXAMPLE_COLLAPSIBLE_BASIC,
|
|
44
|
-
variants: ['variant-a', 'variant-b'],
|
|
45
|
-
}),
|
|
46
|
-
);
|
|
47
|
-
|
|
48
|
-
expect($('.ons-collapsible--variant-a').length).toBe(1);
|
|
49
|
-
expect($('.ons-collapsible--variant-b').length).toBe(1);
|
|
50
|
-
});
|
|
51
|
-
|
|
52
40
|
it('has provided title text', () => {
|
|
53
41
|
const $ = cheerio.load(renderComponent('collapsible', EXAMPLE_COLLAPSIBLE_BASIC));
|
|
54
42
|
|
|
@@ -152,47 +140,6 @@ describe('macro: collapsible', () => {
|
|
|
152
140
|
expect(iconsSpy.occurrences[0].iconType).toBe('chevron');
|
|
153
141
|
});
|
|
154
142
|
|
|
155
|
-
it('has the expected button output', () => {
|
|
156
|
-
const faker = templateFaker();
|
|
157
|
-
const buttonSpy = faker.spy('button');
|
|
158
|
-
|
|
159
|
-
faker.renderComponent('collapsible', {
|
|
160
|
-
...EXAMPLE_COLLAPSIBLE_BASIC,
|
|
161
|
-
button: {
|
|
162
|
-
close: 'Close this',
|
|
163
|
-
attributes: {
|
|
164
|
-
a: 123,
|
|
165
|
-
b: 456,
|
|
166
|
-
},
|
|
167
|
-
},
|
|
168
|
-
});
|
|
169
|
-
|
|
170
|
-
expect(buttonSpy.occurrences[0]).toEqual({
|
|
171
|
-
text: 'Close this',
|
|
172
|
-
type: 'button',
|
|
173
|
-
buttonContext: 'Title for collapsible content',
|
|
174
|
-
classes: 'ons-js-collapsible-button ons-u-d-no ons-btn--secondary',
|
|
175
|
-
innerClasses: 'ons-js-collapsible-button-inner',
|
|
176
|
-
variants: 'small',
|
|
177
|
-
attributes: {
|
|
178
|
-
a: 123,
|
|
179
|
-
b: 456,
|
|
180
|
-
},
|
|
181
|
-
});
|
|
182
|
-
});
|
|
183
|
-
|
|
184
|
-
it('has the expected data attribute when `button` is provided', () => {
|
|
185
|
-
const $ = cheerio.load(
|
|
186
|
-
renderComponent('collapsible', {
|
|
187
|
-
...EXAMPLE_COLLAPSIBLE_BASIC,
|
|
188
|
-
button: {
|
|
189
|
-
close: 'Close this',
|
|
190
|
-
},
|
|
191
|
-
}),
|
|
192
|
-
);
|
|
193
|
-
expect($('.ons-collapsible').attr('data-btn-close')).toBe('Close this');
|
|
194
|
-
});
|
|
195
|
-
|
|
196
143
|
it('calls with content', () => {
|
|
197
144
|
const $ = cheerio.load(renderComponent('collapsible', { EXAMPLE_COLLAPSIBLE_BASIC }, 'Example content...'));
|
|
198
145
|
|
|
@@ -2,20 +2,11 @@ import domready from '../../js/domready';
|
|
|
2
2
|
|
|
3
3
|
async function initialiseCollapsibles() {
|
|
4
4
|
const collapsibleComponents = [...document.querySelectorAll('.ons-js-collapsible')];
|
|
5
|
+
const accordionComponents = [...document.querySelectorAll('.ons-js-accordion')];
|
|
5
6
|
|
|
6
|
-
if (collapsibleComponents.length) {
|
|
7
|
-
const toggleAllButtons = [...document.querySelectorAll('.ons-js-collapsible-all')];
|
|
8
|
-
|
|
7
|
+
if (collapsibleComponents.length && !accordionComponents.length) {
|
|
9
8
|
const Collapsible = (await import('./collapsible')).default;
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
if (toggleAllButtons.length) {
|
|
13
|
-
const CollapsibleGroup = (await import('./collapsible.group')).default;
|
|
14
|
-
|
|
15
|
-
toggleAllButtons.forEach(button => {
|
|
16
|
-
new CollapsibleGroup(button, collapsibles);
|
|
17
|
-
});
|
|
18
|
-
}
|
|
9
|
+
collapsibleComponents.map(element => new Collapsible(element));
|
|
19
10
|
}
|
|
20
11
|
}
|
|
21
12
|
|
|
@@ -2,79 +2,38 @@ export default class Collapsible {
|
|
|
2
2
|
constructor(collapsibleElement) {
|
|
3
3
|
this.saveState = collapsibleElement.getAttribute('data-save-state') === 'true';
|
|
4
4
|
this.open = collapsibleElement.getAttribute('data-open') === 'true';
|
|
5
|
-
|
|
6
|
-
// State
|
|
7
5
|
this.group = collapsibleElement.getAttribute('data-group');
|
|
8
|
-
this.isAccordion = collapsibleElement.classList.contains('ons-collapsible--accordion');
|
|
9
|
-
this.isSimpleAccordion = collapsibleElement.classList.contains('ons-collapsible--simple');
|
|
10
6
|
|
|
11
7
|
// Elements
|
|
12
8
|
this.collapsible = collapsibleElement;
|
|
13
9
|
this.collapsibleHeader = this.collapsible.querySelector('.ons-js-collapsible-heading');
|
|
14
|
-
this.content = this.collapsible.querySelector('.ons-js-collapsible-content');
|
|
15
|
-
this.button = this.collapsible.querySelector('.ons-js-collapsible-button');
|
|
16
|
-
this.buttonInner = this.collapsible.querySelector('.ons-js-collapsible-button-inner');
|
|
17
10
|
|
|
18
11
|
// Initialise
|
|
19
12
|
const collapsibleId = collapsibleElement.getAttribute('id');
|
|
20
13
|
|
|
21
|
-
if (this.button) {
|
|
22
|
-
this.button.addEventListener('click', this.toggle.bind(this));
|
|
23
|
-
this.button.setAttribute('aria-controls', collapsibleId);
|
|
24
|
-
this.button.classList.remove('ons-u-d-no');
|
|
25
|
-
this.buttonOpen = this.buttonInner.innerHTML.trim();
|
|
26
|
-
this.closeButton = this.collapsible.getAttribute('data-btn-close') || this.buttonOpen;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
this.collapsible.setAttribute('role', 'group');
|
|
30
|
-
this.collapsibleHeader.setAttribute('role', 'link');
|
|
31
|
-
this.collapsibleHeader.setAttribute('aria-controls', collapsibleId);
|
|
32
|
-
|
|
33
|
-
if (!this.isAccordion || this.isSimpleAccordion) {
|
|
34
|
-
this.collapsibleHeader.setAttribute('tabindex', 0);
|
|
35
|
-
}
|
|
36
14
|
if (localStorage.getItem(collapsibleId) || this.open) {
|
|
37
15
|
this.setOpen(true);
|
|
38
|
-
|
|
39
|
-
this.setOpen(false);
|
|
16
|
+
this.collapsible['setAttribute']('open', '');
|
|
40
17
|
}
|
|
41
18
|
|
|
42
19
|
this.collapsibleHeader.addEventListener('click', this.toggle.bind(this));
|
|
43
20
|
this.collapsibleHeader.addEventListener('keydown', this.keyboardInteraction.bind(this));
|
|
44
|
-
|
|
45
|
-
this.collapsible.classList.add('ons-collapsible--initialised');
|
|
46
21
|
}
|
|
47
22
|
|
|
48
23
|
toggle(event) {
|
|
49
24
|
event.preventDefault();
|
|
50
|
-
|
|
51
|
-
// Storing previous timestamp and checking against the current event's timestamp prevents event propagation
|
|
52
|
-
// to collapsibleHeader element when the button is in the collapsibleHeader, but does not prevent event propagation to the body for analytics
|
|
53
|
-
if (this.previousTimestamp !== event.timeStamp) {
|
|
54
|
-
this.previousTimestamp = event.timeStamp;
|
|
55
|
-
this.setOpen(!this.isOpen);
|
|
56
|
-
}
|
|
25
|
+
this.setOpen(!this.isOpen);
|
|
57
26
|
}
|
|
58
27
|
|
|
59
28
|
setOpen(open) {
|
|
60
29
|
if (open !== this.isOpen) {
|
|
61
|
-
const openAttribute = open ? 'set' : 'remove';
|
|
62
|
-
const cls = open ? 'add' : 'remove';
|
|
63
30
|
const action = open ? 'Open' : 'Close';
|
|
31
|
+
const openAttribute = open ? 'set' : 'remove';
|
|
64
32
|
|
|
65
33
|
this.isOpen = open;
|
|
66
34
|
this.collapsible[`${openAttribute}Attribute`]('open', '');
|
|
67
|
-
this.collapsible.classList[cls]('ons-collapsible--open');
|
|
68
|
-
this.collapsibleHeader.setAttribute('aria-expanded', open);
|
|
69
|
-
this.content.setAttribute('aria-hidden', !open);
|
|
70
|
-
|
|
71
35
|
this.collapsibleHeader.setAttribute('data-ga-action', `${action} panel`);
|
|
72
36
|
|
|
73
|
-
if (this.button) {
|
|
74
|
-
this.button.setAttribute('data-ga-action', `${action} panel`);
|
|
75
|
-
this.buttonInner.innerHTML = open ? this.closeButton : this.buttonOpen;
|
|
76
|
-
}
|
|
77
|
-
|
|
78
37
|
if (this.onOpen && this.onClose) {
|
|
79
38
|
if (open) {
|
|
80
39
|
this.onOpen();
|
|
@@ -100,7 +59,6 @@ export default class Collapsible {
|
|
|
100
59
|
event.preventDefault();
|
|
101
60
|
event.stopPropagation();
|
|
102
61
|
|
|
103
|
-
// Show answer content
|
|
104
62
|
this.toggle(event);
|
|
105
63
|
break;
|
|
106
64
|
}
|