MCPcopy
hub / github.com/Pomax/react-onclickoutside / onClickOutside

Class onClickOutside

src/index.js:38–234  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

36export default function onClickOutsideHOC(WrappedComponent, config) {
37 const componentName = WrappedComponent.displayName || WrappedComponent.name || 'Component';
38 return class onClickOutside extends Component {
39 static displayName = `OnClickOutside(${componentName})`;
40
41 static defaultProps = {
42 eventTypes: ['mousedown', 'touchstart'],
43 excludeScrollbar: (config && config.excludeScrollbar) || false,
44 outsideClickIgnoreClass: IGNORE_CLASS_NAME,
45 preventDefault: false,
46 stopPropagation: false,
47 };
48
49 static getClass = () => (WrappedComponent.getClass ? WrappedComponent.getClass() : WrappedComponent);
50
51 constructor(props) {
52 super(props);
53 this._uid = uid();
54 this.initTimeStamp = performance.now();
55 }
56
57 /**
58 * Access the WrappedComponent's instance.
59 */
60 getInstance() {
61 if (WrappedComponent.prototype && !WrappedComponent.prototype.isReactComponent) {
62 return this;
63 }
64 const ref = this.instanceRef;
65 return ref.getInstance ? ref.getInstance() : ref;
66 }
67
68 __outsideClickHandler = event => {
69 if (typeof this.__clickOutsideHandlerProp === 'function') {
70 this.__clickOutsideHandlerProp(event);
71 return;
72 }
73
74 const instance = this.getInstance();
75
76 if (typeof instance.props.handleClickOutside === 'function') {
77 instance.props.handleClickOutside(event);
78 return;
79 }
80
81 if (typeof instance.handleClickOutside === 'function') {
82 instance.handleClickOutside(event);
83 return;
84 }
85
86 throw new Error(
87 `WrappedComponent: ${componentName} lacks a handleClickOutside(event) function for processing outside click events.`,
88 );
89 };
90
91 __getComponentNode = () => {
92 const instance = this.getInstance();
93
94 if (config && typeof config.setClickOutsideRef === 'function') {
95 return config.setClickOutsideRef()(instance);

Callers 3

test3.jsFile · 0.85
test2.jsFile · 0.85
test1.jsFile · 0.85

Calls 5

getInstanceMethod · 0.95
testPassiveEventSupportFunction · 0.90
getEventHandlerOptionsFunction · 0.85
setClickOutsideRefMethod · 0.80
handleClickOutsideMethod · 0.45

Tested by

no test coverage detected