Skip to content

Commit

Permalink
feat(elevator): 采用唯一ID,避免未传入 className 导致的报错 (#2834)
Browse files Browse the repository at this point in the history
  • Loading branch information
oasis-cloud authored Dec 5, 2024
1 parent 161733d commit d8ab65e
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions src/packages/elevator/elevator.taro.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
import React, {
createContext,
FunctionComponent,
useRef,
useEffect,
useRef,
useState,
createContext,
} from 'react'
import Taro, { nextTick, createSelectorQuery } from '@tarojs/taro'
import Taro, { createSelectorQuery, nextTick } from '@tarojs/taro'

import { ScrollView } from '@tarojs/components'
import classNames from 'classnames'
import { BasicComponent, ComponentDefaults } from '@/utils/typings'
import useUuid from '@/utils/use-uuid'

export const elevatorContext = createContext({} as ElevatorData)

Expand Down Expand Up @@ -65,6 +66,7 @@ export const Elevator: FunctionComponent<
...defaultProps,
...props,
}
const uuid = useUuid()
const classPrefix = 'nut-elevator'
const listview = useRef<HTMLDivElement>(null)
const initData = {
Expand Down Expand Up @@ -106,7 +108,7 @@ export const Elevator: FunctionComponent<
for (let i = 0; i < state.current.listGroup.length; i++) {
const query = createSelectorQuery()
query
.selectAll(`.${className} .nut-elevator-item-${i}`)
.selectAll(`.${classPrefix}-${uuid} .nut-elevator-item-${i}`)
.boundingClientRect()
// eslint-disable-next-line no-loop-func
query.exec((res: any) => {
Expand Down Expand Up @@ -180,7 +182,7 @@ export const Elevator: FunctionComponent<
const setListGroup = () => {
if (listview.current) {
createSelectorQuery()
.selectAll(`.${className} .nut-elevator-list-item`)
.selectAll(`.${classPrefix}-${uuid} .nut-elevator-list-item`)
.node((el) => {
state.current.listGroup = [...Object.keys(el)]
calculateHeight()
Expand Down Expand Up @@ -220,7 +222,11 @@ export const Elevator: FunctionComponent<
}, [listview])

return (
<div className={`${classPrefix} ${className}`} style={style} {...rest}>
<div
className={`${classPrefix} ${className} ${classPrefix}-${uuid}`}
style={style}
{...rest}
>
<div
className={`${classPrefix}-list`}
style={{ height: Number.isNaN(+height) ? height : `${height}px` }}
Expand Down

0 comments on commit d8ab65e

Please sign in to comment.