@@ -4,7 +4,7 @@ import React from 'react'
4
4
import { Text , View } from '@tarojs/components'
5
5
import { CommonEvent } from '@tarojs/components/types/common'
6
6
import { AtAccordionProps , AtAccordionState } from '../../../types/accordion'
7
- import { delayQuerySelector } from '../../common/utils'
7
+ import { delayQuerySelector , uuid } from '../../common/utils'
8
8
9
9
export default class AtAccordion extends React . Component <
10
10
AtAccordionProps ,
@@ -21,6 +21,7 @@ export default class AtAccordion extends React.Component<
21
21
this . isCompleted = true
22
22
this . startOpen = false
23
23
this . state = {
24
+ componentId : uuid ( ) ,
24
25
wrapperHeight : 0
25
26
}
26
27
}
@@ -34,10 +35,12 @@ export default class AtAccordion extends React.Component<
34
35
35
36
private toggleWithAnimation ( ) : void {
36
37
const { open, isAnimation } = this . props
38
+ const { componentId } = this . state
37
39
if ( ! this . isCompleted || ! isAnimation ) return
38
40
39
41
this . isCompleted = false
40
- delayQuerySelector ( '.at-accordion__body' , 0 ) . then ( rect => {
42
+
43
+ delayQuerySelector ( `#at-accordion__body-${ componentId } ` , 0 ) . then ( rect => {
41
44
const height = parseInt ( rect [ 0 ] . height . toString ( ) )
42
45
const startHeight = open ? height : 0
43
46
const endHeight = open ? 0 : height
@@ -73,15 +76,8 @@ export default class AtAccordion extends React.Component<
73
76
}
74
77
75
78
public render ( ) : JSX . Element {
76
- const {
77
- customStyle,
78
- className,
79
- title,
80
- icon,
81
- hasBorder,
82
- open,
83
- note
84
- } = this . props
79
+ const { customStyle, className, title, icon, hasBorder, open, note } =
80
+ this . props
85
81
const { wrapperHeight } = this . state
86
82
87
83
const rootCls = classNames ( 'at-accordion' , className )
@@ -111,6 +107,8 @@ export default class AtAccordion extends React.Component<
111
107
contentStyle . height = ''
112
108
}
113
109
110
+ const { componentId } = this . state
111
+
114
112
return (
115
113
< View className = { rootCls } style = { customStyle } >
116
114
< View className = { headerCls } onClick = { this . handleClick } >
@@ -126,7 +124,12 @@ export default class AtAccordion extends React.Component<
126
124
</ View >
127
125
</ View >
128
126
< View style = { contentStyle } className = { contentCls } >
129
- < View className = 'at-accordion__body' > { this . props . children } </ View >
127
+ < View
128
+ id = { `at-accordion__body-${ componentId } ` }
129
+ className = 'at-accordion__body'
130
+ >
131
+ { this . props . children }
132
+ </ View >
130
133
</ View >
131
134
</ View >
132
135
)
0 commit comments