Skip to content

Commit

Permalink
Description list not structured properly for screen readers (#3053)
Browse files Browse the repository at this point in the history
* initial change

* update test

* update test

* update comment

* update comment
  • Loading branch information
precious-onyenaucheya-ons authored and rmccar committed Mar 6, 2024
1 parent 0aa73cd commit 4c675dd
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 14 deletions.
9 changes: 4 additions & 5 deletions src/components/summary/_macro.njk
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@
<h{{ titleSize }} class="ons-summary__group-title">{{ group.groupTitle }}</h{{ titleSize }}>
{% endif %}
{% if group.rows %}
<div class="ons-summary__items">

<dl class="ons-summary__items">
{% for row in group.rows %}
{% set itemClass = "" %}
{% if row.error %} {% set itemClass = " ons-summary__item--error" %}{% endif %}
Expand All @@ -40,7 +39,7 @@
{% endif %}

{% for rowItem in row.rowItems %}
<dl class="ons-summary__row{{ " ons-summary__row--has-values" if rowItem.valueList else "" }}"{% if rowItem.id %} id="{{ rowItem.id }}"{% endif %}>
<div class="ons-summary__row{{ " ons-summary__row--has-values" if rowItem.valueList else "" }}"{% if rowItem.id %} id="{{ rowItem.id }}"{% endif %}>
<dt class="ons-summary__item-title"
{% if rowItem.rowTitleAttributes %}{% for attribute, value in (rowItem.rowTitleAttributes.items() if rowItem.rowTitleAttributes is mapping and rowItem.rowTitleAttributes.items else rowItem.rowTitleAttributes) %}{{attribute}}="{{value}}" {% endfor %}{% endif %}
>
Expand Down Expand Up @@ -104,11 +103,11 @@
{% endfor %}
</dd>
{% endif %}
</dl>
</div>
{% endfor %}
</div>
{% endfor %}
</div>
</dl>
{% elif group.placeholderText %}
<span class="ons-summary__placeholder">{{ group.placeholderText }}</span>
{% endif %}
Expand Down
36 changes: 27 additions & 9 deletions src/components/summary/_macro.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -303,12 +303,26 @@ const EXAMPLE_SUMMARY_MULTIPLE_GROUPS = {
],
};

// 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]
const axeRules = {
rules: {
dlitem: {
enabled: false,
},
'definition-list': {
enabled: false,
},
},
};

describe('macro: summary', () => {
describe('mode: general', () => {
it('passes jest-axe checks', async () => {
const $ = cheerio.load(renderComponent('summary', EXAMPLE_SUMMARY_BASIC));
const results = await axe($.html(), axeRules);

const results = await axe($.html());
expect(results).toHaveNoViolations();
});

Expand Down Expand Up @@ -436,15 +450,19 @@ describe('macro: summary', () => {
it('displays the `valueList` text', () => {
const $ = cheerio.load(renderComponent('summary', EXAMPLE_SUMMARY_BASIC));

expect($('.ons-summary__items .ons-summary__item:nth-of-type(1) dl .ons-summary__values .ons-summary__text').text().trim()).toBe(
'row value 1',
);
expect(
$('.ons-summary__items .ons-summary__item:nth-of-type(1) .ons-summary__row .ons-summary__values .ons-summary__text')
.text()
.trim(),
).toBe('row value 1');
});

it('displays the `other` text', () => {
const $ = cheerio.load(renderComponent('summary', EXAMPLE_SUMMARY_BASIC));

expect($('.ons-summary__items .ons-summary__item:nth-of-type(1) dl .ons-summary__values ul li').text().trim()).toBe('other value');
expect($('.ons-summary__items .ons-summary__item:nth-of-type(1) .ons-summary__row .ons-summary__values ul li').text().trim()).toBe(
'other value',
);
});

it('wraps the `valueList` in a ul if multiple values provided', () => {
Expand Down Expand Up @@ -516,8 +534,8 @@ describe('macro: summary', () => {
describe('mode: with title', () => {
it('passes jest-axe checks', async () => {
const $ = cheerio.load(renderComponent('summary', EXAMPLE_SUMMARY_WITH_TITLE));
const results = await axe($.html(), axeRules);

const results = await axe($.html());
expect(results).toHaveNoViolations();
});

Expand All @@ -536,8 +554,8 @@ describe('macro: summary', () => {
variant: 'hub',
}),
);
const results = await axe($.html(), axeRules);

const results = await axe($.html());
expect(results).toHaveNoViolations();
});

Expand Down Expand Up @@ -570,7 +588,7 @@ describe('macro: summary', () => {
it('passes jest-axe checks', async () => {
const $ = cheerio.load(renderComponent('summary', EXAMPLE_SUMMARY_WITH_NO_ROWS));

const results = await axe($.html());
const results = await axe($.html(), axeRules);
expect(results).toHaveNoViolations();
});

Expand Down Expand Up @@ -609,8 +627,8 @@ describe('macro: summary', () => {
describe('mode: card', () => {
it('passes jest-axe checks', async () => {
const $ = cheerio.load(renderComponent('summary', { ...EXAMPLE_SUMMARY_BASIC, variant: 'card' }));
const results = await axe($.html(), axeRules);

const results = await axe($.html());
expect(results).toHaveNoViolations();
});

Expand Down

0 comments on commit 4c675dd

Please sign in to comment.