@@ -44,11 +44,7 @@ const PopoverGroup = () => {
4444 < >
4545 < div ref = { groupRef } >
4646 < Popover content = { SimpleContent } groupedPopoversRef = { groupRef } >
47- { ( onClick , ref , className ) => (
48- < a onClick = { onClick } ref = { ref } className = { className } >
49- Instant Click
50- </ a >
51- ) }
47+ < a > Instant Click</ a >
5248 </ Popover >
5349
5450 < a onClick = { instantClick } id = "instant" >
@@ -73,11 +69,57 @@ describe('Popover', () => {
7369 }
7470 } )
7571
76- test ( 'opens and closes' , ( ) => {
72+ test ( 'renderProps style opens and closes' , ( ) => {
7773 const { getByText, queryByText } = renderWithTheme (
7874 < Popover content = { SimpleContent } >
79- { ( onClick , ref , className ) => (
80- < button ref = { ref } onClick = { onClick } className = { className } >
75+ { ( popoverProps ) => < button { ...popoverProps } > Test</ button > }
76+ </ Popover >
77+ )
78+
79+ // Verify hidden
80+ expect ( queryByText ( 'simple content' ) ) . not . toBeInTheDocument ( )
81+
82+ const trigger = getByText ( 'Test' )
83+ fireEvent . click ( trigger )
84+
85+ // Find content
86+ expect ( getByText ( 'simple content' ) ) . toBeInTheDocument ( )
87+
88+ fireEvent . click ( trigger )
89+ expect ( queryByText ( 'simple content' ) ) . not . toBeInTheDocument ( )
90+ } )
91+
92+ test ( 'cloneElement style opens and closes' , ( ) => {
93+ const { getByText, queryByText } = renderWithTheme (
94+ < Popover content = { SimpleContent } >
95+ < button > Test</ button >
96+ </ Popover >
97+ )
98+
99+ // Verify hidden
100+ expect ( queryByText ( 'simple content' ) ) . not . toBeInTheDocument ( )
101+
102+ const trigger = getByText ( 'Test' )
103+ fireEvent . click ( trigger )
104+
105+ // Find content
106+ expect ( getByText ( 'simple content' ) ) . toBeInTheDocument ( )
107+
108+ fireEvent . click ( trigger )
109+ expect ( queryByText ( 'simple content' ) ) . not . toBeInTheDocument ( )
110+ } )
111+
112+ test ( 'renderProps style expanded opens and closes' , ( ) => {
113+ const { getByText, queryByText } = renderWithTheme (
114+ < Popover content = { SimpleContent } >
115+ { ( { className, onClick, ref, ...props } ) => (
116+ < button
117+ aria-expanded = { props [ 'aria-expanded' ] }
118+ aria-haspopup = { props [ 'aria-haspopup' ] }
119+ className = { className }
120+ onClick = { onClick }
121+ ref = { ref }
122+ >
81123 Test
82124 </ button >
83125 ) }
@@ -97,17 +139,33 @@ describe('Popover', () => {
97139 expect ( queryByText ( 'simple content' ) ) . not . toBeInTheDocument ( )
98140 } )
99141
142+ test ( 'cloneElement style opens and closes' , ( ) => {
143+ const { getByText, queryByText } = renderWithTheme (
144+ < Popover content = { SimpleContent } >
145+ < button > Test</ button >
146+ </ Popover >
147+ )
148+
149+ // Verify hidden
150+ expect ( queryByText ( 'simple content' ) ) . not . toBeInTheDocument ( )
151+
152+ const trigger = getByText ( 'Test' )
153+ fireEvent . click ( trigger )
154+
155+ // Find content
156+ expect ( getByText ( 'simple content' ) ) . toBeInTheDocument ( )
157+
158+ fireEvent . click ( trigger )
159+ expect ( queryByText ( 'simple content' ) ) . not . toBeInTheDocument ( )
160+ } )
161+
100162 test ( 'stopPropagation works - event on container is not called' , ( ) => {
101163 const mockContainerOnClick = jest . fn ( )
102164
103165 const { getByText } = renderWithTheme (
104166 < div onClick = { mockContainerOnClick } >
105167 < Popover content = { SimpleContent } >
106- { ( onClick , ref , className ) => (
107- < button ref = { ref } onClick = { onClick } className = { className } >
108- Test
109- </ button >
110- ) }
168+ < button > Test</ button >
111169 </ Popover >
112170 </ div >
113171 )
@@ -125,11 +183,7 @@ describe('Popover', () => {
125183 const { getByText, queryByText } = renderWithTheme (
126184 < >
127185 < Popover content = { SimpleContent } >
128- { ( onClick , ref , className ) => (
129- < button onClick = { onClick } ref = { ref } className = { className } >
130- Instant Click
131- </ button >
132- ) }
186+ < button > Instant Click</ button >
133187 </ Popover >
134188 < a onClick = { doThing } > Do thing...</ a >
135189 </ >
@@ -179,11 +233,7 @@ describe('Popover', () => {
179233 return (
180234 < div ref = { hoverRef } >
181235 < Popover content = { SimpleContent } hoverDisclosureRef = { hoverRef } >
182- { ( onClick , ref , className ) => (
183- < Button onClick = { onClick } ref = { ref } className = { className } >
184- Instant Click
185- </ Button >
186- ) }
236+ < Button > Instant Click</ Button >
187237 </ Popover >
188238 Some text in the div
189239 </ div >
0 commit comments