- Home
- Forum
- React - EJ 2
- Button component (onclick event) in dialog doesn't work in react v17
Button component (onclick event) in dialog doesn't work in react v17
Hi, the button (onclick event) inside the dialog component doesn't work in react and react-dom v17, but when I downgraded to react v16, it worked. Do you know how to fix it so it can works in react v17? Thank you.
SIGN IN To post a reply.
13 Replies
1 reply marked as answer
KR
Keerthana Rajendran
Syncfusion Team
April 30, 2021 10:26 AM UTC
Hi Deysi,
Thanks for contacting Syncfusion support.
Before we proceed further with your query, we would like to confirm whether the reported issue occurs with EJ1 or EJ2 React components.
Please share us the following details to assist you promptly.
- Exact Syncfusion version in which you get the reported issue.
- Complete code block of Syncfusion component used in your application.
- If possible, share us a simple issue replicating sample.
Regards,
Keerthana.
DF
Deysi Fortuna
May 3, 2021 02:02 AM UTC
Hi, sorry for the late reply. I use syncfusion v19, and react v17 
and this is my code
import { TextBoxComponent } from "@syncfusion/ej2-react-inputs";
import { DialogComponent } from "@syncfusion/ej2-react-popups";
import { ButtonComponent } from "@syncfusion/ej2-react-buttons";
import * as React from "react";
function App() {
return (
<div className="control-pane">
<DialogComponent
// ref={dialog => (this.dialogInstance = dialog)}
visible={true}
// close={this.dialogClose}
showCloseIcon={true}
isModal={true}
width="70%"
header="Dialog with Button"
height="200px"
>
<div>
<ButtonComponent
id="btn"
content="Button"
onClick={()=>alert("test")}
/>
</div>
</DialogComponent>
</div>
);
}
export default App;
The button component doesn't work inside the dialog component. But if I change the react version to 16.9.0, it works. Thank you.
RK
Revanth Krishnan
Syncfusion Team
May 3, 2021 09:16 AM UTC
Hi Deysi,
Greetings from Syncfusion support.
We have validated your query “Button component’s onclick doesn’t work when rendered inside the Dialog in the react version v17”
The above issue can be resolved by rendering the content using the ‘content’ property of the Dialog. We have prepared a sample for your reference,
Code Snippet:
|
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>
);
}
} |
Please check the above code snippet and the sample and let us know if it resolves your issue.
Regards,
Revanth
DF
Deysi Fortuna
May 4, 2021 05:01 AM UTC
Hi, thanks for your reply.

I used the content and got this error.
I got the same problem with this thread https://www.syncfusion.com/forums/165068/click-event-is-not-triggered-on-dialog
Thank you.
AM
Amos
May 4, 2021 07:34 AM UTC
Following this thread too as it is similar to mine.
Syncfusion support: you can merge the 2 threads if you want so you won't need to duplicate your work and effort.
RK
Revanth Krishnan
Syncfusion Team
May 4, 2021 01:08 PM UTC
Hi Deysi,
We are currently validating your query, we will update you with further details on or before 7th May.
We appreciate your patience till then.
Regards,
Revanth
DF
Deysi Fortuna
May 5, 2021 01:52 AM UTC
Hi.
Ok. Thanks for your reply.
Ok. Thanks for your reply.
DF
Deysi Fortuna
May 5, 2021 02:38 AM UTC
Hi.
I use the useState in React Hook but it renders the dialog component first before return a state value and got that error. Maybe the problem is the order in which React components are rendered first.
RK
Revanth Krishnan
Syncfusion Team
May 5, 2021 02:47 PM UTC
Hi Deysi,
As mentioned earlier we will check and update you with further details on or before 7th May.
Meanwhile can you please try to render the dialog component after the state value is returned by using a condition.
Regards,
Revanth
MA
Maxwell
May 6, 2021 02:02 PM UTC
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>
Marked as answer
RK
Revanth Krishnan
Syncfusion Team
May 7, 2021 10:23 AM UTC
Hi Maxell,
Thanks for the update.
We are glad that you found solution for the click event using portals.
Regards,
Revanth
RK
Revanth Krishnan
Syncfusion Team
May 7, 2021 10:24 AM UTC
Hi Deysi,
Good day to you.
We have further validated your query and we have considered “When the content is given as a template function, then the content is not rendered in the Dialog” as a bug from our end and logged the report for the same and it will be included in the coming 2021 Volume 1 SP release which is scheduled to be released by the mid of May.
You can now track the current status of the report, review the proposed resolution timeline, and contact us for any further inquiries through this link: https://www.syncfusion.com/feedback/25059
Regards,
Revanth
RK
Revanth Krishnan
Syncfusion Team
May 17, 2021 02:23 PM UTC
Hi Deysi,
Thanks for the patience.
We have included the fix for “When the content is given as a template function, then the content is not rendered in the Dialog” with the package version 19.1.63.
Can you please upgrade your package to this version to resolve the issue on your end?
Release Note: https://ej2.syncfusion.com/angular/documentation/release-notes/19.1.63/?type=all#dialog
Regards,
Revanth
SIGN IN To post a reply.
- 13 Replies
- 5 Participants
- Marked answer
-
DF Deysi Fortuna
- Apr 30, 2021 03:24 AM UTC
- May 17, 2021 02:23 PM UTC