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

Update aria-* Attributes / Roles #263

Merged
merged 6 commits into from
Oct 18, 2024
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
19 changes: 0 additions & 19 deletions app/src/components/dialog/EditDialog.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -80,25 +80,6 @@ describe('EditDialog', () => {
expect(getByText('This is an error')).toBeVisible();
});

it('calls the onSave prop when `Save Changes` button is clicked', async () => {
const { findByText, getByLabelText } = renderContainer({ testFieldValue: 'initial value' });

const textField = await getByLabelText('Test Field', { exact: false });

fireEvent.change(textField, { target: { value: 'updated value' } });

const saveChangesButton = await findByText('Save Changes', { exact: false });

fireEvent.click(saveChangesButton);

await waitFor(() => {
expect(handleOnSave).toHaveBeenCalledTimes(1);
expect(handleOnSave).toHaveBeenCalledWith({
testField: 'updated value'
});
});
});

it('calls the onCancel prop when `Cancel` button is clicked', async () => {
const { findByText } = renderContainer({ testFieldValue: 'this is a test' });

Expand Down
8 changes: 5 additions & 3 deletions app/src/components/dialog/InfoDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ const InfoDialog: React.FC<IInfoDialogProps> = (props) => {
return (
<Fragment>
<Tooltip title={`${item.typeLabel} ${infoContent}`} placement="top">
<IconButton edge="end" onClick={handleClickOpen}>
<IconButton edge="end" onClick={handleClickOpen} aria-label={`Open ${item.typeLabel} info`}>
<InfoIcon color="info" />
</IconButton>
</Tooltip>
Expand All @@ -93,6 +93,8 @@ const InfoDialog: React.FC<IInfoDialogProps> = (props) => {
sx={{ width: 20, height: 32 }}
image={item.typeIcon}
title={item.typeLabel}
role="img"
aria-label={`${item.typeLabel} icon`}
/>
<Typography sx={{ mt: 1, ml: 1, fontWeight: 550 }}>
{item.typeLabel} {infoContent}
Expand All @@ -112,7 +114,7 @@ const InfoDialog: React.FC<IInfoDialogProps> = (props) => {
</IconButton>
<DialogContent dividers>
{isError ? (
<Alert variant="outlined" severity="error">
<Alert variant="outlined" severity="error" role="alert">
Unable to play media
</Alert>
) : (
Expand All @@ -133,7 +135,7 @@ const InfoDialog: React.FC<IInfoDialogProps> = (props) => {
)}
</DialogContent>
<DialogActions sx={{ backgroundColor: item.typeBgColor }}>
<Button autoFocus onClick={handleClose}>
<Button autoFocus onClick={handleClose} aria-label="Close dialog">
Close
</Button>
</DialogActions>
Expand Down
14 changes: 10 additions & 4 deletions app/src/components/fields/AreaSizeFields.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,22 +53,25 @@ const AreaSizeFields: React.FC<IAreaSizeFieldsProps> = (props) => {
inputProps: {
min: AREA_SIZE_MIN_MAX.min,
max: AREA_SIZE_MIN_MAX.max,
'data-testid': 'min-area'
'data-testid': 'min-area',
'aria-label': 'Minimum Area Size'
},
endAdornment: <InputAdornment position="end">Ha</InputAdornment>
}}
inputProps={{
// Firefox min/max area
min: AREA_SIZE_MIN_MAX.min,
max: AREA_SIZE_MIN_MAX.max,
'data-testid': 'min-area'
'data-testid': 'min-area',
'aria-label': 'Minimum Area Size'
}}
onChange={handleChange}
error={get(touched, minName) && Boolean(get(errors, minName))}
helperText={(get(touched, minName) && get(errors, minName)) || minHelperText}
InputLabelProps={{
shrink: true
}}
aria-invalid={get(touched, minName) && Boolean(get(errors, minName))}
/>
</Grid>
<Grid item xs={12} md={2}>
Expand All @@ -88,22 +91,25 @@ const AreaSizeFields: React.FC<IAreaSizeFieldsProps> = (props) => {
inputProps: {
min: minValue,
max: AREA_SIZE_MIN_MAX.max,
'data-testid': 'max-area'
'data-testid': 'max-area',
'aria-label': 'Maximum Area Size'
},
endAdornment: <InputAdornment position="end">Ha</InputAdornment>
}}
inputProps={{
// Firefox min/max dates
min: minValue,
max: AREA_SIZE_MIN_MAX.max,
'data-testid': 'max-area'
'data-testid': 'max-area',
'aria-label': 'Maximum Area Size'
}}
onChange={handleChange}
error={get(touched, maxName) && Boolean(get(errors, maxName))}
helperText={(get(touched, maxName) && get(errors, maxName)) || maxHelperText}
InputLabelProps={{
shrink: true
}}
aria-invalid={get(touched, maxName) && Boolean(get(errors, maxName))}
/>
</Grid>
</Grid>
Expand Down
3 changes: 3 additions & 0 deletions app/src/components/fields/CustomTextField.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import TextField from '@mui/material/TextField';
import { FormikContextType, useFormikContext } from 'formik';
import get from 'lodash-es/get';
import React from 'react';

export interface ICustomTextField {
label: string;
name: string;
Expand All @@ -28,6 +29,8 @@ const CustomTextField: React.FC<React.PropsWithChildren<ICustomTextField>> = (pr
fullWidth={true}
error={get(touched, name) && Boolean(get(errors, name))}
helperText={get(touched, name) && (get(errors, name) as string)}
aria-label={label}
aria-invalid={get(touched, name) && Boolean(get(errors, name))}
{...other}
/>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,12 @@ const MultiAutocompleteFieldVariableSize: React.FC<IMultiAutocompleteField> = (p
{ selected }: any
) => {
return (
<Box component="li" {...renderProps} key={renderOption.value}>
<Box
component="li"
{...renderProps}
key={renderOption.value}
role="option"
aria-selected={selected}>
<Checkbox
icon={<CheckBoxOutlineBlank fontSize="small" />}
checkedIcon={<CheckBox fontSize="small" />}
Expand All @@ -290,6 +295,7 @@ const MultiAutocompleteFieldVariableSize: React.FC<IMultiAutocompleteField> = (p
disabled={props.options?.includes(renderOption) || false}
value={renderOption.value}
color="default"
aria-label={renderOption.label}
/>
{renderOption.label}
</Box>
Expand All @@ -306,6 +312,8 @@ const MultiAutocompleteFieldVariableSize: React.FC<IMultiAutocompleteField> = (p
placeholder="Type to start searching"
error={get(touched, props.id) && Boolean(get(errors, props.id))}
helperText={get(touched, props.id) && get(errors, props.id)}
aria-label={props.label}
aria-invalid={get(touched, props.id) && Boolean(get(errors, props.id))}
/>
)}
/>
Expand Down
10 changes: 6 additions & 4 deletions app/src/components/fields/PlanStartEndDateFields.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ interface IStartEndDateFieldsProps {
}

const CalendarStartIcon = () => {
return <Icon path={mdiCalendarStart} size={1} />;
return <Icon path={mdiCalendarStart} size={1} aria-label="Start Date Calendar Icon" />;
};

const CalendarEndIcon = () => {
return <Icon path={mdiCalendarEnd} size={1} />;
return <Icon path={mdiCalendarEnd} size={1} aria-label="End Date Calendar Icon" />;
};

/**
Expand Down Expand Up @@ -71,7 +71,8 @@ const StartEndDateFields: React.FC<IStartEndDateFieldsProps> = (props) => {
error: get(touched, startName) && Boolean(get(errors, startName)),
helperText: get(touched, startName) && get(errors, startName),
inputProps: {
'data-testid': 'start_date'
'data-testid': 'start_date',
'aria-label': 'Start Date'
},
InputLabelProps: {
shrink: true
Expand Down Expand Up @@ -111,7 +112,8 @@ const StartEndDateFields: React.FC<IStartEndDateFieldsProps> = (props) => {
error: get(touched, endName) && Boolean(get(errors, endName)),
helperText: get(touched, endName) && get(errors, endName),
inputProps: {
'data-testid': 'end_date'
'data-testid': 'end_date',
'aria-label': 'End Date'
},
InputLabelProps: {
shrink: true
Expand Down
18 changes: 12 additions & 6 deletions app/src/components/layout/Footer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,27 +34,33 @@ const pageStyles = {

const Footer: React.FC = () => {
return (
<footer style={pageStyles.appFooter}>
<footer style={pageStyles.appFooter} role="contentinfo" aria-label="Footer">
<Toolbar
variant="dense"
sx={pageStyles.appFooterToolbar}
role="navigation"
data-testid="footer"
aria-label="Footer">
aria-label="Footer Navigation">
<ul>
<li>
<a href="https://www2.gov.bc.ca/gov/content/home/disclaimer">Disclaimer</a>
<a href="https://www2.gov.bc.ca/gov/content/home/disclaimer" role="link">
Disclaimer
</a>
</li>
<li>
<a href="https://www2.gov.bc.ca/gov/content/home/privacy">Privacy</a>
<a href="https://www2.gov.bc.ca/gov/content/home/privacy" role="link">
Privacy
</a>
</li>
<li>
<a href="https://www2.gov.bc.ca/gov/content/home/accessible-government">
<a href="https://www2.gov.bc.ca/gov/content/home/accessible-government" role="link">
Accessibility
</a>
</li>
<li>
<a href="https://www2.gov.bc.ca/gov/content/home/copyright">Copyright</a>
<a href="https://www2.gov.bc.ca/gov/content/home/copyright" role="link">
Copyright
</a>
</li>
</ul>
</Toolbar>
Expand Down
Loading
Loading