-
-
Notifications
You must be signed in to change notification settings - Fork 32.3k
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
How to set active link color in ListItem? #1534
Comments
Having same problem here. Anyone got workarounds? Because the ListItem component itself doesn't seem to have any properties that allow it to behave like a MenuItem (i.e. selected property, color change, etc.) |
+1 |
@raptoria @desduvauchelle : A work-around for that would be to handle this in a function for the onClick event and assign a style to the ListItem then. Do let us know if that helps. Let us know if that helps. |
I am closing this for now. Do let us know if the above suggestion helps or not. |
Doesn't work because: |
Please reopen this issue, I am facing this same problem, many people have asked this but I am not being able to find an appropriate answer. |
I am assuming this issue is related to the very latest version of material ui. I found a work around but its not 'great', mainly because I expected this to be one of the default things a List Item would actually do. So here it goes: first make sure you have a class for an activle list Item:
Use the global theme object to select a color in your palette. when you do your mapping of data to list items, put the 'correct' class on.
and ...
I want to say this is not perfect, clicking the list item again still shows the material-y growing animation. you can always set the diabled property too ( and that's a little more accurate) ,but of course it looks,,, you know..disable. You want it to look 'active' and also not 'be active again' if you click it repeatedly. Not sure how to stop the animation from firing again, but still 'look' active. |
If anyone runs across this, I solved it like so: import { PureComponent } from 'react';
import { NavLink } from 'react-router-dom';
import { withStyles } from 'material-ui/styles';
import { ListItem, ListItemIcon, ListItemText } from 'material-ui/List';
@withStyles({
active: {
backgroundColor: 'rgba(255, 255, 255, 0.12)',
},
})
export default class ListItemLink extends PureComponent {
render() {
const { classes, icon, title, to } = this.props;
return (
<ListItem button component={NavLink} to={to} activeClassName={classes.active}>
<ListItemIcon>{icon}</ListItemIcon>
<ListItemText primary={title} />
</ListItem>
);
}
} |
@eliperelman Thanks for your answer. I have a route that is the root URL, and it seems to always be matched. How can I prevent it from always making the "home/dashboard" route as active, even thou it is on a different route? |
@johnnyPescarul you have to set "exact" to point to exact route. e.g. |
@fionaDawn's answer worked for me with active: {
backgroundColor: theme.palette.action.selected
} |
This comment has been minimized.
This comment has been minimized.
What if I want each |
with @fionaDawn 's answer and this,
|
@D3athSpank try this:
|
|
As seen at http://material-ui.com/#/components/appbar (the appbar link is pink)
can't seem to get it working in my code.. the active link is still black.
The text was updated successfully, but these errors were encountered: