Skip to content

Commit

Permalink
fix(Avatar): 解决在小程序环境下,使用Avatar.Group无法正常展示头像问题 (#1296)
Browse files Browse the repository at this point in the history
  • Loading branch information
TralafalgarV authored Aug 10, 2023
1 parent 69ee6b4 commit c7fa080
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions src/packages/avatar/avatar.taro.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import React, {
useContext,
} from 'react'
import type { MouseEvent } from 'react'
import Taro, { getEnv } from '@tarojs/taro'
import classNames from 'classnames'
import { My } from '@nutui/icons-react-taro'
import Image from '@/packages/image/index.taro'
Expand Down Expand Up @@ -105,13 +106,26 @@ export const Avatar: FunctionComponent<
}
}, [])

const isAvatarInClassList = (element: any) => {
if (getEnv() === Taro.ENV_TYPE.WEB) {
return (
element.classList[0] === 'nut-avatar' ||
element.classList.values().next().value === 'nut-avatar'
)
}

return (
element.classList?.tokenList[0] === 'nut-avatar' ||
element.classList?.tokenList.values().next().value === 'nut-avatar'
)
}

const avatarLength = (children: any) => {
for (let i = 0; i < children.length; i++) {
if (
children[i] &&
children[i].classList &&
(children[i].classList[0] === 'nut-avatar' ||
children[i].classList.values().next().value === 'nut-avatar')
isAvatarInClassList(children[i])
) {
children[i].setAttribute('data-index', i + 1)
}
Expand Down

0 comments on commit c7fa080

Please sign in to comment.