File tree Expand file tree Collapse file tree 2 files changed +7
-4
lines changed Expand file tree Collapse file tree 2 files changed +7
-4
lines changed Original file line number Diff line number Diff line change @@ -43,7 +43,7 @@ export default class App extends Component <{}, AppState> {
43
43
< GHCorner openInNewTab href = { repoUrl } />
44
44
< button > outside</ button >
45
45
outside
46
-
46
+ < button onClick = { ( ) => alert ( 'ok' ) } > test outside event </ button >
47
47
< button onClick = { toggle } ref = { this . toggleRef } > toggle drop</ button >
48
48
< button onClick = { toggle } > toggle drop 2</ button >
49
49
{ on && < div style = { { backgroundColor : '#EEE' } } >
@@ -54,6 +54,8 @@ export default class App extends Component <{}, AppState> {
54
54
shards = { [ this . toggleRef , this . scrollRef ] }
55
55
>
56
56
Holala!!
57
+ < button onClick = { ( ) => alert ( 'ok' ) } > test inside event</ button >
58
+ < a href = "http://github.com" > link</ a >
57
59
< button onClick = { toggle } > close</ button >
58
60
< ScrollBox > innerbox</ ScrollBox >
59
61
</ FocusOn >
Original file line number Diff line number Diff line change @@ -28,9 +28,10 @@ const extractRef = (ref: React.RefObject<any> | HTMLElement): HTMLElement => (
28
28
29
29
export class ReactFocusOn extends Component < ReactFocusOnProps > {
30
30
private _undo ?: ( ) => void ;
31
+ private lastEventTarget ?: EventTarget ;
31
32
32
33
private lockProps = {
33
- onClick : ( e : React . MouseEvent ) => e . preventDefault ( ) ,
34
+ onClick : ( e : React . MouseEvent ) => this . lastEventTarget = e . target
34
35
} ;
35
36
36
37
private onActivation = ( node : HTMLElement ) => {
@@ -47,7 +48,7 @@ export class ReactFocusOn extends Component<ReactFocusOnProps> {
47
48
document . addEventListener ( 'click' , this . onClick ) ;
48
49
} ;
49
50
50
- private onDeactivation = ( node : HTMLElement ) => {
51
+ private onDeactivation = ( ) => {
51
52
this . _undo ! ( ) ;
52
53
const { onDeactivation} = this . props ;
53
54
if ( onDeactivation ) {
@@ -69,7 +70,7 @@ export class ReactFocusOn extends Component<ReactFocusOnProps> {
69
70
70
71
private onClick = ( event : MouseEvent ) => {
71
72
const { shards = [ ] , onClickOutside} = this . props ;
72
- if ( event . defaultPrevented ) {
73
+ if ( event . defaultPrevented || event . target === this . lastEventTarget ) {
73
74
return ;
74
75
}
75
76
if (
You can’t perform that action at this time.
0 commit comments