Pomax / react-onclickoutside

An onClickOutside wrapper for React components
MIT License
1.83k stars 187 forks source link

Unable to reach wrapped component props? #338

Closed Maubas closed 4 years ago

Maubas commented 4 years ago

I've created a popover component that has been wrapped in a controller. The outside click is being found as expected, but does not run the function within the handler.

class Popover extends Component {
    constructor(props) {
        super(props);
    }

    handleClick = () => {
        this.props.onClick();
    }

    handleClickOutside = () => {
        console.log('You clicked outside!');
        this.props.onCloseClick();
    }

    render() {
        return (
            <div
                className={containerStyles}
                onClick={this.handleClick}
                ref={elem => this.elem = elem}
            >
                <div className={wrapperStyles}>
                    { this.props.children }
                </div>
            </div>
        );
    }
}

const clickOutsideConfig = {
    handleClickOutside: function(instance) {
        return instance.handleClickOutside;
    }
};

const OnClickOutsideWrappedPopover = onClickOutside(Popover, clickOutsideConfig);

class Controller extends Component {
    constructor(props) {
        super(props);
    }

    render() {
        return <OnClickOutsideWrappedPopover {...this.props} />;
    }
}

export default Controller;

The console statement in handleClickOutside() is logged, however, the function does not get run. I've confirmed that the function does work standalone, so I'm unsure if my wrapping is improper. An interesting note is that the behavior is the same, even when calling the Popover component without the controller. Any help would be greatly appreciated!

Versions:

Maubas commented 4 years ago

Turns out, this was due a bad merge causing a mismatch in the package-lock file.