Comments (7)
In case anyone else experiences this issue, the workaround I used was to fill the list item with the anchor and set the class on the anchor. This doesn't hit all use cases, but it does work as expected. Example:
<mz-sidenav-link>
<a routerLink="dashboard" routerLinkActive="active">Dashboard</a>
</mz-sidenav-link>
<mz-sidenav-link>
<a routerLink="users" routerLinkActive="active">Users</a>
</mz-sidenav-link>
from ngx-materialize.
It looks like we'll be good to go, with the PR suggested at Materialize. Dogfalo/materialize#5285 It will allow .active
to apply to any element instead of li
or a
. Then this:
<mz-sidenav-link>
<a routerLink="/dashboard" routerLinkActive="active">Dashboard</a>
</mz-sidenav-link>
<mz-sidenav-link>
<a routerLink="/users" routerLinkActive="active">Users</a>
</mz-sidenav-link>
will work as expected.
from ngx-materialize.
Hi @wnipper,
Thanks for the workaround. We're gonna have to take a look at it before to take action.
Just wondering what you meant by "it doesn't hit all use cases" ?
This could be helpfull for the fix investigation.
from ngx-materialize.
I agree with @wnipper It should hook into the Angular routerLinkActive directive in order to set the class. Setting it manually doesn't really make too much sense, because how will we manage setting the property based on router path?
The <li [routerLinkActive]="['active']">
solution that @wnipper provided won't work, however. That;s because routerLinkActive
only works on an tag with routerLink
set, which doesn't exist in the sidenav component, routerlink is set by the user on their own a tags.
However his workaround is more like the correct way to use routerLinkActive than a workaround.
Then the only change needed is to change css
.side-nav li.active {
background-color: rgba(0, 0, 0, 0.05);
}
to
.side-nav a.active {
background-color: rgba(0, 0, 0, 0.05);
}
That can be done in your own css.
Otherwise the mz-sidenav-link will need a new property added called routerLink
to allow the user to set the router link there, and then in the template it would be
from ngx-materialize.
I was able to modify the sidenav component to get it working properly, using angular's native implementation. I made a PR, please review #226
An alternative to this is to submit a PR to Materialize for the CSS change I proposed above. I don't know if routerLink is recommended to be set on the a
or if setting on li
is good, but it works both ways. I raised an issue over here at Dogfalo/materialize#5284
from ngx-materialize.
I think the best fix would be the tomscholz proposition on the Materialize issue you created.
.side-nav .active {
background-color: rgba(0, 0, 0, 0.05);
}
Allowing active
class to be applied on the a
tag would solve the problem without having to change anything.
Adding routerLink
property binds the component to @angular/router
and does not help people that would use alternate router (god knows why they would).
from ngx-materialize.
OK, no problem. I'll update here when they respond to that issue.
from ngx-materialize.
Related Issues (20)
- How to make a fixed navbar ? HOT 3
- Ho to align material-icon and a text-input HOT 1
- Tooltip with max width HOT 1
- Components no implements (click)
- autocomplete not working for input if data is dynamically bind through webservice HOT 3
- MzToastService.show: Materialize is not defined HOT 2
- Autocomplete not working with chip input (does with regular input) HOT 1
- Dropdown click inisde elements closes HOT 1
- Errors after updating to Angular 7 HOT 2
- Pagination component.
- Sidenav - this.collapseButton.sideNav is not a function HOT 5
- "Falling" icon in float+flat button in a mz-navbar HOT 1
- Chip selected when scrolling (swiping) through chip autocomplete list.
- Add own picture in select option with data-icon?
- Date picker and Time picker issue in latest chrome browser HOT 15
- Date picker - How Modify default Language HOT 2
- Text area not expanding on large input size HOT 1
- Getting compilation error when import ngx-materialize. HOT 1
- pagination breaks after totalItems = 0 HOT 1
- @angular/core has no exported member 'Renderer' HOT 12
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from ngx-materialize.