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(elevator): 采用唯一ID,避免未传入 className 导致的报错 #2834

Merged
merged 1 commit into from
Dec 5, 2024
Merged
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
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
Loading