| 199 | } |
| 200 | |
| 201 | function Inner() { |
| 202 | let [show, setShow] = useState(true); |
| 203 | return show ? <button onClick={() => setShow(false)}>hide</button> : null; |
| 204 | } |
| 205 | |
| 206 | let events = []; |
| 207 | let addEvent = e => events.push({type: e.type, target: e.target}); |
| 208 | let tree = render( |
| 209 | <> |
| 210 | <Test |
| 211 | onFocusWithin={addEvent} |
| 212 | onBlurWithin={addEvent} |
| 213 | onFocusWithinChange={isFocused => events.push({type: 'focuschange', isFocused})}> |
| 214 | <Inner /> |
| 215 | </Test> |
| 216 | <input data-testid="outer" /> |
| 217 | </> |
| 218 | ); |
| 219 | |
| 220 | let el = tree.getByRole('button'); |
| 221 | act(() => el.focus()); |
| 222 | act(() => el.click()); |
| 223 | act(() => tree.getByTestId('outer').focus()); |
| 224 | |
| 225 | expect(events).toEqual([ |
| 226 | {type: 'focus', target: el}, |
| 227 | {type: 'focuschange', isFocused: true}, |
| 228 | {type: 'blur', target: tree.getByTestId('test')}, |
| 229 | {type: 'focuschange', isFocused: false} |
| 230 | ]); |
| 231 | }); |
| 232 | }); |