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: [M3-7155] - Link Accessibility & Markup on Billing Detail page #9697

Merged
merged 6 commits into from
Sep 20, 2023
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
5 changes: 5 additions & 0 deletions packages/manager/.changeset/pr-9697-fixed-1695133545193.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@linode/manager": Fixed
---

Back link and CSV download button accessibility on Billing Detail page ([#9697](https://github.com/linode/manager/pull/9697))
Original file line number Diff line number Diff line change
Expand Up @@ -135,15 +135,8 @@ describe('Account invoices', () => {
cy.findByText(`Invoice #${mockInvoice.id}`).should('be.visible');
cy.findByText(formatUsd(sumSubtotal + sumTax)).should('be.visible');

ui.button
.findByTitle('Download CSV')
.should('be.visible')
.should('be.enabled');

ui.button
.findByTitle('Download PDF')
.should('be.visible')
.should('be.enabled');
cy.findByText('Download CSV').should('be.visible');
cy.findByText('Download PDF').should('be.visible');
});

// Confirm that invoice summary displays subtotal, tax subtotal, tax summary entries, and grand total.
Expand Down
28 changes: 16 additions & 12 deletions packages/manager/src/components/DownloadCSV/DownloadCSV.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ interface DownloadCSVProps {
data: unknown[];
filename: string;
headers: { key: string; label: string }[];
onClick: () => void;
onClick?: () => void;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like we still may need the onClick support on the MaintenanceTable component

sx?: SxProps;
text?: string;
}
Expand All @@ -40,20 +40,24 @@ export const DownloadCSV = ({
text = 'Download CSV',
}: DownloadCSVProps) => {
return (
<>
<CSVLink
aria-hidden="true"
className={className}
data={cleanCSVData(data)}
filename={filename}
headers={headers}
ref={csvRef}
<CSVLink
className={className}
data={cleanCSVData(data)}
filename={filename}
headers={headers}
ref={csvRef}
>
<Button
buttonType={buttonType}
component="span"
disableRipple
onClick={onClick}
sx={sx}
tabIndex={-1}
/>
<Button buttonType={buttonType} onClick={onClick} sx={sx}>
>
{text}
</Button>
</>
</CSVLink>
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here we use the CSV link as the accessible element rather than the button. (also, downloads are semantically links with href)

Rendering the as a span is a decent way to keep the styling identical while being semantically correct (buttons are not permitted within <a> tags)

Content model: Transparent, but there must be no interactive content descendant.

The a element may be wrapped around entire paragraphs, lists, tables, and so forth, even entire sections, so long as there is no interactive content within (e.g. buttons or other links).

);
};

Expand Down
7 changes: 4 additions & 3 deletions packages/manager/src/components/Link.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -67,18 +67,18 @@ export const Link = (props: LinkProps) => {
className,
external,
forceCopyColor,
hideIcon,
onClick,
to,
hideIcon,
} = props;
const { classes, cx } = useStyles();
const sanitizedUrl = () => sanitizeUrl(to);
const shouldOpenInNewTab = opensInNewTab(sanitizedUrl());
const childrenAsAriaLabel = flattenChildrenIntoAriaLabel(children);
const externalNotice = '- link opens in a new tab';
const ariaLabel = accessibleAriaLabel
? `${accessibleAriaLabel} ${externalNotice}`
: `${childrenAsAriaLabel} ${externalNotice}`;
? `${accessibleAriaLabel} ${shouldOpenInNewTab ? externalNotice : ''}`
: `${childrenAsAriaLabel} ${shouldOpenInNewTab ? externalNotice : ''}`;

if (childrenContainsNoText(children) && !accessibleAriaLabel) {
// eslint-disable-next-line no-console
Expand Down Expand Up @@ -122,6 +122,7 @@ export const Link = (props: LinkProps) => {
</a>
) : (
<RouterLink
aria-label={ariaLabel}
data-testid="internal-link"
{...routerLinkProps}
className={cx(
Expand Down
6 changes: 5 additions & 1 deletion packages/manager/src/features/Account/AccountLanding.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,11 @@ import { useGrants } from 'src/queries/profile';

import AccountLogins from './AccountLogins';

const Billing = React.lazy(() => import('src/features/Billing'));
const Billing = React.lazy(() =>
import('src/features/Billing/BillingDetail').then((module) => ({
default: module.BillingDetail,
}))
);
const EntityTransfersLanding = React.lazy(() =>
import(
'src/features/EntityTransfers/EntityTransfersLanding/EntityTransfersLanding'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,6 @@ const MaintenanceTable = ({ type }: Props) => {

const downloadCSV = async () => {
await getCSVData();
csvRef.current.link.click();
};

return (
Expand Down
6 changes: 4 additions & 2 deletions packages/manager/src/features/Account/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@ import { SuspenseLoader } from 'src/components/SuspenseLoader';
const AccountLanding = React.lazy(
() => import('src/features/Account/AccountLanding')
);
const InvoiceDetail = React.lazy(
() => import('src/features/Billing/InvoiceDetail')
const InvoiceDetail = React.lazy(() =>
import('src/features/Billing/InvoiceDetail/InvoiceDetail').then((module) => ({
default: module.InvoiceDetail,
}))
);
const EntityTransfersCreate = React.lazy(() =>
import(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,14 +129,22 @@ export const InvoiceDetail = () => {
>
<Grid container rowGap={2}>
<Grid xs={12}>
<Grid container spacing={2} sx={sxGrid} data-qa-invoice-header>
<Grid container data-qa-invoice-header spacing={2} sx={sxGrid}>
<Grid sm={4} sx={sxGrid} xs={12}>
<Link to={`/account/billing`} data-qa-back-to-billing>
<Link
accessibleAriaLabel="Back to Billing"
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the missing tag/accessibility support causing the console error:

https://github.com/linode/manager/blob/develop/packages/manager/src/components/Link.tsx#L83-L88

It works! 🎉

data-qa-back-to-billing
to={`/account/billing`}
>
<IconButton
sx={{
padding: 0,
}}
component="span"
disableFocusRipple
role="none"
size="large"
tabIndex={-1}
>
<KeyboardArrowLeft
sx={{
Expand Down Expand Up @@ -168,7 +176,6 @@ export const InvoiceDetail = () => {
data={items}
filename={`invoice-${invoice.date}.csv`}
headers={csvHeaders}
onClick={() => csvRef.current.link.click()}
sx={{ ...sxDownloadButton, marginRight: '8px' }}
/>
<Button
Expand Down Expand Up @@ -246,5 +253,3 @@ export const InvoiceDetail = () => {
</Paper>
);
};

export default InvoiceDetail;

This file was deleted.

1 change: 0 additions & 1 deletion packages/manager/src/features/Billing/index.tsx

This file was deleted.