Skip to content

Commit

Permalink
feat(component): Add imgAlt attribute to Cards
Browse files Browse the repository at this point in the history
Allows `Card`s to pass `imgAlt` to provide `alt` text
to the underlying `<img/>`, when an `imgSrc` has also
been provided.

Now, by default, `Card`s with an image will have
`alt=""`, which browsers interpret appropriately as
[decorative images](https://www.w3.org/WAI/tutorials/images/decorative/).

To add `alt` text to your `Card` with an image:

```js
<Card
  imgAlt="Meaningful alt text for an image that is not purely decorative"
  imgSrc="https://flowbite.com/docs/images/people/profile-picture-5.jpg"
>
  ..
</Card>
```
  • Loading branch information
tulup-conner committed Apr 25, 2022
1 parent ffd605b commit aef555c
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/components/Card/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@ import { FC, PropsWithChildren } from 'react';
import classNames from 'classnames';

export type CardProps = PropsWithChildren<{
alt?: string;
className?: string;
horizontal?: boolean;
imgSrc?: string;
}>;

export const Card: FC<CardProps> = ({ children, className, horizontal, imgSrc }) => {
export const Card: FC<CardProps> = ({ alt, children, className, horizontal, imgSrc }) => {
return (
<div
className={classNames(
Expand All @@ -26,7 +27,7 @@ export const Card: FC<CardProps> = ({ children, className, horizontal, imgSrc })
'h-96 w-full rounded-t-lg object-cover md:h-auto md:w-48 md:rounded-none md:rounded-l-lg': horizontal,
})}
src={imgSrc}
alt=""
alt={alt ?? ''}
/>
)}
<div className="flex h-full flex-col justify-center gap-4 p-6">{children}</div>
Expand Down

0 comments on commit aef555c

Please sign in to comment.