question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Dialog doesn't work well with Table/TableRow

See original GitHub issue

I 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

  1. click the first row
  2. click open
  3. 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:closed
  • Created 4 years ago
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

3reactions
eps1loncommented, May 15, 2019

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.

1reaction
oliviertassinaricommented, May 15, 2019

@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:

const contains = event.currentTarget.contains(event.target);
Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found