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

[CardActionArea] does not comply with the HTML5 specification #45130

Open
DosymzhanKogabaev opened this issue Jan 27, 2025 · 1 comment
Open
Assignees
Labels
accessibility a11y component: card This is the name of the generic UI component, not the React module!

Comments

@DosymzhanKogabaev
Copy link

DosymzhanKogabaev commented Jan 27, 2025

Steps to reproduce

Steps:

  1. Open this link to live example: (MUI Card Docs)
  2. Open developer tools
  3. Make sure that tag <div> is placed inside a tag <button>, which does not comply to HTML5's specification

Problem:
http://www.w3.org/TR/2012/WD-html5-20120329/the-button-element.html#the-button-element says that a <button> must contain only Phrasing content. Phrasing content is defined as including <span> but not <div>.

Image

Current behavior

<CardActionArea> when rendered becomes a <button> tag. If you add anything inside of it, e.g. <CardContent> or <Box>, it will happen that after rendering, you'll end up with a <button> tag, that has <div> inside of it.

Expected behavior

All components from MUI should follow HTML5's validation rules, including <CardActionArea>.

Context

I was using MUI's <Card> component, which had a <CardActionArea> component inside of it, with child components, such as <CardHeader> and <CardContent>, then I published my website to the server and tried to check for any HTML validation errors on https://validator.w3.org, which showed me errors related to <Card> component from MUI.

Image

Your environment

npx @mui/envinfo
  System:
    OS: Windows 11 10.0.22631
  Binaries:
    Node: 20.18.0 - C:\Program Files\nodejs\node.EXE
    npm: 9.6.6 - C:\Program Files\nodejs\npm.CMD
    pnpm: Not Found
  Browsers:
    Chrome: Not Found
    Edge: Chromium (127.0.2651.74)
  npmPackages:
    @emotion/react: ^11.13.3 => 11.14.0
    @emotion/styled: ^11.13.0 => 11.14.0
    @mui/base:  5.0.0-beta.69
    @mui/core-downloads-tracker:  6.4.1
    @mui/icons-material: ^6.1.3 => 6.4.1
    @mui/lab: ^6.0.0-beta.22 => 6.0.0-beta.24
    @mui/material: ^6.1.3 => 6.4.1
    @mui/private-theming:  6.4.1
    @mui/styled-engine:  6.4.0
    @mui/system:  6.4.1
    @mui/types:  7.2.21
    @mui/utils:  6.4.1
    @types/react: ^18.3.11 => 18.3.18
    react: ^18.3.1 => 18.3.1
    react-dom: ^18.3.1 => 18.3.1
    typescript: ^5.7.3 => 5.7.3

Search keywords: W3C CardActionArea Card HTML5 SEO

@DosymzhanKogabaev DosymzhanKogabaev added the status: waiting for maintainer These issues haven't been looked at yet by a maintainer label Jan 27, 2025
@zannager zannager added the component: card This is the name of the generic UI component, not the React module! label Jan 27, 2025
@mj12albert mj12albert changed the title CardActionArea does not comply with the HTML5 specification [CardActionArea] does not comply with the HTML5 specification Feb 3, 2025
@mj12albert
Copy link
Member

@DosymzhanKogabaev You can do this as a workaround for now:

<CardActionArea component="div" role="button" />

We could probably make this the default (as a breaking change) to allow for arbitrary children more easily

@mj12albert mj12albert added accessibility a11y and removed status: waiting for maintainer These issues haven't been looked at yet by a maintainer labels Feb 3, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
accessibility a11y component: card This is the name of the generic UI component, not the React module!
Projects
None yet
Development

No branches or pull requests

4 participants