class Dialog extends Component {
constructor() {
super(...arguments);
this.clickEventHandler = this.clickEventHandler.bind(this);
}
content() {
return (
<div className="dialogContent">
<button onClick={this.clickEventHandler.bind(this)}>
Button 1 (pure JS)
</button>{" "}
</div>
);
}
clickEventHandler() {
console.log("clickEventHandler called");
}
render() {
return (
<div className="control-pane">
<div className="control-section" id="rteTools">
<div className="rte-control-section" />
<DialogComponent
visible={true}
showCloseIcon={true}
width="70%"
header="Dialog Header"
height="200px"
allowDragging={true}
content={this.content.bind(this)}
/>
</div>
</div>
);
}
} |
This problem is caused by changes in event delegation(React 17) - https://reactjs.org/blog/2020/10/20/react-v17.html#changes-to-event-delegation
I solved this with Portals(https://reactjs.org/docs/portals.html) i.e.
const ModalPortal = props => {
const modalRoot = document.createElement('div');
modalRoot.setAttribute('uk-modal', 'bg-close: false');
modalRoot.id = 'modal-save';
useEffect(() => {
document.body.appendChild(modalRoot);
return () => {
document.body.removeChild(modalRoot);
}
});
return ReactDOM.createPortal(props.children, modalRoot);
}
export default ModalPortal;
Then you should wrap modal content in the parent element (React Course Button)
<ModalPortal>
// modal body
<span onClick={() => console.log('test')}>Test</span>
</ModalPortal>