@ons/design-system 72.10.4 → 72.10.6

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.
Files changed (39) hide show
  1. package/components/button/_button.scss +8 -6
  2. package/components/chart/_chart.scss +2 -14
  3. package/components/chart/_macro.njk +15 -3
  4. package/components/chart/_macro.spec.js +163 -1
  5. package/components/chart/boxplot.js +3 -0
  6. package/components/chart/columnrange-chart.js +3 -0
  7. package/components/chart/example-area-chart-with-axis-min-and-max-values.njk +72 -0
  8. package/components/chart/example-bar-chart-with-axis-min-and-max-values.njk +59 -0
  9. package/components/chart/example-column-chart-with-axis-min-and-max-values.njk +59 -0
  10. package/components/chart/example-line-chart-with-axis-min-and-max-values.njk +227 -0
  11. package/components/chart/example-scatter-chart-with-axis-min-and-max-values.njk +98 -0
  12. package/components/chart/specific-chart-options.js +29 -6
  13. package/components/details-panel/_details-panel.scss +4 -0
  14. package/components/details-panel/_macro.njk +17 -13
  15. package/components/details-panel/_macro.spec.js +17 -0
  16. package/components/details-panel/example-details-panel-open.njk +2 -1
  17. package/components/details-panel/example-details-panel.njk +2 -1
  18. package/components/header/_header.scss +40 -24
  19. package/components/header/_macro.njk +103 -89
  20. package/components/header/_macro.spec.js +131 -3
  21. package/components/header/example-header-basic-with-search-and-language.njk +207 -0
  22. package/components/header/{example-header-with-search-button.njk → example-header-basic-with-search-button.njk} +1 -0
  23. package/components/header/example-header-basic.njk +1 -0
  24. package/components/hero/_macro.njk +9 -2
  25. package/components/hero/_macro.spec.js +22 -0
  26. package/components/hero/example-hero-grey.njk +2 -1
  27. package/components/language-selector/_macro.njk +1 -1
  28. package/components/language-selector/_macro.spec.js +49 -3
  29. package/components/navigation/navigation.js +24 -17
  30. package/components/pagination/_macro.njk +17 -7
  31. package/components/pagination/_macro.spec.js +191 -17
  32. package/components/table/_macro.njk +83 -44
  33. package/components/table/_macro.spec.js +90 -0
  34. package/components/table/_table.scss +15 -3
  35. package/components/table/example-table-merge-cells.njk +139 -0
  36. package/css/main.css +1 -1
  37. package/package.json +1 -1
  38. package/scripts/main.es5.js +1 -1
  39. package/scripts/main.js +1 -1
@@ -8,6 +8,7 @@
8
8
  onsHeader({
9
9
  "variants": 'basic',
10
10
  "menuLinks": {
11
+ "id": "menu-links",
11
12
  "keyLinks": [
12
13
  {
13
14
  'heading': 'Taking part in a survey?',
@@ -94,10 +94,17 @@
94
94
  {% if params.informationPanel %}
95
95
  <div class="ons-hero__information ons-u-mt-s">
96
96
  <div class="ons-hero__panel ons-hero__panel--{{ params.informationPanel.panelType }}">
97
- {{- params.informationPanel.panelText -}}
97
+ <h2 class="ons-u-fs-r--b ons-u-m-no">{{- params.informationPanel.panelText -}}</h2>
98
98
  </div>
99
99
  <div class="ons-hero__link">
100
- <a href="{{ params.informationPanel.panelLink.url }}">{{ params.informationPanel.panelLink.text }}</a>
100
+ <a
101
+ href="{{ params.informationPanel.panelLink.url }}"
102
+ {% if params.informationPanel.panelLink.ariaLabel %}
103
+ aria-label="{{ params.informationPanel.panelLink.ariaLabel }}"
104
+ {% endif %}
105
+ >
106
+ {{ params.informationPanel.panelLink.text }}
107
+ </a>
101
108
  </div>
102
109
  </div>
103
110
  {% endif %}
@@ -176,6 +176,28 @@ describe('macro: hero', () => {
176
176
  expect($('.ons-hero__link > a').text().trim()).toBe('Some link text');
177
177
  expect($('.ons-hero__link > a').attr('href')).toBe('#0');
178
178
  });
179
+
180
+ it('renders the `informationPanel` link with a custom aria-label', () => {
181
+ const $ = cheerio.load(
182
+ renderComponent('hero', {
183
+ ...EXAMPLE_HERO,
184
+ variants: 'grey',
185
+ informationPanel: {
186
+ panelText: 'Some panel text',
187
+ panelType: 'ons-green',
188
+ panelLink: {
189
+ text: 'Some link text',
190
+ url: '#0',
191
+ ariaLabel: 'Some link aria label',
192
+ },
193
+ },
194
+ }),
195
+ );
196
+ const link = $('.ons-hero__link > a');
197
+ expect(link.attr('aria-label')).toBe('Some link aria label');
198
+ expect(link.text().trim()).toBe('Some link text');
199
+ expect(link.attr('href')).toBe('#0');
200
+ });
179
201
  });
180
202
 
181
203
  describe('and `panelType` is set to `ons-green`', () => {
@@ -14,7 +14,8 @@
14
14
  "panelType": 'ons-green',
15
15
  "panelLink": {
16
16
  "text": 'View previous releases',
17
- "url": '#0'
17
+ "url": '#0',
18
+ "ariaLabel": 'View previous release of Retail sales rise amid summer discounts and sporting events'
18
19
  }
19
20
  },
20
21
  "topic": 'Statistical article',
@@ -11,7 +11,7 @@
11
11
  {% if language.attributes %}{% for attribute, value in (language.attributes) %}{{ ' ' }}{{ attribute }}="{{ value }}"{% endfor %}{% endif %}
12
12
  >
13
13
  {# Visually hidden helper text for screenreaders #}
14
- <span class="ons-u-vh">Change language to{{ ' ' }}</span>
14
+ <span class="ons-u-vh">{{ (language.srText | default("Change language to")) + ' ' }}</span>
15
15
  {% if language.abbrText %}
16
16
  <span class="ons-u-d-no@s">{{ language.abbrText }}</span><span class="ons-u-d-no@2xs@s">{{- language.text -}}</span>
17
17
  {% else %}
@@ -102,7 +102,7 @@ describe('macro: language-selector', () => {
102
102
  it('has the `abbrText` rendered', () => {
103
103
  const $ = cheerio.load(renderComponent('language-selector', EXAMPLE_WITH_TWO_LANGUAGES));
104
104
 
105
- expect($('.ons-language-links__item a span:first-child').text()).toBe('CY');
105
+ expect($('.ons-language-links__item a span:nth-child(2)').text()).toBe('CY');
106
106
  });
107
107
  });
108
108
 
@@ -124,8 +124,9 @@ describe('macro: language-selector', () => {
124
124
  it('does not show the current language', () => {
125
125
  const $ = cheerio.load(renderComponent('language-selector', EXAMPLE_WITH_THREE_LANGUAGES));
126
126
 
127
- expect($('.ons-language-links__item:first-child a').text()).toBe('English');
128
- expect($('.ons-language-links__item:last-child a').text()).toBe('Polski');
127
+ // .replace(/\s+/g, ' ') will replace any sequence of whitespace characters (spaces, tabs, newlines) with a single space
128
+ expect($('.ons-language-links__item:first-child a').text().replace(/\s+/g, ' ').trim()).toBe('Change language to English');
129
+ expect($('.ons-language-links__item:last-child a').text().replace(/\s+/g, ' ').trim()).toBe('Change language to Polski');
129
130
  });
130
131
 
131
132
  it('has the visibility class applied', () => {
@@ -134,4 +135,49 @@ describe('macro: language-selector', () => {
134
135
  expect($('.ons-language-links').hasClass('ons-u-d-no@2xs@m')).toBe(true);
135
136
  });
136
137
  });
138
+
139
+ describe('srText parameter', () => {
140
+ it('renders custom srText when provided', () => {
141
+ const params = {
142
+ languages: [
143
+ {
144
+ url: '/welsh',
145
+ isoCode: 'cy',
146
+ text: 'Cymraeg',
147
+ srText: 'Custom screen reader text',
148
+ current: false,
149
+ },
150
+ {
151
+ url: '/english',
152
+ isoCode: 'en',
153
+ text: 'English',
154
+ current: true,
155
+ },
156
+ ],
157
+ };
158
+ const $ = cheerio.load(renderComponent('language-selector', params));
159
+ expect($('.ons-language-links__item a .ons-u-vh').text().trim()).toBe('Custom screen reader text');
160
+ });
161
+
162
+ it('renders default srText when not provided', () => {
163
+ const params = {
164
+ languages: [
165
+ {
166
+ url: '/welsh',
167
+ isoCode: 'cy',
168
+ text: 'Cymraeg',
169
+ current: false,
170
+ },
171
+ {
172
+ url: '/english',
173
+ isoCode: 'en',
174
+ text: 'English',
175
+ current: true,
176
+ },
177
+ ],
178
+ };
179
+ const $ = cheerio.load(renderComponent('language-selector', params));
180
+ expect($('.ons-language-links__item a .ons-u-vh').text().trim()).toBe('Change language to');
181
+ });
182
+ });
137
183
  });
@@ -82,9 +82,11 @@ export default class NavigationToggle {
82
82
  <span class="ons-btn__text"></span>
83
83
  </span>`,
84
84
  };
85
- toggle.innerHTML = isOpen ? icons.open : icons.close;
86
- toggle.classList.toggle('ons-btn--close', isOpen);
87
- toggle.classList.toggle('ons-btn--search-icon', !isOpen);
85
+ if (isOpen != null) {
86
+ toggle.innerHTML = isOpen ? icons.open : icons.close;
87
+ toggle.classList.toggle('ons-btn--close', isOpen);
88
+ toggle.classList.toggle('ons-btn--search-icon', !isOpen);
89
+ }
88
90
  }
89
91
 
90
92
  isHidden(el) {
@@ -115,22 +117,27 @@ export default class NavigationToggle {
115
117
  }
116
118
 
117
119
  toggleMenuAndSearch() {
118
- const isMenuOpen = this.menuBtn.getAttribute('aria-expanded') === 'true';
119
- const isSearchOpen = this.searchBtn.getAttribute('aria-expanded') === 'true';
120
-
121
- if (isMenuOpen && this.toggle == this.menuBtn) {
122
- this.updateSearchIcon(false, this.searchToggleBtn);
123
- this.searchBtn.setAttribute('aria-expanded', 'false');
124
- this.searchEl.setAttribute('aria-hidden', 'true');
125
- this.searchEl.classList.add('ons-u-d-no');
126
- this.searchToggleBtn.classList.remove('active');
120
+ if (this.menuBtn) {
121
+ const isMenuOpen = this.menuBtn.getAttribute('aria-expanded') === 'true';
122
+
123
+ if (isMenuOpen && this.toggle == this.menuBtn && this.searchBtn) {
124
+ this.updateSearchIcon(false, this.searchToggleBtn && this.searchBtn);
125
+ this.searchBtn.setAttribute('aria-expanded', 'false');
126
+ this.searchEl.setAttribute('aria-hidden', 'true');
127
+ this.searchEl.classList.add('ons-u-d-no');
128
+ this.searchToggleBtn.classList.remove('active');
129
+ }
127
130
  }
128
131
 
129
- if (isSearchOpen && this.toggle == this.searchToggleBtn) {
130
- this.menuBtn.setAttribute('aria-expanded', 'false');
131
- this.menuEl.setAttribute('aria-hidden', 'true');
132
- this.menuEl.classList.add('ons-u-d-no');
133
- this.menuBtn.classList.remove('active');
132
+ if (this.searchBtn) {
133
+ const isSearchOpen = this.searchBtn.getAttribute('aria-expanded') === 'true';
134
+
135
+ if (isSearchOpen && this.toggle == this.searchToggleBtn && this.menuBtn) {
136
+ this.menuBtn.setAttribute('aria-expanded', 'false');
137
+ this.menuEl.setAttribute('aria-hidden', 'true');
138
+ this.menuEl.classList.add('ons-u-d-no');
139
+ this.menuBtn.classList.remove('active');
140
+ }
134
141
  }
135
142
  }
136
143
  }
@@ -7,10 +7,12 @@
7
7
  {% set firstPage = params.pages | first %}
8
8
  {% set prevPageIndex = currentPageIndex - 1 %}
9
9
  {% set nextPageIndex = currentPageIndex + 1 %}
10
+ {% set prevPageAriaLabel = (params.previousAriaLabel or 'Go to the previous page') %}
11
+ {% set nextPageAriaLabel = (params.nextAriaLabel or 'Go to the next page') %}
10
12
 
11
13
  <nav
12
14
  class="ons-pagination{{ ' ' + params.classes if params.classes else '' }}{{ ' ons-pagination--no-indicator' if params.hideRangeIndicator }}"
13
- aria-label="Pagination ({{ position }})"
15
+ aria-label="{{ params.ariaLabel | default ('Pagination') }} ({{ position }})"
14
16
  >
15
17
  <div class="ons-pagination__position">{{ position }}</div>
16
18
  <ul class="ons-pagination__items{{ ' ons-pagination__items--no-previous' if currentPageIndex == 1 }}">
@@ -21,7 +23,7 @@
21
23
  href="{{ params.pages[prevPageIndex].url }}"
22
24
  class="ons-pagination__link ons-pagination__link--no-underline"
23
25
  rel="prev"
24
- aria-label="Go to the previous page (Page {{ currentPageIndex - 1 }})"
26
+ aria-label="{{ prevPageAriaLabel }} ({{ currentPageIndex - 1 }})"
25
27
  >
26
28
  {{-
27
29
  onsIcon({
@@ -36,7 +38,12 @@
36
38
  {% endif %}
37
39
  {% if currentPageIndex > 2 %}
38
40
  <li class="ons-pagination__item{{ ' ons-pagination__item--current' if currentPageIndex == 1 }}">
39
- <a href="{{ firstPage.url }}" class="ons-pagination__link" aria-label="Go to the first page (Page 1)">1</a>
41
+ <a
42
+ href="{{ firstPage.url }}"
43
+ class="ons-pagination__link"
44
+ aria-label="{{ params.firstAriaLabel | default('Go to the first page') }}"
45
+ >1</a
46
+ >
40
47
  </li>
41
48
  {% endif %}
42
49
  {% if currentPageIndex > 4 %}
@@ -56,9 +63,9 @@
56
63
  href="{{ page.url }}"
57
64
  class="ons-pagination__link"
58
65
  {%- if loop.index == currentPageIndex -%}
59
- aria-current="true" aria-label="Current page ({{ position }})"
66
+ aria-current="true" aria-label="{{ params.currentAriaLabel | default('Current page') }} ({{ position }})"
60
67
  {%- else -%}
61
- aria-label="Go to page {{ loop.index }}"
68
+ aria-label="{{ params.goToAriaLabel | default('Go to page') }} {{ loop.index }}"
62
69
  {%- endif -%}
63
70
  {%- if loop.index == currentPageIndex - 1 -%}
64
71
  rel="prev"
@@ -76,7 +83,10 @@
76
83
  {% endif %}
77
84
  {% if currentPageIndex < totalPages - 1 %}
78
85
  <li class="ons-pagination__item{{ ' ons-pagination__item--current' if currentPageIndex == totalPages }}">
79
- <a href="{{ lastPage.url }}" class="ons-pagination__link" aria-label="Go to the last page (Page {{ totalPages }})"
86
+ <a
87
+ href="{{ lastPage.url }}"
88
+ class="ons-pagination__link"
89
+ aria-label="{{ params.lastAriaLabel | default('Go to the last page') }} ({{ totalPages }})"
80
90
  >{{ totalPages }}</a
81
91
  >
82
92
  </li>
@@ -87,7 +97,7 @@
87
97
  href="{{ params.pages[currentPageIndex].url }}"
88
98
  class="ons-pagination__link ons-pagination__link--no-underline"
89
99
  rel="next"
90
- aria-label="Go to the next page (Page {{ currentPageIndex + 1 }})"
100
+ aria-label="{{ nextPageAriaLabel }} ({{ currentPageIndex + 1 }})"
91
101
  >
92
102
  <span class="ons-pagination__link-text">{{ params.next | default("Next") }}</span>
93
103
  {{-
@@ -105,7 +105,7 @@ describe('macro: pagination', () => {
105
105
  expect($('li').length).toBe(3);
106
106
  assertIsCurrentPage($('.ons-pagination__item:nth-child(1)'), '/page/1', 'Current page (Page 1 of 2)', '1');
107
107
  assertIsNextPage($('.ons-pagination__item:nth-child(2)'), '/page/2', 'Go to page 2', '2');
108
- assertIsNextPage($('.ons-pagination__item:nth-child(3)'), '/page/2', 'Go to the next page (Page 2)', 'Next page');
108
+ assertIsNextPage($('.ons-pagination__item:nth-child(3)'), '/page/2', 'Go to the next page (2)', 'Next page');
109
109
  });
110
110
  });
111
111
 
@@ -133,7 +133,7 @@ describe('macro: pagination', () => {
133
133
 
134
134
  it('has a 3 list items ("Previous page", "1", "2")', () => {
135
135
  expect($('li').length).toBe(3);
136
- assertIsPreviousPage($('.ons-pagination__item:nth-child(1)'), '/page/1', 'Go to the previous page (Page 1)', 'Previous page');
136
+ assertIsPreviousPage($('.ons-pagination__item:nth-child(1)'), '/page/1', 'Go to the previous page (1)', 'Previous page');
137
137
  assertIsPreviousPage($('.ons-pagination__item:nth-child(2)'), '/page/1', 'Go to page 1', '1');
138
138
  assertIsCurrentPage($('.ons-pagination__item:nth-child(3)'), '/page/2', 'Current page (Page 2 of 2)', '2');
139
139
  });
@@ -163,11 +163,11 @@ describe('macro: pagination', () => {
163
163
 
164
164
  it('has a 5 list items ("Previous page", "1", "2", "3", "Next page")', () => {
165
165
  expect($('li').length).toBe(5);
166
- assertIsPreviousPage($('.ons-pagination__item:nth-child(1)'), '/page/1', 'Go to the previous page (Page 1)', 'Previous page');
166
+ assertIsPreviousPage($('.ons-pagination__item:nth-child(1)'), '/page/1', 'Go to the previous page (1)', 'Previous page');
167
167
  assertIsPreviousPage($('.ons-pagination__item:nth-child(2)'), '/page/1', 'Go to page 1', '1');
168
168
  assertIsCurrentPage($('.ons-pagination__item:nth-child(3)'), '/page/2', 'Current page (Page 2 of 3)', '2');
169
169
  assertIsNextPage($('.ons-pagination__item:nth-child(4)'), '/page/3', 'Go to page 3', '3');
170
- assertIsNextPage($('.ons-pagination__item:nth-child(5)'), '/page/3', 'Go to the next page (Page 3)', 'Next page');
170
+ assertIsNextPage($('.ons-pagination__item:nth-child(5)'), '/page/3', 'Go to the next page (3)', 'Next page');
171
171
  });
172
172
  });
173
173
 
@@ -195,13 +195,13 @@ describe('macro: pagination', () => {
195
195
 
196
196
  it('has a 7 list items ("Previous page", "1", "2", "3", "4", "5", "Next page")', () => {
197
197
  expect($('li').length).toBe(7);
198
- assertIsPreviousPage($('.ons-pagination__item:nth-child(1)'), '/page/1', 'Go to the previous page (Page 1)', 'Previous page');
198
+ assertIsPreviousPage($('.ons-pagination__item:nth-child(1)'), '/page/1', 'Go to the previous page (1)', 'Previous page');
199
199
  assertIsPreviousPage($('.ons-pagination__item:nth-child(2)'), '/page/1', 'Go to page 1', '1');
200
200
  assertIsCurrentPage($('.ons-pagination__item:nth-child(3)'), '/page/2', 'Current page (Page 2 of 5)', '2');
201
201
  assertIsNextPage($('.ons-pagination__item:nth-child(4)'), '/page/3', 'Go to page 3', '3');
202
202
  assertIsOtherPage($('.ons-pagination__item:nth-child(5)'), '/page/4', 'Go to page 4', '4');
203
- assertIsOtherPage($('.ons-pagination__item:nth-child(6)'), '/page/5', 'Go to the last page (Page 5)', '5');
204
- assertIsNextPage($('.ons-pagination__item:nth-child(7)'), '/page/3', 'Go to the next page (Page 3)', 'Next page');
203
+ assertIsOtherPage($('.ons-pagination__item:nth-child(6)'), '/page/5', 'Go to the last page (5)', '5');
204
+ assertIsNextPage($('.ons-pagination__item:nth-child(7)'), '/page/3', 'Go to the next page (3)', 'Next page');
205
205
  });
206
206
  });
207
207
 
@@ -236,13 +236,13 @@ describe('macro: pagination', () => {
236
236
 
237
237
  it('has 7 list items ("Previous page", "1", "2", "3", "...", "6", "Next page")', () => {
238
238
  expect($('li').length).toBe(7);
239
- assertIsPreviousPage($('.ons-pagination__item:nth-child(1)'), '/page/1', 'Go to the previous page (Page 1)', 'Previous page');
239
+ assertIsPreviousPage($('.ons-pagination__item:nth-child(1)'), '/page/1', 'Go to the previous page (1)', 'Previous page');
240
240
  assertIsPreviousPage($('.ons-pagination__item:nth-child(2)'), '/page/1', 'Go to page 1', '1');
241
241
  assertIsCurrentPage($('.ons-pagination__item:nth-child(3)'), '/page/2', 'Current page (Page 2 of 6)', '2');
242
242
  assertIsNextPage($('.ons-pagination__item:nth-child(4)'), '/page/3', 'Go to page 3', '3');
243
243
  assertIsGap($('.ons-pagination__item:nth-child(5)'));
244
- assertIsOtherPage($('.ons-pagination__item:nth-child(6)'), '/page/6', 'Go to the last page (Page 6)', '6');
245
- assertIsNextPage($('.ons-pagination__item:nth-child(7)'), '/page/3', 'Go to the next page (Page 3)', 'Next page');
244
+ assertIsOtherPage($('.ons-pagination__item:nth-child(6)'), '/page/6', 'Go to the last page (6)', '6');
245
+ assertIsNextPage($('.ons-pagination__item:nth-child(7)'), '/page/3', 'Go to the next page (3)', 'Next page');
246
246
  });
247
247
  });
248
248
 
@@ -282,15 +282,15 @@ describe('macro: pagination', () => {
282
282
 
283
283
  it('has a 9 list items ("Previous page", "1", "...", "4", "5", "6", "...", "11", "Next page")', () => {
284
284
  expect($('li').length).toBe(9);
285
- assertIsPreviousPage($('.ons-pagination__item:nth-child(1)'), '/page/4', 'Go to the previous page (Page 4)', 'Previous page');
286
- assertIsOtherPage($('.ons-pagination__item:nth-child(2)'), '/page/1', 'Go to the first page (Page 1)', '1');
285
+ assertIsPreviousPage($('.ons-pagination__item:nth-child(1)'), '/page/4', 'Go to the previous page (4)', 'Previous page');
286
+ assertIsOtherPage($('.ons-pagination__item:nth-child(2)'), '/page/1', 'Go to the first page', '1');
287
287
  assertIsGap($('.ons-pagination__item:nth-child(3)'));
288
288
  assertIsPreviousPage($('.ons-pagination__item:nth-child(4)'), '/page/4', 'Go to page 4', '4');
289
289
  assertIsCurrentPage($('.ons-pagination__item:nth-child(5)'), '/page/5', 'Current page (Page 5 of 11)', '5');
290
290
  assertIsNextPage($('.ons-pagination__item:nth-child(6)'), '/page/6', 'Go to page 6', '6');
291
291
  assertIsGap($('.ons-pagination__item:nth-child(7)'));
292
- assertIsOtherPage($('.ons-pagination__item:nth-child(8)'), '/page/11', 'Go to the last page (Page 11)', '11');
293
- assertIsNextPage($('.ons-pagination__item:nth-child(9)'), '/page/6', 'Go to the next page (Page 6)', 'Next page');
292
+ assertIsOtherPage($('.ons-pagination__item:nth-child(8)'), '/page/11', 'Go to the last page (11)', '11');
293
+ assertIsNextPage($('.ons-pagination__item:nth-child(9)'), '/page/6', 'Go to the next page (6)', 'Next page');
294
294
  });
295
295
  });
296
296
 
@@ -330,13 +330,187 @@ describe('macro: pagination', () => {
330
330
 
331
331
  it('has a 7 list items ("Previous page", "1", "...", "9", "10", "11", "Next page")', () => {
332
332
  expect($('li').length).toBe(7);
333
- assertIsPreviousPage($('.ons-pagination__item:nth-child(1)'), '/page/9', 'Go to the previous page (Page 9)', 'Previous page');
334
- assertIsOtherPage($('.ons-pagination__item:nth-child(2)'), '/page/1', 'Go to the first page (Page 1)', '1');
333
+ assertIsPreviousPage($('.ons-pagination__item:nth-child(1)'), '/page/9', 'Go to the previous page (9)', 'Previous page');
334
+ assertIsOtherPage($('.ons-pagination__item:nth-child(2)'), '/page/1', 'Go to the first page', '1');
335
335
  assertIsGap($('.ons-pagination__item:nth-child(3)'));
336
336
  assertIsPreviousPage($('.ons-pagination__item:nth-child(4)'), '/page/9', 'Go to page 9', '9');
337
337
  assertIsCurrentPage($('.ons-pagination__item:nth-child(5)'), '/page/10', 'Current page (Page 10 of 11)', '10');
338
338
  assertIsNextPage($('.ons-pagination__item:nth-child(6)'), '/page/11', 'Go to page 11', '11');
339
- assertIsNextPage($('.ons-pagination__item:nth-child(7)'), '/page/11', 'Go to the next page (Page 11)', 'Next page');
339
+ assertIsNextPage($('.ons-pagination__item:nth-child(7)'), '/page/11', 'Go to the next page (11)', 'Next page');
340
+ });
341
+ });
342
+
343
+ describe('custom previousAriaLabel and nextAriaLabel', () => {
344
+ const customPreviousAriaLabel = 'Go back to page';
345
+ const customNextAriaLabel = 'Continue to page';
346
+ const $custom = cheerio.load(
347
+ renderComponent('pagination', {
348
+ currentPageNumber: 2,
349
+ pages: [{ url: '/page/1' }, { url: '/page/2' }, { url: '/page/3' }],
350
+ previous: 'Previous',
351
+ next: 'Next',
352
+ previousAriaLabel: customPreviousAriaLabel,
353
+ nextAriaLabel: customNextAriaLabel,
354
+ }),
355
+ );
356
+ const $default = cheerio.load(
357
+ renderComponent('pagination', {
358
+ currentPageNumber: 2,
359
+ pages: [{ url: '/page/1' }, { url: '/page/2' }, { url: '/page/3' }],
360
+ previous: 'Previous',
361
+ next: 'Next',
362
+ }),
363
+ );
364
+
365
+ it('renders the custom previousAriaLabel and page number on the Previous link', () => {
366
+ const prevItem = $custom('.ons-pagination__item--previous');
367
+ expect(prevItem.length).toBe(1);
368
+ expect(prevItem.find('a').attr('aria-label')).toBe('Go back to page (1)');
369
+ });
370
+ it('renders the default previousAriaLabel and page number on the Previous link if not provided', () => {
371
+ const prevItem = $default('.ons-pagination__item--previous');
372
+ expect(prevItem.length).toBe(1);
373
+ expect(prevItem.find('a').attr('aria-label')).toBe('Go to the previous page (1)');
374
+ });
375
+ it('renders the custom nextAriaLabel and page number on the Next link', () => {
376
+ const nextItem = $custom('.ons-pagination__item--next');
377
+ expect(nextItem.length).toBe(1);
378
+ expect(nextItem.find('a').attr('aria-label')).toBe('Continue to page (3)');
379
+ });
380
+ it('renders the default nextAriaLabel and page number on the Next link if not provided', () => {
381
+ const nextItem = $default('.ons-pagination__item--next');
382
+ expect(nextItem.length).toBe(1);
383
+ expect(nextItem.find('a').attr('aria-label')).toBe('Go to the next page (3)');
384
+ });
385
+ });
386
+
387
+ describe('custom ariaLabel', () => {
388
+ it('renders a custom aria-label on the nav element', () => {
389
+ const $ = cheerio.load(
390
+ renderComponent('pagination', {
391
+ currentPageNumber: 2,
392
+ pages: [{ url: '/page/1' }, { url: '/page/2' }, { url: '/page/3' }],
393
+ ariaLabel: 'Custom pagination navigation',
394
+ }),
395
+ );
396
+ expect($('.ons-pagination').attr('aria-label')).toBe('Custom pagination navigation (Page 2 of 3)');
397
+ });
398
+ it('renders the default aria-label on the nav element if not provided', () => {
399
+ const $ = cheerio.load(
400
+ renderComponent('pagination', {
401
+ currentPageNumber: 2,
402
+ pages: [{ url: '/page/1' }, { url: '/page/2' }, { url: '/page/3' }],
403
+ }),
404
+ );
405
+ expect($('.ons-pagination').attr('aria-label')).toBe('Pagination (Page 2 of 3)');
406
+ });
407
+ });
408
+
409
+ describe('custom firstAriaLabel', () => {
410
+ it('renders a custom aria-label on the first page link', () => {
411
+ const $ = cheerio.load(
412
+ renderComponent('pagination', {
413
+ currentPageNumber: 3,
414
+ pages: [{ url: '/page/1' }, { url: '/page/2' }, { url: '/page/3' }, { url: '/page/4' }],
415
+ firstAriaLabel: 'Jump to first page',
416
+ }),
417
+ );
418
+ const firstPageLink = $('.ons-pagination__item a').filter(function () {
419
+ return $(this).text().trim() === '1';
420
+ });
421
+ expect(firstPageLink.attr('aria-label')).toBe('Jump to first page');
422
+ });
423
+ it('renders the default aria-label on the first page link if not provided', () => {
424
+ const $ = cheerio.load(
425
+ renderComponent('pagination', {
426
+ currentPageNumber: 3,
427
+ pages: [{ url: '/page/1' }, { url: '/page/2' }, { url: '/page/3' }, { url: '/page/4' }],
428
+ }),
429
+ );
430
+ const firstPageLink = $('.ons-pagination__item a').filter(function () {
431
+ return $(this).text().trim() === '1';
432
+ });
433
+ expect(firstPageLink.attr('aria-label')).toBe('Go to the first page');
434
+ });
435
+ });
436
+
437
+ describe('custom currentAriaLabel', () => {
438
+ it('renders a custom aria-label on the current page link', () => {
439
+ const $ = cheerio.load(
440
+ renderComponent('pagination', {
441
+ currentPageNumber: 2,
442
+ pages: [{ url: '/page/1' }, { url: '/page/2' }, { url: '/page/3' }],
443
+ currentAriaLabel: 'You are on page',
444
+ }),
445
+ );
446
+ const currentPageLink = $('.ons-pagination__item--current a');
447
+ expect(currentPageLink.attr('aria-label')).toBe('You are on page (Page 2 of 3)');
448
+ });
449
+ it('renders the default aria-label on the current page link if not provided', () => {
450
+ const $ = cheerio.load(
451
+ renderComponent('pagination', {
452
+ currentPageNumber: 2,
453
+ pages: [{ url: '/page/1' }, { url: '/page/2' }, { url: '/page/3' }],
454
+ }),
455
+ );
456
+ const currentPageLink = $('.ons-pagination__item--current a');
457
+ expect(currentPageLink.attr('aria-label')).toBe('Current page (Page 2 of 3)');
458
+ });
459
+ });
460
+
461
+ describe('custom lastAriaLabel', () => {
462
+ it('renders a custom aria-label on the last page link', () => {
463
+ const $ = cheerio.load(
464
+ renderComponent('pagination', {
465
+ currentPageNumber: 2,
466
+ pages: [{ url: '/page/1' }, { url: '/page/2' }, { url: '/page/3' }, { url: '/page/4' }],
467
+ lastAriaLabel: 'Jump to last page',
468
+ }),
469
+ );
470
+ const lastPageLink = $('.ons-pagination__item a').filter(function () {
471
+ return $(this).text().trim() === '4';
472
+ });
473
+ expect(lastPageLink.attr('aria-label')).toBe('Jump to last page (4)');
474
+ });
475
+ it('renders the default aria-label on the last page link if not provided', () => {
476
+ const $ = cheerio.load(
477
+ renderComponent('pagination', {
478
+ currentPageNumber: 2,
479
+ pages: [{ url: '/page/1' }, { url: '/page/2' }, { url: '/page/3' }, { url: '/page/4' }],
480
+ }),
481
+ );
482
+ const lastPageLink = $('.ons-pagination__item a').filter(function () {
483
+ return $(this).text().trim() === '4';
484
+ });
485
+ expect(lastPageLink.attr('aria-label')).toBe('Go to the last page (4)');
486
+ });
487
+ });
488
+
489
+ describe('custom goToAriaLabel', () => {
490
+ it('renders a custom aria-label on non-current, non-first/last page links', () => {
491
+ const $ = cheerio.load(
492
+ renderComponent('pagination', {
493
+ currentPageNumber: 3,
494
+ pages: [{ url: '/page/1' }, { url: '/page/2' }, { url: '/page/3' }, { url: '/page/4' }, { url: '/page/5' }],
495
+ goToAriaLabel: 'Jump to page',
496
+ }),
497
+ );
498
+ const page2Link = $('.ons-pagination__item a').filter(function () {
499
+ return $(this).text().trim() === '2';
500
+ });
501
+ expect(page2Link.attr('aria-label')).toBe('Jump to page 2');
502
+ });
503
+ it('renders the default aria-label on non-current, non-first/last page links if not provided', () => {
504
+ const $ = cheerio.load(
505
+ renderComponent('pagination', {
506
+ currentPageNumber: 3,
507
+ pages: [{ url: '/page/1' }, { url: '/page/2' }, { url: '/page/3' }, { url: '/page/4' }, { url: '/page/5' }],
508
+ }),
509
+ );
510
+ const page2Link = $('.ons-pagination__item a').filter(function () {
511
+ return $(this).text().trim() === '2';
512
+ });
513
+ expect(page2Link.attr('aria-label')).toBe('Go to page 2');
340
514
  });
341
515
  });
342
516
  });