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

Add hidden context for icons in rows for summary tables #3165

Merged
Merged
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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
19 changes: 10 additions & 9 deletions src/components/summary/_macro-options.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,16 @@

## SummaryRowItem

| Name | Type | Required | Description |
| ------------------ | ---------------------- | -------- | ------------------------------------------------------------------------------------------- |
| id | string | false | The HTML `id` of the row item |
| iconType | string | false | Adds an icon before the row title, by setting the [icon type](/foundations/icons#icon-type) |
| rowTitle | string | false | The title for the row item |
| rowTitleAttributes | object | false | HTML attributes (for example, data attributes) to add to the rowTitle |
| 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 |
| ---------------------- | ---------------------- | -------- | ------------------------------------------------------------------------------------------- |
| id | string | false | The HTML `id` of the row item |
| 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 |
| rowTitle | string | false | The title for the row item |
| rowTitleAttributes | object | false | HTML attributes (for example, data attributes) to add to the rowTitle |
| 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 |

## SummaryValue

Expand Down
5 changes: 4 additions & 1 deletion src/components/summary/_macro.njk
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
{% if params.classes %}
{% set className = className + " " + params.classes %}
{% endif %}

<div class="{{ className }}">
{% for summary in params.summaries %}
{% if summary.summaryTitle %}
Expand Down Expand Up @@ -51,6 +51,9 @@
"iconType": rowItem.iconType
})
-}}
{% if rowItem.iconVisuallyHiddenText %}
<span class="ons-u-vh">{{ rowItem.iconVisuallyHiddenText }}</span>
{% endif %}
</span>
{% endif %}

Expand Down
7 changes: 7 additions & 0 deletions src/components/summary/_macro.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ const EXAMPLE_SUMMARY_ROWS = {
b: 'bbb',
},
iconType: 'check',
iconVisuallyHiddenText: 'Section completed',
id: 'item-id-1',
valueList: [
{
Expand Down Expand Up @@ -432,6 +433,12 @@ describe('macro: summary', () => {
expect($('.ons-summary__item-title-icon').hasClass('ons-summary__item-title-icon--check')).toBe(true);
});

it('has the visually hidden text <span> text when `iconType` is `check`', () => {
const $ = cheerio.load(renderComponent('summary', EXAMPLE_SUMMARY_BASIC));

expect($('.ons-summary__item-title-icon').text().trim()).toBe('Section completed');
});

it('has the correct item text class when `iconType` is provided', () => {
const $ = cheerio.load(renderComponent('summary', EXAMPLE_SUMMARY_BASIC));

Expand Down
75 changes: 75 additions & 0 deletions src/components/summary/example-summary-hub-minimal.njk
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
{% from "components/summary/_macro.njk" import onsSummary %}

{{ onsSummary({
"variant": "hub",
"summaries": [
{
"groups": [
{
"rows": [
{
"rowTitle": "People who live here",
"rowItems": [
{
"iconType": "check",
"iconVisuallyHiddenText": "Section complete",
"actions": [
{
"text": "View answers",
"visuallyHiddenText": "View answers for People who live here",
"url": "#0"
}
]
}
]
},
{
"rowTitle": "Mary Smith (You)",
"rowItems": [
{
"iconType": "check",
"iconVisuallyHiddenText": "Section complete",
"actions": [
{
"text": "View answers",
"visuallyHiddenText": "View answers for Mary Smith",
"url": "#0"
}
]
}
]
},
{
"rowTitle": "John Smith",
"rowItems": [
{
"actions": [
{
"text": "Continue with section",
"visuallyHiddenText": "Continue with John Smith's section",
"url": "#0"
}
]
}
]
},
{
"rowTitle": "Billy Smith",
"rowItems": [
{
"actions": [
{
"text": "Start section",
"visuallyHiddenText": "Start Billy Smith's section",
"url": "#0"
}
]
}
]
}
]
}
]
}
]
}) }}
Loading