Dialog doesn't work well with Table/TableRow
See original GitHub issueI add a onClick
event to TableRow
component, when user clicks the row, it should highlight the selected row and show a button. User can click the button and open a modal to fill a form. But when user clicks the textfield in the dialog, the onClick
event get triggered which closes the dialog.
- This is not a v0.x issue.
- I have searched the issues of this repository and believe that this is not a duplicate.
Expected Behavior 🤔
Dialog should keep open when textfield is focused.
Current Behavior 😯
When textfield in the dialog is focused, dialog is closed.
Steps to Reproduce 🕹
Link: https://codesandbox.io/s/5vwyjr35pl
- click the first row
- click
open
- click TextField in the dialog
Your Environment 🌎
Tech | Version |
---|---|
Material-UI | v3.9.3 |
React | v16.8.6 |
Browser | Chrome 74.0.3729.131 |
Issue Analytics
- State:
- Created 4 years ago
- Comments:7 (4 by maintainers)
Top Results From Across the Web
Dialog doesn't work well with Table/TableRow #15705 - GitHub
I add a onClick event to TableRow component, when user clicks the row, it should highlight the selected row and show a button....
Read more >pushing the specific table row data to a dialog in reactJS
I'm getting TypeError: Cannot read property 'name' of undefined error. Will this work with the dialog inside or outside of the loop? ·...
Read more >Netscape Composer: Formatting with Tables
Using the Row tab in the Table Properties dialog box, you can make settings ... "Cell spans" feature does not work properly, so...
Read more >conditional style in the template - TinyButStrong
Hi Gior, It's possible to manage conditional styles in OpenOffice / LibreOffice Workbooks. OpenOffice/LibreOffice Calc workbooks manage both ...
Read more >print - DataTables
The constructed table does not retain the full information from the original table (table row and cell classes are not copied across for...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
The problem is that any click in the dialog bubbles up to the TableRow in which it toggles it’s highlighted state. When it’s not highlighted the Dialog unmounts as well.
It’s a common pitfall in React to assume events bubble up according to the DOM but they actually bubble through portals. See facebook/react#11387 for the relevant discussion about this. The simplest workaround is to not toggle. A better workaround would be to either refactor your component tree or stop propagation of click events in your Dialog.
@eps1lon Wow, I always thought that the event wasn’t bubbling in the Portal. I have learned something 😃.
@Michaeltym In this case, I would probably mount a single Dialog outside the Table, or filter the wrong events: