@ons/design-system 53.0.4 → 54.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 +1 -1
- package/components/browser-banner/_browser-banner.scss +39 -0
- package/components/browser-banner/_macro.njk +17 -0
- package/components/browser-banner/_macro.spec.js +83 -0
- package/components/checkboxes/_macro.njk +1 -1
- package/components/collapsible/_collapsible.scss +58 -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/duration/_macro.njk +1 -1
- package/components/duration/_macro.spec.js +1 -1
- package/components/fieldset/_fieldset.scss +3 -6
- package/components/header/_macro.njk +7 -0
- package/components/input/_macro.njk +20 -15
- package/components/input/_macro.spec.js +56 -0
- package/components/label/_label.scss +1 -1
- package/components/mutually-exclusive/mutually-exclusive.duration.spec.js +2 -0
- package/components/mutually-exclusive/mutually-exclusive.number.spec.js +1 -0
- package/css/census.css +1 -1
- package/css/error.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 +1 -0
- package/package.json +1 -1
- package/scripts/main.es5.js +1 -1
- package/scripts/main.js +2 -2
- package/scss/main.scss +1 -0
- package/scss/objects/_page.scss +1 -1
- package/scss/vars/_colors.scss +1 -0
|
@@ -1,106 +1,81 @@
|
|
|
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
|
+
display: none;
|
|
15
|
+
}
|
|
17
16
|
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
}
|
|
25
|
-
.ons-collapsible__icon .ons-svg-icon {
|
|
26
|
-
fill: $color-text-link-focus;
|
|
27
|
-
}
|
|
17
|
+
&:focus {
|
|
18
|
+
.ons-collapsible__title {
|
|
19
|
+
@extend %a-focus;
|
|
20
|
+
// extend collapsible focus background behind caret
|
|
21
|
+
margin-left: -$collapsible-caret-width;
|
|
22
|
+
padding-left: $collapsible-caret-width;
|
|
28
23
|
}
|
|
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
|
-
}
|
|
24
|
+
.ons-collapsible__icon .ons-svg-icon {
|
|
25
|
+
fill: $color-text-link-focus;
|
|
38
26
|
}
|
|
39
27
|
}
|
|
40
28
|
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
29
|
+
&:hover:not(:focus) {
|
|
30
|
+
color: $color-text-link-hover;
|
|
31
|
+
.ons-collapsible__icon {
|
|
32
|
+
fill: $color-text-link-hover;
|
|
33
|
+
}
|
|
34
|
+
.ons-collapsible__title {
|
|
35
|
+
text-decoration: underline solid $color-text-link-hover 2px;
|
|
36
|
+
}
|
|
49
37
|
}
|
|
38
|
+
}
|
|
50
39
|
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
40
|
+
&__icon {
|
|
41
|
+
display: inline-block;
|
|
42
|
+
fill: $color-text-link;
|
|
43
|
+
height: $collapsible-caret-width;
|
|
44
|
+
left: -0.15rem;
|
|
45
|
+
position: absolute;
|
|
46
|
+
top: -0.2rem;
|
|
47
|
+
width: $collapsible-caret-width;
|
|
48
|
+
}
|
|
59
49
|
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
50
|
+
&__title {
|
|
51
|
+
display: inline-block;
|
|
52
|
+
font-size: 1rem;
|
|
53
|
+
font-weight: $font-weight-bold;
|
|
54
|
+
margin-bottom: 0;
|
|
55
|
+
text-underline-position: under;
|
|
56
|
+
transform: translateY(-1px);
|
|
63
57
|
}
|
|
64
58
|
|
|
65
|
-
&
|
|
66
|
-
|
|
59
|
+
&__content {
|
|
60
|
+
border-left: 4px solid $color-borders-indent;
|
|
61
|
+
display: block;
|
|
62
|
+
margin: 1rem 0 0;
|
|
63
|
+
padding: 0 0 0 1.3em;
|
|
67
64
|
}
|
|
68
65
|
|
|
69
|
-
|
|
66
|
+
&[open] & {
|
|
70
67
|
&__icon {
|
|
71
68
|
left: -0.1rem;
|
|
72
|
-
top: 0.
|
|
69
|
+
top: 0.2rem;
|
|
73
70
|
transform: rotate(90deg);
|
|
74
71
|
}
|
|
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
72
|
}
|
|
98
73
|
|
|
99
74
|
&--accordion & {
|
|
100
75
|
&__heading {
|
|
101
76
|
border-top: 1px solid $color-borders;
|
|
102
77
|
margin: 0;
|
|
103
|
-
padding-bottom:
|
|
78
|
+
padding-bottom: 0.9rem;
|
|
104
79
|
padding-top: 1rem;
|
|
105
80
|
width: 100%;
|
|
106
81
|
|
|
@@ -115,10 +90,6 @@ $collapsible-caret-width: 1.5rem;
|
|
|
115
90
|
|
|
116
91
|
&__icon {
|
|
117
92
|
top: 0.8rem;
|
|
118
|
-
|
|
119
|
-
@include mq(s) {
|
|
120
|
-
top: 1.15rem;
|
|
121
|
-
}
|
|
122
93
|
}
|
|
123
94
|
|
|
124
95
|
&__controls {
|
|
@@ -138,10 +109,12 @@ $collapsible-caret-width: 1.5rem;
|
|
|
138
109
|
padding: 0;
|
|
139
110
|
}
|
|
140
111
|
}
|
|
112
|
+
}
|
|
141
113
|
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
114
|
+
.ons-collapsible--accordion {
|
|
115
|
+
&[open] {
|
|
116
|
+
.ons-collapsible__icon {
|
|
117
|
+
top: 1.2rem;
|
|
145
118
|
}
|
|
146
119
|
}
|
|
147
120
|
}
|
|
@@ -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
|
}
|
|
@@ -7,53 +7,6 @@ const EXAMPLE_COLLAPSIBLE_BASIC = {
|
|
|
7
7
|
};
|
|
8
8
|
|
|
9
9
|
describe('script: collapsible', () => {
|
|
10
|
-
it('begins closed', async () => {
|
|
11
|
-
await setTestPage('/test', renderComponent('collapsible', EXAMPLE_COLLAPSIBLE_BASIC));
|
|
12
|
-
|
|
13
|
-
const openItemCount = await page.$$eval('.ons-collapsible--open', elements => elements.length);
|
|
14
|
-
expect(openItemCount).toBe(0);
|
|
15
|
-
});
|
|
16
|
-
|
|
17
|
-
it('sets the `role` attribute', async () => {
|
|
18
|
-
await setTestPage('/test', renderComponent('collapsible', EXAMPLE_COLLAPSIBLE_BASIC));
|
|
19
|
-
|
|
20
|
-
const role = await page.$eval('.ons-collapsible', element => element.getAttribute('role'));
|
|
21
|
-
expect(role).toBe('group');
|
|
22
|
-
});
|
|
23
|
-
|
|
24
|
-
it('adds the correct class', async () => {
|
|
25
|
-
await setTestPage('/test', renderComponent('collapsible', EXAMPLE_COLLAPSIBLE_BASIC));
|
|
26
|
-
|
|
27
|
-
const className = await page.$eval('.ons-collapsible', element => element.classList.contains('ons-collapsible--initialised'));
|
|
28
|
-
expect(className).toBe(true);
|
|
29
|
-
});
|
|
30
|
-
|
|
31
|
-
it('sets attributes on the heading element', async () => {
|
|
32
|
-
await setTestPage('/test', renderComponent('collapsible', EXAMPLE_COLLAPSIBLE_BASIC));
|
|
33
|
-
|
|
34
|
-
const role = await page.$eval('.ons-js-collapsible-heading', element => element.getAttribute('role'));
|
|
35
|
-
const ariaControls = await page.$eval('.ons-js-collapsible-heading', element => element.getAttribute('aria-controls'));
|
|
36
|
-
const tabIndex = await page.$eval('.ons-js-collapsible-heading', element => element.getAttribute('tabindex'));
|
|
37
|
-
|
|
38
|
-
expect(role).toBe('link');
|
|
39
|
-
expect(ariaControls).toBe('collapsible-id');
|
|
40
|
-
expect(tabIndex).toBe('0');
|
|
41
|
-
});
|
|
42
|
-
|
|
43
|
-
it('sets attributes on the button element', async () => {
|
|
44
|
-
await setTestPage('/test', renderComponent('collapsible', EXAMPLE_COLLAPSIBLE_BASIC));
|
|
45
|
-
|
|
46
|
-
const ariaControls = await page.$eval('.ons-js-collapsible-button', element => element.getAttribute('aria-controls'));
|
|
47
|
-
expect(ariaControls).toBe('collapsible-id');
|
|
48
|
-
});
|
|
49
|
-
|
|
50
|
-
it('sets the button element to be visible', async () => {
|
|
51
|
-
await setTestPage('/test', renderComponent('collapsible', EXAMPLE_COLLAPSIBLE_BASIC));
|
|
52
|
-
|
|
53
|
-
const openClass = await page.$eval('.ons-collapsible', element => element.classList.contains('ons-collapsible--open'));
|
|
54
|
-
expect(openClass).toBe(false);
|
|
55
|
-
});
|
|
56
|
-
|
|
57
10
|
it('begins open when specified', async () => {
|
|
58
11
|
await setTestPage(
|
|
59
12
|
'/test',
|
|
@@ -63,8 +16,8 @@ describe('script: collapsible', () => {
|
|
|
63
16
|
}),
|
|
64
17
|
);
|
|
65
18
|
|
|
66
|
-
const
|
|
67
|
-
expect(
|
|
19
|
+
const openAttribute = await page.$eval('.ons-js-collapsible', node => node.open !== null);
|
|
20
|
+
expect(openAttribute).toBe(true);
|
|
68
21
|
});
|
|
69
22
|
|
|
70
23
|
describe('when the collapsible heading is clicked to open the collapsible', () => {
|
|
@@ -78,59 +31,10 @@ describe('script: collapsible', () => {
|
|
|
78
31
|
expect(openAttribute).toBe(true);
|
|
79
32
|
});
|
|
80
33
|
|
|
81
|
-
it('sets the open class', async () => {
|
|
82
|
-
const openClass = await page.$eval('.ons-collapsible', element => element.classList.contains('ons-collapsible--open'));
|
|
83
|
-
expect(openClass).toBe(true);
|
|
84
|
-
});
|
|
85
|
-
|
|
86
|
-
it('sets the `aria` attributes', async () => {
|
|
87
|
-
const ariaExpanded = await page.$eval('.ons-js-collapsible-heading', element => element.getAttribute('aria-expanded'));
|
|
88
|
-
const ariaHidden = await page.$eval('.ons-js-collapsible-content', element => element.getAttribute('aria-hidden'));
|
|
89
|
-
|
|
90
|
-
expect(ariaExpanded).toBe('true');
|
|
91
|
-
expect(ariaHidden).toBe('false');
|
|
92
|
-
});
|
|
93
|
-
|
|
94
34
|
it('sets the `ga` attributes', async () => {
|
|
95
35
|
const gaHeadingAttribute = await page.$eval('.ons-js-collapsible-heading', element => element.getAttribute('data-ga-action'));
|
|
96
|
-
const gaButtonAttribute = await page.$eval('.ons-js-collapsible-button', element => element.getAttribute('data-ga-action'));
|
|
97
36
|
|
|
98
37
|
expect(gaHeadingAttribute).toBe('Open panel');
|
|
99
|
-
expect(gaButtonAttribute).toBe('Open panel');
|
|
100
|
-
});
|
|
101
|
-
});
|
|
102
|
-
|
|
103
|
-
describe('when the collapsible button is clicked to close the collapsible', () => {
|
|
104
|
-
beforeEach(async () => {
|
|
105
|
-
await setTestPage('/test', renderComponent('collapsible', EXAMPLE_COLLAPSIBLE_BASIC));
|
|
106
|
-
await page.click('.ons-js-collapsible-heading');
|
|
107
|
-
await page.click('.ons-js-collapsible-button');
|
|
108
|
-
});
|
|
109
|
-
|
|
110
|
-
it('removes the `open` attribute', async () => {
|
|
111
|
-
const openAttribute = await page.$eval('.ons-js-collapsible', node => node.open === true);
|
|
112
|
-
expect(openAttribute).toBe(false);
|
|
113
|
-
});
|
|
114
|
-
|
|
115
|
-
it('removes the open class', async () => {
|
|
116
|
-
const openClass = await page.$eval('.ons-collapsible', element => element.classList.contains('ons-collapsible--open'));
|
|
117
|
-
expect(openClass).toBe(false);
|
|
118
|
-
});
|
|
119
|
-
|
|
120
|
-
it('sets the `aria` attributes', async () => {
|
|
121
|
-
const ariaExpanded = await page.$eval('.ons-js-collapsible-heading', element => element.getAttribute('aria-expanded'));
|
|
122
|
-
const ariaHidden = await page.$eval('.ons-js-collapsible-content', element => element.getAttribute('aria-hidden'));
|
|
123
|
-
|
|
124
|
-
expect(ariaExpanded).toBe('false');
|
|
125
|
-
expect(ariaHidden).toBe('true');
|
|
126
|
-
});
|
|
127
|
-
|
|
128
|
-
it('sets the `ga` attributes', async () => {
|
|
129
|
-
const gaHeadingAttribute = await page.$eval('.ons-js-collapsible-heading', element => element.getAttribute('data-ga-action'));
|
|
130
|
-
const gaButtonAttribute = await page.$eval('.ons-js-collapsible-button', element => element.getAttribute('data-ga-action'));
|
|
131
|
-
|
|
132
|
-
expect(gaHeadingAttribute).toBe('Close panel');
|
|
133
|
-
expect(gaButtonAttribute).toBe('Close panel');
|
|
134
38
|
});
|
|
135
39
|
});
|
|
136
40
|
|
|
@@ -146,8 +50,8 @@ describe('script: collapsible', () => {
|
|
|
146
50
|
});
|
|
147
51
|
|
|
148
52
|
it('opens the collapsible content', async () => {
|
|
149
|
-
const
|
|
150
|
-
expect(
|
|
53
|
+
const openAttribute = await page.$eval('.ons-js-collapsible', node => node.open !== null);
|
|
54
|
+
expect(openAttribute).toBe(true);
|
|
151
55
|
});
|
|
152
56
|
});
|
|
153
57
|
|
|
@@ -157,8 +61,8 @@ describe('script: collapsible', () => {
|
|
|
157
61
|
});
|
|
158
62
|
|
|
159
63
|
it('opens the collapsible content', async () => {
|
|
160
|
-
const
|
|
161
|
-
expect(
|
|
64
|
+
const openAttribute = await page.$eval('.ons-js-collapsible', node => node.open !== null);
|
|
65
|
+
expect(openAttribute).toBe(true);
|
|
162
66
|
});
|
|
163
67
|
});
|
|
164
68
|
});
|
|
@@ -196,41 +100,4 @@ describe('script: collapsible', () => {
|
|
|
196
100
|
});
|
|
197
101
|
});
|
|
198
102
|
});
|
|
199
|
-
|
|
200
|
-
describe('when the collapsible is an accordion', () => {
|
|
201
|
-
beforeEach(async () => {
|
|
202
|
-
await setTestPage(
|
|
203
|
-
'/test',
|
|
204
|
-
renderComponent('collapsible', {
|
|
205
|
-
...EXAMPLE_COLLAPSIBLE_BASIC,
|
|
206
|
-
isAccordion: true,
|
|
207
|
-
}),
|
|
208
|
-
);
|
|
209
|
-
});
|
|
210
|
-
|
|
211
|
-
it('does not set `tabindex` on the heading element', async () => {
|
|
212
|
-
const tabIndex = await page.$eval('.ons-js-collapsible-heading', element => element.getAttribute('tabindex'));
|
|
213
|
-
|
|
214
|
-
expect(tabIndex).toBe(null);
|
|
215
|
-
});
|
|
216
|
-
});
|
|
217
|
-
|
|
218
|
-
describe('when the collapsible is an accordion and the simple variant', () => {
|
|
219
|
-
beforeEach(async () => {
|
|
220
|
-
await setTestPage(
|
|
221
|
-
'/test',
|
|
222
|
-
renderComponent('collapsible', {
|
|
223
|
-
...EXAMPLE_COLLAPSIBLE_BASIC,
|
|
224
|
-
isAccordion: true,
|
|
225
|
-
variants: 'simple',
|
|
226
|
-
}),
|
|
227
|
-
);
|
|
228
|
-
});
|
|
229
|
-
|
|
230
|
-
it('does set `tabindex` on the heading element', async () => {
|
|
231
|
-
const tabIndex = await page.$eval('.ons-js-collapsible-heading', element => element.getAttribute('tabindex'));
|
|
232
|
-
|
|
233
|
-
expect(tabIndex).toBe('0');
|
|
234
|
-
});
|
|
235
|
-
});
|
|
236
103
|
});
|
|
@@ -1,22 +1,30 @@
|
|
|
1
1
|
.ons-cookies-banner {
|
|
2
2
|
background: $color-banner-bg;
|
|
3
3
|
display: none;
|
|
4
|
-
padding: 1rem 0;
|
|
4
|
+
padding: 1rem 0 1.5rem;
|
|
5
5
|
|
|
6
6
|
&__title {
|
|
7
7
|
color: $color-text;
|
|
8
8
|
}
|
|
9
9
|
|
|
10
|
-
&
|
|
10
|
+
&__statement {
|
|
11
11
|
color: $color-text;
|
|
12
|
-
margin-bottom: 1rem;
|
|
13
12
|
word-break: break-word;
|
|
13
|
+
p {
|
|
14
|
+
margin: 0 0 0.5rem;
|
|
15
|
+
|
|
16
|
+
@include mq(xxs, s) {
|
|
17
|
+
font-size: 0.9rem;
|
|
18
|
+
line-height: 1.4;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
&__link {
|
|
24
|
+
line-height: 2.1rem;
|
|
14
25
|
}
|
|
15
26
|
|
|
16
27
|
&__btn {
|
|
17
|
-
|
|
18
|
-
display: block;
|
|
19
|
-
width: 100%;
|
|
20
|
-
}
|
|
28
|
+
margin: 0 0 0.8rem;
|
|
21
29
|
}
|
|
22
30
|
}
|