File tree Expand file tree Collapse file tree 2 files changed +13
-16
lines changed Expand file tree Collapse file tree 2 files changed +13
-16
lines changed Original file line number Diff line number Diff line change @@ -33,15 +33,19 @@ describe('ClickAway Listener', () => {
33
33
const fakeHandleClick2 = jest . fn ( ) ;
34
34
const { getByTestId } = render (
35
35
< React . Fragment >
36
- < ClickAwayListener onClickAway = { fakeHandleClick } data-testid = "hello-world" >
37
- Hello World
36
+ < ClickAwayListener onClickAway = { fakeHandleClick } >
37
+ < div data-testid = "hello-world" >
38
+ Hello World
39
+ </ div >
38
40
</ ClickAwayListener >
39
41
< button data-testid = "button-one" > A button</ button >
40
42
< button data-testid = "some-other-button-one" > Some other button</ button >
41
43
< p data-testid = "text-one" > A text element</ p >
42
44
43
- < ClickAwayListener onClickAway = { fakeHandleClick2 } data-testid = "foo-bar" >
44
- Foo bar
45
+ < ClickAwayListener onClickAway = { fakeHandleClick2 } >
46
+ < div data-testid = "foo-bar" >
47
+ Foo bar
48
+ </ div >
45
49
</ ClickAwayListener >
46
50
< button data-testid = "button-two" > Foo bar button</ button >
47
51
< button data-testid = "some-other-button-two" > Foo bar other button</ button >
Original file line number Diff line number Diff line change 1
- import React , { useEffect , useRef } from 'react' ;
1
+ import React , { useEffect , useRef , FunctionComponent } from 'react' ;
2
2
3
3
interface Props {
4
- children ?: React . ReactNode ;
5
4
onClickAway : Function ;
6
- childrenProps ?: { [ key : string ] : any } [ ] ;
7
5
}
8
6
9
- const ClickAwayListener = ( props : Props ) => {
10
- const {
11
- children,
12
- onClickAway,
13
- ...childrenProps
14
- } = props ;
7
+ const ClickAwayListener : FunctionComponent < Props > = ( { onClickAway, children } ) => {
15
8
16
9
let node = useRef < HTMLDivElement > ( null ) ;
17
10
18
11
useEffect ( ( ) => {
19
- const handleMouseDown = ( event :any ) => {
20
- if ( node . current && node . current . contains ( event . target ) ) {
12
+ const handleMouseDown = ( event : MouseEvent ) : void => {
13
+ if ( node . current && node . current . contains ( event . target as Node ) ) {
21
14
return ;
22
15
}
23
16
@@ -32,7 +25,7 @@ const ClickAwayListener = (props: Props) => {
32
25
} ) ;
33
26
34
27
return (
35
- < div ref = { node } { ... childrenProps } >
28
+ < div ref = { node } >
36
29
{ children }
37
30
</ div >
38
31
) ;
You can’t perform that action at this time.
0 commit comments