Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Button in a ListItem with button=true #11231

Closed
1 task done
phbernard opened this issue May 4, 2018 · 3 comments
Closed
1 task done

Button in a ListItem with button=true #11231

phbernard opened this issue May 4, 2018 · 3 comments
Labels
status: waiting for author Issue with insufficient information

Comments

@phbernard
Copy link

  • I have searched the issues of this repository and believe that this is not a duplicate.

Expected Behavior

When a ListItem has its button attribute set to true, it shows no highlighting, which is normal:

default

When the mouse cursor is dragged on the ListItem, the later is highlighted, as expected:

over

When the mouse cursor is on a Button embedded in the ListItem, I would expect the button to be highligthed, but not the ListItem, as follow:

expected

Current Behavior

Instead, both components are highlighted:

observed

In addition, when clicking the Button, a wave effect is triggered on the ListItem, giving the impression that the ListItem was clicked:

click

Although that can be true (both components can receive and process the click event), stopPropagation() will probably be used in the Button handler to prevent the click from being processed two times. Thus, the UI feedback is not accurate in this scenario.

Steps to Reproduce (for bugs)

  1. Go to https://codesandbox.io/s/wy6kvr7827
  2. Open the DevTools of your browser (to see the console, because this example is using console.log)
  3. Click the "Click here" button. You notice that only the Button handler is triggered, thanks to stopPropagation(). Yet, the wave effect is applied to the ListItem.

Context

This behavior can send the wrong signal to the user, making him believe that "two" clicks happen when he clicks a button in a list item.

Two approaches to improve the situation:

  • Do not display the wave effect on click on an embedded button (but keep the highlighting of the ListItem when the mouse cursor is on the embedded button)
  • Display neither the wave effect nor the highlighting when the mouse cursor is on the embedded button.

Your Environment

Tech Version
Material-UI 1.0.0-beta.43
React 15.6.2
browser Chrome and FF
etc
@oliviertassinari
Copy link
Member

@phbernard Do you have a reproduction example? At first sight, the root of the issue comes from your example nesting two buttons, it's an invalid HTML5 structure, to be verified.

@phbernard
Copy link
Author

The example is https://codesandbox.io/s/wy6kvr7827

Hum... I get your point. You are right, as mentioned in the docs, a ListItem with button to true becomes a ButtonBase. As the ListItem is technically a button, it doesn't make much sense to embed another button in it.

Now I need to figure out how I want to implement the behavior I have in mind without resorting to the button property.

Thanks for the tip and sorry for bothering!

@oliviertassinari
Copy link
Member

oliviertassinari commented May 4, 2018

Maybe you can use the ListItemSecondaryAction component. We have a demo demonstrating the usage of two buttons withing the same item.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: waiting for author Issue with insufficient information
Projects
None yet
Development

No branches or pull requests

2 participants