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(calendar): remove duplicate information for screen-reader user #2457

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
5 changes: 5 additions & 0 deletions .changeset/nasty-numbers-destroy.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@lion/ui': patch
---

[calendar] remove duplicate information for screen-reader user
1 change: 0 additions & 1 deletion packages/ui/components/calendar/src/calendarStyle.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,6 @@ export const calendarStyle = css`

.u-sr-only {
position: absolute;
top: 0;
width: 1px;
height: 1px;
overflow: hidden;
Expand Down
8 changes: 1 addition & 7 deletions packages/ui/components/calendar/src/utils/dataTemplate.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,7 @@ export function dataTemplate(
<div id="js-content-wrapper">
${data.months.map(
month => html`
<table
role="grid"
data-wrap-cols
aria-readonly="true"
class="calendar__grid"
aria-labelledby="month year"
>
<table role="grid" data-wrap-cols aria-readonly="true" class="calendar__grid">
<thead>
<tr role="row">
${weekdaysShort.map(
Expand Down
10 changes: 5 additions & 5 deletions packages/ui/components/calendar/src/utils/dayTemplate.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@ const lastDaysOfYear = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
* @param {{ weekdays: string[], monthsLabels?: string[] }} opts
*/
export function dayTemplate(day, { weekdays, monthsLabels = defaultMonthLabels }) {
const { dayNumber, monthName, year, weekdayName } = getDayMonthYear(day, weekdays, monthsLabels);
const { dayNumber, monthName, year } = getDayMonthYear(day, weekdays, monthsLabels);

function __getFullDate() {
return `${monthName} ${year} ${weekdayName}`;
function __getMonthAndYear() {
return `${monthName} ${year}.`;
}

function __getAccessibleMessage() {
return `${day.disabledInfo}`;
return ` ${day.disabledInfo}`;
}

const firstDay = dayNumber === 1;
Expand Down Expand Up @@ -66,7 +66,7 @@ export function dayTemplate(day, { weekdays, monthsLabels = defaultMonthLabels }
?next-month=${day.nextMonth}
>
<span class="calendar__day-button__text">${dayNumber}</span>
<span class="u-sr-only">${__getFullDate()} ${__getAccessibleMessage()}</span>
<span class="u-sr-only">${__getMonthAndYear()}${__getAccessibleMessage()}</span>
</div>
</td>
`;
Expand Down
8 changes: 4 additions & 4 deletions packages/ui/components/calendar/test/lion-calendar.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -857,7 +857,7 @@ describe('<lion-calendar>', () => {
30
</span>
<span class="u-sr-only">
September 2019 Monday
September 2019.
</span>
</div>
`);
Expand Down Expand Up @@ -921,7 +921,7 @@ describe('<lion-calendar>', () => {
15
</span>
<span class="u-sr-only">
December 2000 Friday This date is unavailable. Please choose another date.
December 2000. This date is unavailable. Please choose another date.
</span>
</div>
`);
Expand Down Expand Up @@ -950,7 +950,7 @@ describe('<lion-calendar>', () => {
1
</span>
<span class="u-sr-only">
December 2000 Friday This date is unavailable. Earliest available date is 9 December 2000. Please choose another date.
December 2000. This date is unavailable. Earliest available date is 9 December 2000. Please choose another date.
</span>
</div>
`);
Expand Down Expand Up @@ -979,7 +979,7 @@ describe('<lion-calendar>', () => {
30
</span>
<span class="u-sr-only">
December 2000 Saturday This date is unavailable. Latest available date is 9 December 2000. Please choose another date.
December 2000. This date is unavailable. Latest available date is 9 December 2000. Please choose another date.
</span>
</div>
`);
Expand Down
50 changes: 50 additions & 0 deletions packages/ui/components/calendar/test/utils/dataTemplate.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,56 @@ import { dataTemplate } from '../../src/utils/dataTemplate.js';
import snapshot_enGB_Sunday_201812 from './snapshots/monthTemplate_en-GB_Sunday_2018-12.js';

describe('dataTemplate', () => {
it('table row has role="row" to allow users to extend without breaking the accessibility', async () => {
// The reason is: lion is made with extending it in mind. That means overriding css.
// If you change the display prop of tables, it loses its semantics
const date = new Date('2018/12/01');
const month = createMultipleMonth(date, { firstDayOfWeek: 0 });
const el = await fixture(
dataTemplate(month, {
weekdaysShort: weekdayNames['en-GB'].Sunday.short,
weekdays: weekdayNames['en-GB'].Sunday.long,
}),
);
const tableRows = el.querySelectorAll('tr');
expect(tableRows[0].hasAttribute('role')).to.be.true;
expect(tableRows[0].getAttribute('role')).to.equal('row', 'inside thead');
expect(tableRows[1].hasAttribute('role')).to.be.true;
expect(tableRows[1].getAttribute('role')).to.equal('row', 'inside tbody');
});

it('table header has role="columnheader" to allow users to extend without breaking the accessibility', async () => {
// The reason is: lion is made with extending it in mind. That means overriding css.
// If you change the display prop of tables, it loses its semantics
const date = new Date('2018/12/01');
const month = createMultipleMonth(date, { firstDayOfWeek: 0 });
const el = await fixture(
dataTemplate(month, {
weekdaysShort: weekdayNames['en-GB'].Sunday.short,
weekdays: weekdayNames['en-GB'].Sunday.long,
}),
);
const tableRows = el.querySelectorAll('th');
expect(tableRows[0].hasAttribute('role')).to.be.true;
expect(tableRows[0].getAttribute('role')).to.equal('columnheader');
});

it('table cell has role="gridcell" to allow users to extend without breaking the accessibility', async () => {
// The reason is: lion is made with extending it in mind. That means overriding css.
// If you change the display prop of tables, it loses its semantics
const date = new Date('2018/12/01');
const month = createMultipleMonth(date, { firstDayOfWeek: 0 });
const el = await fixture(
dataTemplate(month, {
weekdaysShort: weekdayNames['en-GB'].Sunday.short,
weekdays: weekdayNames['en-GB'].Sunday.long,
}),
);
const tableRows = el.querySelectorAll('td');
expect(tableRows[0].hasAttribute('role')).to.be.true;
expect(tableRows[0].getAttribute('role')).to.equal('gridcell');
});

it('renders one month table', async () => {
const date = new Date('2018/12/01');
const month = createMultipleMonth(date, { firstDayOfWeek: 0 });
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ describe('dayTemplate', () => {
>
<span class="calendar__day-button__text">19</span>
<span class="u-sr-only">
April 2019 Friday
April 2019.
</span>
</div>
</td>
Expand Down
Loading
Loading