Skip to content

Commit

Permalink
fix: improve event times table accessibility
Browse files Browse the repository at this point in the history
- Remove index column
- Update heading of actions column
- Change font size to 0 in actions column.
  • Loading branch information
jorilindell committed Mar 28, 2024
1 parent e976320 commit b86b382
Show file tree
Hide file tree
Showing 15 changed files with 39 additions and 63 deletions.
2 changes: 1 addition & 1 deletion src/common/components/table/table.module.scss
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
}

thead tr th:last-of-type {
@include hidden-from-screen;
font-size: 0;
}
}
}
Expand Down
4 changes: 4 additions & 0 deletions src/domain/app/i18n/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -916,6 +916,10 @@
"tabEventTime": "Event time",
"tabRecurringEvent": "Recurring event",
"textNoLinksToEvents": "No links.",
"timesTableColumns": {
"actions": "Edit or delete the date",
"time": "Time"
},
"titleAttendeeCapacity": "Attendee capacity",
"titleAudience": "Target groups",
"titleAudienceAge": "Age restrictions",
Expand Down
4 changes: 4 additions & 0 deletions src/domain/app/i18n/fi.json
Original file line number Diff line number Diff line change
Expand Up @@ -917,6 +917,10 @@
"tabEventTime": "Tapahtuman ajankohta",
"tabRecurringEvent": "Toistuva tapahtuma",
"textNoLinksToEvents": "Ei kytköksiä",
"timesTableColumns": {
"actions": "Muokkaa tai poista ajankohta",
"time": "Ajankohta"
},
"titleAttendeeCapacity": "Osallistujamäärä",
"titleAudience": "Kohderyhmät",
"titleAudienceAge": "Ikärajoitukset",
Expand Down
4 changes: 4 additions & 0 deletions src/domain/app/i18n/sv.json
Original file line number Diff line number Diff line change
Expand Up @@ -917,6 +917,10 @@
"tabEventTime": "Evenemangstid",
"tabRecurringEvent": "Återkommande evenemang",
"textNoLinksToEvents": "Inga länkar.",
"timesTableColumns": {
"actions": "Redigera eller ta bort tid",
"time": "Tid"
},
"titleAttendeeCapacity": "Deltagarkapacitet",
"titleAudience": "Målgrupper",
"titleAudienceAge": "Åldersbegränsningar",
Expand Down
2 changes: 1 addition & 1 deletion src/domain/event/__tests__/EditEventPage.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,7 @@ test('should update recurring event', async () => {
// Delete first sub-event
const withinRow = within(
screen.getByRole('row', {
name: `1 ${formatDate(
name: `${formatDate(
subEventTimes[0].startTime,
DATETIME_FORMAT
)}${formatDate(subEventTimes[0].endTime, DATETIME_FORMAT)}`,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,15 +132,15 @@ test('should render all event times', async () => {

// Event
await screen.findByRole('row', {
name: '1 18.4.2021 12.00 – 18.4.2021 15.00',
name: '18.4.2021 12.00 – 18.4.2021 15.00',
});
// Recurring event
screen.getByRole('heading', {
name: 'Ma, Viikon välein, 1.5.2021 – 15.5.2021',
});
// Single event time
screen.getByRole('row', {
name: '4 11.6.2021 12.00 – 11.6.2021 15.00',
name: '11.6.2021 12.00 – 11.6.2021 15.00',
});
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,10 +155,10 @@ test('should add/delete event time', async () => {
await user.click(addButton);

await screen.findByRole('row', {
name: '1 14.4.2021 12.00 – 14.4.2021 14.00',
name: '14.4.2021 12.00 – 14.4.2021 14.00',
});
screen.getByRole('row', {
name: '2 11.6.2021 12.00 – 11.6.2021 15.00',
name: '11.6.2021 12.00 – 11.6.2021 15.00',
});

const toggleButton = getSingleEventElement('toggle');
Expand All @@ -170,12 +170,12 @@ test('should add/delete event time', async () => {
await waitFor(() =>
expect(
screen.queryByRole('row', {
name: '1 14.4.2021 12.00 – 14.4.2021 14.00',
name: '14.4.2021 12.00 – 14.4.2021 14.00',
})
).not.toBeInTheDocument()
);
screen.getByRole('row', {
name: '1 11.6.2021 12.00 – 11.6.2021 15.00',
name: '11.6.2021 12.00 – 11.6.2021 15.00',
});
});

Expand All @@ -188,7 +188,7 @@ test('should edit event time', async () => {
renderComponent(initialValues);

screen.getByRole('row', {
name: '1 11.6.2021 12.00 – 11.6.2021 15.00',
name: '11.6.2021 12.00 – 11.6.2021 15.00',
});

const toggleMenuButton = screen.getByRole('button', { name: /valinnat/i });
Expand All @@ -211,7 +211,7 @@ test('should edit event time', async () => {
await user.click(updateButton);

await screen.findByRole('row', {
name: '1 2.5.2021 12.00 – 11.6.2021 15.00',
name: '2.5.2021 12.00 – 11.6.2021 15.00',
});
});

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useMemo } from 'react';
import React from 'react';

import FieldColumn from '../../../../app/layout/fieldColumn/FieldColumn';
import EventTimesTable from '../eventTimesTable/EventTimesTable';
Expand All @@ -11,16 +11,6 @@ const EventTimesSummary: React.FC = () => {
const { events, eventTimes, recurringEvents, setEventTimes } =
useTimeSectionContext();

const eventTimesStartIndex = useMemo(() => {
let startIndex = 1 + events.length;

recurringEvents.forEach((recurringEvent) => {
startIndex = startIndex + recurringEvent.eventTimes.length;
});

return startIndex;
}, [events.length, recurringEvents]);

const isVisible =
events?.length || eventTimes?.length || recurringEvents?.length;

Expand All @@ -40,7 +30,6 @@ const EventTimesSummary: React.FC = () => {
<EventTimesTable
eventTimes={eventTimes}
setEventTimes={setEventTimes}
startIndex={eventTimesStartIndex}
/>
</FieldColumn>
</>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,9 @@ test('should render event times summary', async () => {
});
await user.click(toggleButton);

screen.getByRole('row', { name: '1 7.5.2021 12.00 – 7.5.2021 15.00' });
screen.getByRole('row', { name: '2 9.5.2021 12.00 – 9.5.2021 15.00' });
screen.getByRole('row', { name: '7.5.2021 12.00 – 7.5.2021 15.00' });
screen.getByRole('row', { name: '9.5.2021 12.00 – 9.5.2021 15.00' });

screen.getByRole('row', { name: '3 2.5.2021 12.00 – 2.5.2021 15.00' });
screen.getByRole('row', { name: '4 3.5.2021 12.00 – 3.5.2021 15.00' });
screen.getByRole('row', { name: '2.5.2021 12.00 – 2.5.2021 15.00' });
screen.getByRole('row', { name: '3.5.2021 12.00 – 3.5.2021 15.00' });
});
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ interface EventTimeRowProps {
index: number;
onDelete: (index: number) => void;
onUpdate: (index: number, values: EventTime) => void;
startIndex: number;
}

const formatDateStr = (date: Date | null) => formatDate(date, DATETIME_FORMAT);
Expand All @@ -47,7 +46,6 @@ const EventTimeRow: React.FC<EventTimeRowProps> = ({
index,
onDelete,
onUpdate,
startIndex,
}) => {
const { t } = useTranslation();
const { isEditingAllowed, savedEvent } = useTimeSectionContext();
Expand Down Expand Up @@ -170,7 +168,6 @@ const EventTimeRow: React.FC<EventTimeRowProps> = ({
)}

<tr>
<td className={styles.indexColumn}>{startIndex + index}</td>
<td>{dateText}</td>
<td>
<MenuDropdown
Expand Down Expand Up @@ -198,13 +195,11 @@ const EventTimeRow: React.FC<EventTimeRowProps> = ({
export interface EventTimesTableProps {
eventTimes: EventTime[];
setEventTimes: (eventTimes: EventTime[]) => void;
startIndex?: number;
}

const EventTimesTable: React.FC<EventTimesTableProps> = ({
eventTimes,
setEventTimes,
startIndex = 1,
}) => {
const { t } = useTranslation();

Expand Down Expand Up @@ -234,9 +229,8 @@ const EventTimesTable: React.FC<EventTimesTableProps> = ({
>
<thead>
<HeaderRow>
<th className={styles.indexColumn}>#</th>
<th>{t('event.form.labelTime')}</th>
<th>{t('common.actions')}</th>
<th>{t('event.form.timesTableColumns.time')}</th>
<th>{t('event.form.timesTableColumns.actions')}</th>
</HeaderRow>
</thead>
<TableBody>
Expand All @@ -248,7 +242,6 @@ const EventTimesTable: React.FC<EventTimesTableProps> = ({
index={index}
onDelete={handleDelete}
onUpdate={handleUpdate}
startIndex={startIndex}
/>
);
})}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,8 @@ test('should render event times table', async () => {
renderComponent({ eventTimes });

screen.getByRole('table');
screen.getByRole('row', { name: '1 2.5.2021 12.00 – 2.5.2021 15.00' });
screen.getByRole('row', { name: '2 3.5.2021 12.00 – 3.5.2021 15.00' });
screen.getByRole('row', { name: '2.5.2021 12.00 – 2.5.2021 15.00' });
screen.getByRole('row', { name: '3.5.2021 12.00 – 3.5.2021 15.00' });
});

test('should call setEventTimes when deleting an event time', async () => {
Expand All @@ -85,7 +85,7 @@ test('should call setEventTimes when deleting an event time', async () => {
renderComponent({ eventTimes, setEventTimes });

const withinRow = within(
screen.getByRole('row', { name: '1 2.5.2021 12.00 – 2.5.2021 15.00' })
screen.getByRole('row', { name: '2.5.2021 12.00 – 2.5.2021 15.00' })
);
const toggleMenuButton = withinRow.getByRole('button', { name: /valinnat/i });
await user.click(toggleMenuButton);
Expand All @@ -105,7 +105,7 @@ test('should call setEventTimes when updating an event time', async () => {
renderComponent({ eventTimes, setEventTimes });

const withinRow = within(
screen.getByRole('row', { name: '1 2.5.2021 12.00 – 2.5.2021 15.00' })
screen.getByRole('row', { name: '2.5.2021 12.00 – 2.5.2021 15.00' })
);
const toggleMenuButton = withinRow.getByRole('button', { name: /valinnat/i });
await user.click(toggleMenuButton);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@ import useTimeSectionContext from '../hooks/useTimeSectionContext';
import RecurringEvent from './recurringEvent/RecurringEvent';

const RecurringEvents: React.FC = () => {
const { events, recurringEvents, setRecurringEvents } =
useTimeSectionContext();
const { recurringEvents, setRecurringEvents } = useTimeSectionContext();

const handleDelete = (index: number) => {
setRecurringEvents(
Expand All @@ -27,15 +26,6 @@ const RecurringEvents: React.FC = () => {
);
};

const getStartIndex = (index: number) => {
let startIndex = 1 + events.length;

recurringEvents.slice(0, index).forEach((recurringEvent) => {
startIndex = startIndex + recurringEvent.eventTimes.length;
});
return startIndex;
};

return (
<>
{recurringEvents.map((recurringEvent, index) => {
Expand All @@ -47,7 +37,6 @@ const RecurringEvents: React.FC = () => {
onDelete={handleDelete}
onUpdateEventTimes={handleUpdateEventTimes}
recurringEvent={recurringEvent}
startIndex={getStartIndex(index)}
/>
</FormGroup>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,11 +87,11 @@ test('should render component', async () => {
await user.click(toggleButton1);

screen.getByRole('row', {
name: '1 2.5.2021 12.00 – 2.5.2021 15.00',
name: '2.5.2021 12.00 – 2.5.2021 15.00',
hidden: false,
});
screen.getByRole('row', {
name: '2 9.5.2021 12.00 – 9.5.2021 15.00',
name: '9.5.2021 12.00 – 9.5.2021 15.00',
hidden: false,
});

Expand All @@ -101,11 +101,11 @@ test('should render component', async () => {
await user.click(toggleButton2);

screen.getByRole('row', {
name: '3 2.6.2021 12.00 – 2.6.2021 15.00',
name: '2.6.2021 12.00 – 2.6.2021 15.00',
hidden: false,
});
screen.getByRole('row', {
name: '4 9.6.2021 12.00 – 9.6.2021 15.00',
name: '9.6.2021 12.00 – 9.6.2021 15.00',
hidden: false,
});
});
Expand All @@ -124,7 +124,7 @@ test('should call setRecurringEvents when deleting a single event time', async (

const withinEventRow = within(
screen.getByRole('row', {
name: '1 2.5.2021 12.00 – 2.5.2021 15.00',
name: '2.5.2021 12.00 – 2.5.2021 15.00',
})
);
const toggleMenuButton = withinEventRow.getByRole('button', {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,13 @@ type Props = {
onDelete: (index: number) => void;
onUpdateEventTimes: (index: number, eventTimes: EventTime[]) => void;
recurringEvent: RecurringEventSettings;
startIndex: number;
};

const RecurringEvent: React.FC<Props> = ({
index,
onDelete,
onUpdateEventTimes,
recurringEvent,
startIndex,
}) => {
const { endDate, startDate } = useMemo(() => {
return {
Expand Down Expand Up @@ -80,7 +78,6 @@ const RecurringEvent: React.FC<Props> = ({
setEventTimes={(eventTimes: EventTime[]) => {
onUpdateEventTimes(index, eventTimes);
}}
startIndex={startIndex}
/>
</Collapsible>
</FieldWithButton>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,6 @@
.eventTimesTable {
width: 100%;

.indexColumn {
width: var(--spacing-l);
}

.toggleButton {
padding: 0;
display: flex;
Expand Down

0 comments on commit b86b382

Please sign in to comment.