Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix summary rendering when no valueList is supplied #3521

Draft
wants to merge 8 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions src/components/summary/_macro-options.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,15 @@

## SummaryRowItem

| Name | Type | Required | Description |
| ---------------------- | ---------------------- | -------- | ------------------------------------------------------------------------------------------- |
| iconType | string | false | Adds an icon before the row title, by setting the [icon type](/foundations/icons#icon-type) |
| iconVisuallyHiddenText | string | false | Visually hidden text in a span under the icon to add more context for screen readers |
| title | string | false | The title for the row item |
| titleAttributes | object | false | HTML attributes (for example, data attributes) to add to the row title |
| valueList | Array`<SummaryValue>` | false | An array of [value(s)](#summaryvalue) for the row item |
| actions | Array`<SummaryAction>` | false | Settings for the row [action links](#summaryaction) |
| attributes | object | false | HTML attributes (for example, data attributes) to add to the row item |
| Name | Type | Required | Description |
| ---------------------- | ---------------------- | -------------------------------- | ------------------------------------------------------------------------------------------- |
| iconType | string | false | Adds an icon before the row title, by setting the [icon type](/foundations/icons#icon-type) |
| iconVisuallyHiddenText | string | false | Visually hidden text in a span under the icon to add more context for screen readers |
| title | string | true | The title for the row item |
| titleAttributes | object | false | HTML attributes (for example, data attributes) to add to the row title |
| valueList | Array`<SummaryValue>` | false (if actions is provided) | An array of [value(s)](#summaryvalue) for the row item |
| actions | Array`<SummaryAction>` | false (if valueList is provided) | Settings for the row [action links](#summaryaction) |
| attributes | object | false | HTML attributes (for example, data attributes) to add to the row item |

## SummaryValue

Expand Down
4 changes: 2 additions & 2 deletions src/components/summary/_macro.njk
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@
</dt>
{% if item.valueList %}
<dd
class="ons-summary__values{{ ' ons-summary__values--2' if not item.actions }}"
class="ons-summary__values{{ ' ons-summary__column-size--2' if not item.actions }}"
{% if item.attributes %}{% for attribute, value in (item.attributes.items() if item.attributes is mapping and item.attributes.items else item.attributes) %}{{ attribute }}="{{ value }}"{% endfor %}{% endif %}
>
{% if item.valueList | length == 1 %}
Expand All @@ -104,7 +104,7 @@
</dd>
{% endif %}
{% if item.actions %}
<dd class="ons-summary__actions">
<dd class="ons-summary__actions{{ ' ons-summary__column-size--2' if not item.valueList }}">
{% for action in item.actions %}
{% if loop.index > 1 %}<span class="ons-summary__spacer"></span>{% endif %}
<a
Expand Down
58 changes: 37 additions & 21 deletions src/components/summary/_macro.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -196,20 +196,10 @@ const EXAMPLE_SUMMARY_HOUSEHOLD_GROUP = {
itemsList: [
{
title: 'row item 4',
valueList: [
{
text: 'list item 4',
},
],
actions: [
{
text: 'Change',
visuallyHiddenText: 'change answer',
url: '#0',
},
{
text: 'Remove',
visuallyHiddenText: 'remove list item',
visuallyHiddenText: 'change list item',
url: '#0',
},
],
Expand All @@ -221,13 +211,6 @@ const EXAMPLE_SUMMARY_HOUSEHOLD_GROUP = {
text: 'list item 5',
},
],
actions: [
{
text: 'Change',
visuallyHiddenText: 'change list item',
url: '#0',
},
],
},
{
title: 'row item 6',
Expand Down Expand Up @@ -304,6 +287,21 @@ const EXAMPLE_SUMMARY_MULTIPLE_GROUPS = {
],
};

const EXAMPLE_SUMMARY_SINGLE_GROUP = {
summaries: [
{
title: 'summary title',
groups: [
{
id: 'group-id-1',
title: 'group title',
...EXAMPLE_SUMMARY_HOUSEHOLD_GROUP,
},
],
},
],
};

// To address a DAC issue, we've disabled specific axe definition list rules causing test failures.
// While resolving it would require a significant refactor, the failures are deemed non-critical for accessibility,
// leading to their removal in this context. [https://github.com/ONSdigital/design-system/issues/3027]
Expand Down Expand Up @@ -411,9 +409,9 @@ describe('macro: summary', () => {
it('displays the row `title` text', () => {
const $ = cheerio.load(renderComponent('summary', EXAMPLE_SUMMARY_BASIC));

expect($('.ons-summary__items .ons-summary__item:nth-of-type(1) .ons-summary__item--text').text().trim()).toBe(
'row title 1',
);
expect(
$('.ons-summary__items .ons-summary__item:nth-of-type(1) .ons-summary__item--text:nth-of-type(1)').text().trim(),
).toBe('row title 1');
});

it('has a custom icon `iconType`', () => {
Expand Down Expand Up @@ -473,6 +471,16 @@ describe('macro: summary', () => {

expect($('.ons-summary__items .ons-summary__item:nth-of-type(3) .ons-summary__values ul').length).toBe(1);
});

it('adds the `ons-summary__column-size--2` class if no `valueList` is provided', () => {
const $ = cheerio.load(renderComponent('summary', EXAMPLE_SUMMARY_SINGLE_GROUP));

expect(
$('.ons-summary__items .ons-summary__item:nth-of-type(2) .ons-summary__actions').hasClass(
'ons-summary__column-size--2',
),
).toBe(true);
});
});

describe('part: item action', () => {
Expand Down Expand Up @@ -543,6 +551,14 @@ describe('macro: summary', () => {
),
).toBe('def');
});

it('adds the `ons-summary__column-size--2` class if no action is provided', () => {
const $ = cheerio.load(renderComponent('summary', EXAMPLE_SUMMARY_SINGLE_GROUP));

expect(
$('.ons-summary__items .ons-summary__item:nth-of-type(2) .ons-summary__values').hasClass('ons-summary__column-size--2'),
).toBe(true);
});
});
});

Expand Down
2 changes: 1 addition & 1 deletion src/components/summary/_summary.scss
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ $hub-row-spacing: 1.3rem;
text-align: right;
}

&__values--2 {
&__column-size--2 {
flex: 10.5 1 66%;
}

Expand Down
12 changes: 0 additions & 12 deletions src/components/summary/example-summary-grouped.njk
Original file line number Diff line number Diff line change
Expand Up @@ -284,11 +284,6 @@
"itemsList": [
{
"title": "Food",
"valueList": [
{
"text": "£50.00"
}
],
"actions": [
{
"text": "Change",
Expand Down Expand Up @@ -333,13 +328,6 @@
{
"text": "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat."
}
],
"actions": [
{
"text": "Change",
"visuallyHiddenText": "Change answer",
"url": "#0"
}
]
}
]
Expand Down
Loading