Why Card component is not semantic by default? Card, CardHeader, CardContent CardFooter ustilizing only div element #5384
Replies: 2 comments 1 reply
-
For keeping the retrocompatibility, it should be better to mark |
Beta Was this translation helpful? Give feedback.
-
I thought about this also, but then realized that he probably kept this generic to allow users to decide what they want to do with it. Some people use |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
shadcn-ui is wonderful because it doesn't dictate how your components should be built. However, when it comes to the Card component, I have some concerns. Cards are usually used to display a block or an independent piece of information (like theme settings, a post, etc.) at least that is how I use them. Splitting
<Card>
content into blocks like<CardHeader>
,<CardContent>
, and<CardFooter>
is a reasonable approach to highlight important information inside the card, display its title, etc. However, the problem arises when each block is built using only the<div>
element...Why use
<div>
by default? While<div>
is great for creating layouts, there's no doubt that we have semantic elements like<article>
,<header>
, and<footer>
. My suggestion is to switch the Card component to use article, the CardHeader to header, and the CardFooter to footer as the default layout elements e.g:Of course, there isn't a single best solution for people who prefer using a
<Card>
as a wrapper for some other stuff. For those users, there is another way to improve components. React allows you to create elements using thecreateElement
function, which gives you more control over the component. Since different components have different props, it can be even more useful to choose which element you want to use for your card e.g.Considering all of the above, I believe it's better to show more semantic way of building components. While it's rare for users to edit something like a
<Card>
component, it's definitely better to have a semantic card from the scratch.I will be glad to hear you mind regarding matter)
Beta Was this translation helpful? Give feedback.
All reactions