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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(avatar): avoid passing disableAnimation prop to a DOM element #3111

Merged
merged 4 commits into from
May 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/hungry-garlics-kiss.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@nextui-org/avatar": patch
---

avoid passing `disableAnimation` prop to a DOM element (#3109)
19 changes: 13 additions & 6 deletions packages/components/avatar/src/use-avatar.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import type {AvatarSlots, AvatarVariantProps, SlotsToClasses} from "@nextui-org/theme";
import type {DOMElement, DOMAttributes, HTMLNextUIProps, PropGetter} from "@nextui-org/system";
wingkwong marked this conversation as resolved.
Show resolved Hide resolved

import {avatar} from "@nextui-org/theme";
import {HTMLNextUIProps, PropGetter, useProviderContext} from "@nextui-org/system";
import {useProviderContext} from "@nextui-org/system";
import {mergeProps} from "@react-aria/utils";
import {useDOMRef} from "@nextui-org/react-utils";
import {ReactRef, useDOMRef, filterDOMProps} from "@nextui-org/react-utils";
import {clsx, safeText, dataAttr} from "@nextui-org/shared-utils";
import {ReactRef} from "@nextui-org/react-utils";
import {useFocusRing} from "@react-aria/focus";
import {useMemo, useCallback} from "react";
import {useImage} from "@nextui-org/use-image";
Expand Down Expand Up @@ -141,6 +141,8 @@ export function useAvatar(originalProps: UseAvatarProps = {}) {

const isImgLoaded = imageStatus === "loaded";

const shouldFilterDOMProps = typeof ImgComponent === "string";

/**
* Fallback avatar applies under 2 conditions:
* - If `src` was passed and the image has not loaded or failed to load
Expand Down Expand Up @@ -199,12 +201,17 @@ export function useAvatar(originalProps: UseAvatarProps = {}) {
(props = {}) => ({
ref: imgRef,
src: src,
disableAnimation,
"data-loaded": dataAttr(isImgLoaded),
className: slots.img({class: classNames?.img}),
...mergeProps(imgProps, props),
...mergeProps(
imgProps,
props,
filterDOMProps({disableAnimation} as DOMAttributes<DOMElement>, {
enabled: shouldFilterDOMProps,
}),
),
}),
[slots, isImgLoaded, imgProps, disableAnimation, src, imgRef],
[slots, isImgLoaded, imgProps, disableAnimation, src, imgRef, shouldFilterDOMProps],
);

return {
Expand Down
Loading