Skip to content

Conversation

@ChristopherChudzicki
Copy link
Contributor

@ChristopherChudzicki ChristopherChudzicki commented Oct 30, 2024

What are the relevant tickets?

Closes https://github.com/mitodl/hq/issues/5538

Description (What does it do?)

This PR makes some accessibility enhancements to cards and learning resource cards in particular.

Card Title is Link: Previously the entire card was a link. Now just the title is a link, leading to much better link names. The whole card remains clickable.

LearningResourceCards are articles: Learning resource cards now use article as a root element with [resource.type]: [resource.title] as the article name. Consequently, cards are landmarks that appear in landmark navigation

Simplified Positioning: Cards no longer use absolute positioning for buttons.

Screenshots

landmarks_rotor
links_rotor

Card aesthetics should be unchanged:

Screenshot 2024-10-30 at 7 57 45 AM Screenshot 2024-10-30 at 7 57 55 AM Screenshot 2024-10-30 at 7 58 04 AM Screenshot 2024-10-30 at 7 58 12 AM

How can this be tested?

  1. Inspect cards and check that their aesthetic is unchanged. Cards include:
    • Carousel resource cards (LearningResourceCard)
    • Search result cards (LearningResourceListCard)
    • Userlist cards at /dashboard/my-lists/
    • Draggable resource cards at /dashboard/my-lists/{list_id} when "Reordering"
    • News & Events cards on the homepage
      2.Where cards were clickable as links before, they should be now.
    • You should still be able to ctrl+click to open in a new tab
  2. Interactive children in cards should still work, and should NOT navigate the whole link. Examples are
    • "AddToListDialog" (learning path and userlist versions)
    • The "..." menu on learning path cards.

@ChristopherChudzicki ChristopherChudzicki changed the title Cc/cards no root anchor Card Accessibility Improvements Oct 30, 2024
* - an anchor or button element
* - OR an element with data-card-action
*/
forwardClicksToLink?: boolean
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Originally, I made this the default behavior. However, since reliably NOT triggering the link when clicking interactive children requires some effort from consumer (adding data-card-action if the interactive child is not a anchor or button) I decided to make it opt-in to increase visibility.

Comment on lines -133 to -135
position: absolute;
bottom: 16px;
right: 16px;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Previously, we used absolute positioning because:

  • The "main" card element was an anchor
  • anchors can't have interactive children (invalid HTML)
  • so we made anchor + buttons children of a wrapper

Since the main card element is no longer an anchor, this is no longer necessary.

@ChristopherChudzicki ChristopherChudzicki marked this pull request as ready for review October 30, 2024 12:08
@ChristopherChudzicki ChristopherChudzicki added the Needs Review An open Pull Request that is ready for review label Oct 30, 2024
<StyledCard href={href} className={className} size={size}>
<StyledCard
as="article"
aria-label={`${readableType}: ${resource.title}`}
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we need this label? I'm finding that Voiceover repeats the title. Is the<a> content overridable with aria-label to add the readableType

image

This only happens on the small Media carousel cards, but not the Featured Courses carousel, though I don't see any difference in the HTML that would explain why/

Copy link
Contributor Author

@ChristopherChudzicki ChristopherChudzicki Oct 30, 2024

Choose a reason for hiding this comment

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

We do need the label... Otherwise the landmarks menu does not show meaningful info:
landmarks_rotor_nolabel

And landmarks are supposed to have labels:

A visible label should be provided, referenced with aria-labelledby. If necessary, brief, descriptive, label can be provided with aria-label.

That said... Apparently (I just learned) article is not a real landmark role, but MDN's article role page says:

Articles are not considered a navigational landmark, but many assistive technologies that support landmarks also support a means to navigate among articles. They may also support indication of nesting relationships within articles.

I guess VoiceOver just treats them as landmarks.

Anyway: The usage here is based on what we do in OCW. (Although there we have infinite scroll, se we also add aria-posinset.

// alt text will be checked on Card.Image
// eslint-disable-next-line styled-components-a11y/alt-text
<Image
className="MitCard-image"
Copy link
Contributor

Choose a reason for hiding this comment

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

Not one for this PR as this hasn't changed here, but can we use data-testids if these are just for selection in the tests (or ideally avoid altogether). .MitCard-root and .MitCard-info are the only ones in use for CSS selectors.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We do use MitCard-root and MitCard-info for styling at least once, which is why they were added. When I added them, I added for other parts (like MitCard-title) that made sense but weren't actually used (as of yet).

Copy link
Contributor

@jonkafton jonkafton left a comment

Choose a reason for hiding this comment

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

Looks good. Just the one comment with repeated content for the small resources cards, though not sure if this is controlloable or a VoiceOver artifact as the HTML looks the same.

@ChristopherChudzicki ChristopherChudzicki merged commit 2e2193b into main Oct 30, 2024
11 checks passed
This was referenced Oct 31, 2024
This was referenced Nov 5, 2024
@rhysyngsun rhysyngsun deleted the cc/cards-no-root-anchor branch February 7, 2025 20:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Needs Review An open Pull Request that is ready for review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants