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.

How to set hover styling for Typography component?

See original GitHub issue

I want a normal text link to be underlined on hover. In order to that I’ve tried to style a Typography component nested inside a link component but this doesn’t work. I’ve searched through the entire documentation but can’t find anything about adjusting hover effects on typography/link components.

const styles = {
  textDecoration: 'none',
  '&:hover': {
    textDecoration: 'underline',
}

<Link to="/mypage"> 
      <Typography 
        color="secondary"
        type="body1" 
        style={styles}> 
          {props.text}  
      </Typography>
</Link>;

Expected Behavior

I expect the link to underline on hover.

Current Behavior

Nothing happens.

Steps to Reproduce (for bugs)

The full code for the component:

import * as React from 'react';
import { Link } from "react-router-dom";
import Typography from 'material-ui/Typography';
import { withStyles } from 'material-ui/styles';

const styles = {
  textDecoration: 'none',
  '&:hover': {
    color: 'white'
  }
};

function TextLink(props) {

  return (
    <Link
        to="/"
      > 
      <Typography 
        color="secondary"
        type="body1" 
        style={styles}> 
          {props.text}  
      </Typography>
    </Link>;
  )
}

export default withStyles(styles)(TextLink);

Your Environment

“material-ui”: “^1.0.0-beta.30”, “react”: “^16.2.0”, “react-dom”: “^16.2.0”,

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:3
  • Comments:7 (1 by maintainers)

github_iconTop GitHub Comments

34reactions
vdhieucommented, Jan 29, 2018

You have use className and classes

const styles = {
+  myTextStyle: {
     textDecoration: 'none',
     '&:hover': {
      color: 'white'
   }
+ }
};

function TextLink(props) {

  return (
    <Link
        to="/"
      > 
      <Typography 
        color="secondary"
        type="body1" 
-      style={styles}
+      className={props.classes.myTextStyle}> 
          {props.text}  
      </Typography>
    </Link>;
  )
}

export default withStyles(styles)(TextLink);
Read more comments on GitHub >

github_iconTop Results From Across the Web

How to set hover styling for Typography component? #10075
I want a normal text link to be underlined on hover. In order to that I've tried to style a Typography component nested...
Read more >
MaterialUI Custom Hover Style - reactjs
You should define a key for TableRow as a className and then put your hover style right on that class name as an...
Read more >
Add Hover Styling With MUI's SX Prop (4 Examples!) - YouTube
Do you want to build a full MUI app from beginning to end, learn every aspect of the sx prop, styled API, and...
Read more >
How to Add Hover Styling with MUI's SX Prop (4 Examples)
Hover styling is a common requirement for UI components. ... how to add hover styling to the Box, Button, Paper, and TextField components....
Read more >
How to customize - Material UI
In this case, the styles are applied with .css-ae2u5c-MuiSlider-thumb but you only really need to target the .MuiSlider-thumb , where Slider is 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