Skip to content

Commit

Permalink
fix: render border colors in Avatar with placeholder initials (#521)
Browse files Browse the repository at this point in the history
fix: render border colors in Avatar without image

Fixes the Avatar component so that the `color` prop is respected and the border
is rendered in the expected color when using `placeholderInitials`.

Co-authored-by: Ricardo Lüders <ricardo@luders.com.br>
  • Loading branch information
adamgruber and rluders authored Jan 8, 2023
1 parent 89d2ff8 commit 3aa12c6
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
13 changes: 12 additions & 1 deletion src/lib/components/Avatar/Avatar.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,17 @@ describe('Components / Avatar', () => {
</Flowbite>,
);

expect(initialsPlaceholder()).toHaveTextContent('RR');
expect(initialsPlaceholderText()).toHaveTextContent('RR');
});

it('should support border color with placeholder initials', () => {
render(
<Flowbite>
<Avatar placeholderInitials="RR" bordered color="success" />
</Flowbite>,
);

expect(initialsPlaceholder()).toHaveClass('ring-green-500 dark:ring-green-500');
});
});
describe('Image', () => {
Expand All @@ -71,3 +81,4 @@ describe('Components / Avatar', () => {

const img = () => screen.getByTestId('flowbite-avatar-img');
const initialsPlaceholder = () => screen.getByTestId('flowbite-avatar-initials-placeholder');
const initialsPlaceholderText = () => screen.getByTestId('flowbite-avatar-initials-placeholder-text');
4 changes: 3 additions & 1 deletion src/lib/components/Avatar/Avatar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -102,9 +102,11 @@ const AvatarComponent: FC<AvatarProps> = ({
rounded && theme.rounded,
stacked && theme.stacked,
bordered && theme.bordered,
bordered && theme.color[color],
)}
data-testid="flowbite-avatar-initials-placeholder"
>
<span className={classNames(theme.initials.text)} data-testid="flowbite-avatar-initials-placeholder">
<span className={classNames(theme.initials.text)} data-testid="flowbite-avatar-initials-placeholder-text">
{placeholderInitials}
</span>
</div>
Expand Down

0 comments on commit 3aa12c6

Please sign in to comment.