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

feat: Autolabel table and cards with header #1364

Merged
merged 6 commits into from
Aug 11, 2023
Merged

Conversation

Al-Dani
Copy link
Member

@Al-Dani Al-Dani commented Jul 25, 2023

Description

Scrollable tables and cards create an unlabelled tabIndex, which leads to screen readers reading out all the contents. This can be fixed manually by providing ariaLabels.tableLabel(cardsLabel) property, but it is not commonly used. To simplify this, we will automatically label table (cards) with a header.
Because header is a slot, we will use context to provide id to the <Header> component, assuming that <Header> is the recommended way to entitle collections.
For the custom headers it's still required to provide ariaLabels.tableLabel(cardsLabel) property

Related links, issue #, if available: AWSUI-21380

How has this been tested?

New unit tests are added, tested with VO+Safari

Review checklist

The following items are to be evaluated by the author(s) and the reviewer(s).

Correctness

  • Changes include appropriate documentation updates.
  • Changes are backward-compatible if not indicated, see CONTRIBUTING.md.
  • Changes do not include unsupported browser features, see CONTRIBUTING.md.
  • Changes were manually tested for accessibility, see accessibility guidelines.

Security

Testing

  • Changes are covered with new/existing unit tests?
  • Changes are covered with new/existing integration tests?

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

@Al-Dani Al-Dani requested a review from a team as a code owner July 25, 2023 09:24
@Al-Dani Al-Dani requested review from YueyingLu and removed request for a team July 25, 2023 09:24
@codecov
Copy link

codecov bot commented Jul 25, 2023

Codecov Report

Patch coverage: 100.00% and no project coverage change.

Comparison is base (e2002cd) 93.58% compared to head (fee5108) 93.59%.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #1364   +/-   ##
=======================================
  Coverage   93.58%   93.59%           
=======================================
  Files         636      637    +1     
  Lines       16934    16950   +16     
  Branches     5581     5584    +3     
=======================================
+ Hits        15848    15864   +16     
  Misses       1014     1014           
  Partials       72       72           
Files Changed Coverage Δ
src/container/internal.tsx 100.00% <ø> (ø)
src/cards/index.tsx 93.97% <100.00%> (+0.07%) ⬆️
src/header/internal.tsx 100.00% <100.00%> (ø)
src/internal/context/collection-label-context.ts 100.00% <100.00%> (ø)
src/table/internal.tsx 98.54% <100.00%> (+0.05%) ⬆️
src/table/table-role/table-role-helper.ts 100.00% <100.00%> (ø)
src/table/tools-header.tsx 100.00% <100.00%> (ø)

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@@ -24,7 +25,12 @@ export default function InternalBox({
__internalRootRef = null,
...props
}: InternalBoxProps) {
const baseProps = getBaseProps(props);
const wrapperHeadingId = useContext(ScrollbarLabelContext);
Copy link
Member

Choose a reason for hiding this comment

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

Box is one of our most used components in the system. I'm a little scared of adding a React context to it. Have you checked this for potential performance degredation?

Copy link
Member Author

Choose a reason for hiding this comment

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

Box is definitely tricky, and there are more concerns (like pointing aria to a non-existing id). So I changed the implementation to provide an id from the header component.
But it might still worth checking for performance issues in a dev pipeline first

// SPDX-License-Identifier: Apache-2.0
import { createContext } from 'react';

export const ScrollbarLabelContext = createContext<string | undefined>(undefined);
Copy link
Member

Choose a reason for hiding this comment

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

Why is this called ScrollbarLabelContext? It sounds like we're adding a label to a scrollbar.

Copy link
Member Author

Choose a reason for hiding this comment

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

Naming is difficult! We are adding a label to table / cards kinda because of a scrollbar. But maybe, CollectionLabelContext sounds better

@@ -12478,12 +12478,12 @@ scroll parent scrolls to reveal the first row of the table.",
* \`allItemsSelectionLabel\` ((SelectionState) => string) - Specifies the alternative text for multi-selection column header.
* \`selectionGroupLabel\` (string) - Specifies the alternative text for the whole selection and single-selection column header.
It is prefixed to \`itemSelectionLabel\` and \`allItemsSelectionLabel\` when they are set.
* \`tableLabel\` (string) - Provides an alternative text for the table. If you use a header for this table, you may reuse the string
Copy link
Member Author

Choose a reason for hiding this comment

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

feels like this property was placed above the following text by accident

YueyingLu
YueyingLu previously approved these changes Aug 1, 2023
timogasda
timogasda previously approved these changes Aug 1, 2023
Copy link
Member

@avinashbot avinashbot left a comment

Choose a reason for hiding this comment

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

Rebase, implicitly approving

@Al-Dani Al-Dani merged commit afa885b into main Aug 11, 2023
24 checks passed
@Al-Dani Al-Dani deleted the table-cards-auto-label branch August 11, 2023 14:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants