Skip to content

Not able to apply dynamic value to className on the basis of condition #18455

@muhammadmeharbhutta

Description

@muhammadmeharbhutta

What version of Tailwind CSS are you using?

v4.01.10

What build tool (or framework if it abstracts the build tool) are you using?

Vite 6.3.5

What version of Node.js are you using?

For example: v22.16.0

What browser are you using?

Chrome

What operating system are you using?

Windows

Code

export interface UserAvatarProps {
  src: string | null | undefined;
  firstName: string;
  lastName: string | null | undefined;
  className?: string;
  showOnOff?: boolean;
  isOnline?: boolean;
  size?: number;
  contentSize?: string;
  borderSize?: number;
  background?: string;
  content?: string;
}

const UserAvatar = (props: UserAvatarProps) => {
  const {
    src,
    firstName,
    lastName,
    size = 10,
    contentSize = "sm",
    background = "bg-accent",
    content = "text-accent-content",
    borderSize,
    className,
    showOnOff,
    isOnline,
  } = props;
  return (
    <div
      className={`avatar avatar-placeholder ${
        showOnOff ? (isOnline ? "avatar-online" : "avatar-offline") : ""
      } ${className ? className : ""}`}
    >
      <div
        className={`overflow-hidden rounded-full size-${size} ${
          borderSize ? `border-${borderSize}` : ""
        } ${background} ${content}`}
      >
        {src ? (
          <img src={src} alt={`Avatar ${firstName} ${lastName}`} />
        ) : (
          <span className={`text-${contentSize}`}>
            {firstName[0]}
            {lastName && lastName[0]}
          </span>
        )}
      </div>
    </div>
  );
};

export default UserAvatar;

Describe your issue

Not assigning the size-32 and border-2 class if the size value change to 32 and border value to 2 and also not showing class even when inspect.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions