Skip to content

Commit

Permalink
fix(avatar): avoid passing disableAnimation prop to a DOM element (#…
Browse files Browse the repository at this point in the history
…3111)

* fix(avatar): avoid passing `disableAnimation` prop to a DOM element

* refactor(avatar): use filterDOMProps approach

* chore(avatar): remove to type import

* chore(avatar): change to shouldFilterDOMProps
  • Loading branch information
wingkwong authored May 31, 2024
1 parent 685995a commit cdbc651
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 6 deletions.
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";

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

0 comments on commit cdbc651

Please sign in to comment.