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.

[ListItemSecondaryAction] visibility on hover

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

Expected Behavior

ListItemSecondaryAction should be able to be hidden by default, then visible on hover. This is a really common use case, so if possible, we should consider a clean way to make this (optional) behavior available behind a boolean property.

Current Behavior

When implemented with css sibling selectors and hovering over the secondary action, the icon blinks continuously. When hovered anywhere else on the ListItem, the blinking stops and works as expected.

blink2

Steps to Reproduce (for bugs)

Using css sibling selector (shown above): https://codesandbox.io/s/xo0mmyv2oo

Context

Secondary actions visible for larger lists (e.g. Google contacts list) can be overwhelming. Hiding icons until hovered is a common way to declutter user interfaces.

Your Environment

Tech Version
Material-UI 1.0.0-beta.33
React 16.2.0
browser Chrome

Any guidance @oliviertassinari @kof as to what the root cause of blinking?

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:5 (5 by maintainers)

github_iconTop GitHub Comments

8reactions
oliviertassinaricommented, Feb 13, 2018
import React from "react";
import PropTypes from "prop-types";
import { withStyles } from "material-ui/styles";
import List, {
  ListItem,
  ListItemSecondaryAction,
  ListItemText
} from "material-ui/List";
import Checkbox from "material-ui/Checkbox";
import IconButton from "material-ui/IconButton";
import CommentIcon from "material-ui-icons/Comment";

const styles = theme => ({
  root: {
    width: "100%",
    maxWidth: 360,
    backgroundColor: theme.palette.background.paper
  },
  listItemSecondaryAction: {
    visibility: "hidden"
  },
  listItem: {
    border: "1px solid blue",
-   "&:hover ~ $listItemSecondaryAction": {
+   "&:hover $listItemSecondaryAction": {
      border: "1px solid green",
      visibility: "inherit"
    }
  }
});

class CheckboxList extends React.Component {
  state = {
    checked: [0]
  };

  handleToggle = value => () => {
    const { checked } = this.state;
    const currentIndex = checked.indexOf(value);
    const newChecked = [...checked];

    if (currentIndex === -1) {
      newChecked.push(value);
    } else {
      newChecked.splice(currentIndex, 1);
    }

    this.setState({
      checked: newChecked
    });
  };

  render() {
    const { classes } = this.props;

    return (
      <div className={classes.root}>
        <List>
          {[0, 1, 2, 3].map(value => (
            <ListItem
              key={value}
              dense
              button
              onClick={this.handleToggle(value)}
-             className={classes.listItem}
+             classes={{
+               container: classes.listItem
+             }}
            >
              <Checkbox
                checked={this.state.checked.indexOf(value) !== -1}
                tabIndex={-1}
                disableRipple
              />
              <ListItemText primary={`Line item ${value + 1}`} />
              <ListItemSecondaryAction
                className={classes.listItemSecondaryAction}
              >
                <IconButton aria-label="Comments">
                  <CommentIcon />
                </IconButton>
              </ListItemSecondaryAction>
            </ListItem>
          ))}
        </List>
      </div>
    );
  }
}

CheckboxList.propTypes = {
  classes: PropTypes.object.isRequired
};

export default withStyles(styles)(CheckboxList);

https://codesandbox.io/s/l3n2nwpzq7

0reactions
rosskevincommented, Feb 13, 2018

Awesome thanks @oliviertassinari. I couldn’t get your url to load your changes so I forked it in case anyone else runs across it - https://codesandbox.io/s/649v7kozm3

Thanks again for taking a look.

Read more comments on GitHub >

github_iconTop Results From Across the Web

[ListItemSecondaryAction] visibility on hover #10285 - GitHub
ListItemSecondaryAction should be able to be hidden by default, then visible on hover. This is a really common use case, so if possible, ......
Read more >
Hover on ListItemSecondaryAction of List component
I'm trying to implement a hover on the Delete button of my list. I want to have it hidden on default, but show...
Read more >
material-ui ListItemSecondaryAction hover handler
Forked Frommaterial-ui ListItemSecondaryAction hover handler; Environmentcreate-react-app. Files. demo.js. index.html. index.js. package.json. Dependencies.
Read more >
Css – How to use pseudo selectors in material-ui - iTecNote
1) hoverEle class with '&:hover' selector. 2) Tried to override the default root class of <ListItemSecondaryAction> with my class rootListItem
Read more >
LayerPanel - ol-kit
This will give you a LayerPanel placed on the right side of the screen that allows you to view the Layers from the...
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