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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(user): avatar icon not shown in user #3371

5 changes: 5 additions & 0 deletions .changeset/nice-penguins-work.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@nextui-org/user": patch
---

Removed `name` from `avatarProps` in `use-user.ts` (#3369)
5 changes: 5 additions & 0 deletions .changeset/ten-donuts-tease.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@nextui-org/user": patch
---

Removed `name` from `avatarProps` in `use-user.ts` (#3369)
27 changes: 24 additions & 3 deletions packages/components/user/__tests__/user.test.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import * as React from "react";
import {render} from "@testing-library/react";
import {Link} from "@nextui-org/link";
import {AvatarIcon} from "@nextui-org/avatar";

import {User} from "../src";

Expand All @@ -19,10 +20,30 @@ describe("User", () => {
});

it("should have the passed name", () => {
const {container} = render(<User name="Test" />);
const name = container.querySelector("span");
const {getByText} = render(<User name="Test" />);
const nameElement = getByText("Test");

expect(name).toHaveTextContent("Test");
expect(nameElement).toBeInTheDocument();
});

it("should render the default icon if no name passed to avatar", () => {
const {queryByTestId} = render(
<User
avatarProps={{
radius: "full",
size: "sm",
icon: <AvatarIcon />,
classNames: {
base: "bg-gradient-to-br from-[#FFB457] to-[#FF705B]",
icon: "text-black/80",
},
name: "avatar-icon",
}}
name="Test"
/>,
);

expect(queryByTestId("avatar-icon")).toBeNull();
Copy link
Member

@wingkwong wingkwong Jun 30, 2024

Choose a reason for hiding this comment

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

this test case doesn't match with the title. also the issue is that the attribute name in User component got forwarded to Avatar component. in your test case, it shouldn't have name in avatarProps.

Copy link
Author

Choose a reason for hiding this comment

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

Ok, I Will try again to make it perfect.

});

it("should have the passed description", () => {
Expand Down
1 change: 0 additions & 1 deletion packages/components/user/src/use-user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ export function useUser(props: UseUserProps) {

const avatarProps = {
isFocusable: false,
name: typeof name === "string" ? name : undefined,
...userAvatarProps,
};

Expand Down