1- import React , { useState } from 'react' ;
1+ import React , { useState , useRef } from 'react' ;
22import PropTypes from 'prop-types' ;
3- import onClickOutside from 'react-onclickoutside' ;
43import { IconDots , Button , LinkButton } from '.' ;
4+ import { useOnClickOutside } from '../hooks' ;
55
66const propTypes = {
77 handleDelete : PropTypes . func . isRequired ,
@@ -23,19 +23,23 @@ export function MoreDetails({
2323 itemId,
2424} ) {
2525 const [ menuShown , setmenuShown ] = useState ( false ) ;
26-
27- MoreDetails . handleClickOutside = ( ) => setmenuShown ( false ) ;
26+ const refToButton = useRef ( ) ;
27+ const refToMenu = useOnClickOutside ( {
28+ callback : ( ) => setmenuShown ( false ) ,
29+ ignoreRef : refToButton ,
30+ } ) ;
2831
2932 return (
3033 < div className = "more-details" >
3134 < button
35+ ref = { refToButton }
3236 className = "more-details__icon"
3337 onClick = { ( ) => setmenuShown ( current => ! current ) }
3438 >
3539 < IconDots />
3640 </ button >
3741 { menuShown && (
38- < div className = "more-details__button-group" >
42+ < div className = "more-details__button-group" ref = { refToMenu } >
3943 { setBadStateShown && (
4044 < Button
4145 altClasses = "more-details_button"
@@ -66,8 +70,4 @@ export function MoreDetails({
6670MoreDetails . propTypes = propTypes ;
6771MoreDetails . defaultProps = defaultProps ;
6872
69- const clickOutsideConfig = {
70- handleClickOutside : ( ) => MoreDetails . handleClickOutside ,
71- } ;
72-
73- export default onClickOutside ( MoreDetails , clickOutsideConfig ) ;
73+ export default MoreDetails ;
0 commit comments