Hello
I'm using the menu component version 4.13
I'd like to change the style of the active menu item but could not find any examples. Here's one of my menu items
i'm following your example to do the routing
I'm using react router dom.
Do you have an example for how to change the css of the active menu item?
Thank you.
Fabian
Hello, Fabian,
I converted this thread to an official feature request.
Regards,
FilipProgress Telerik
Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.
Hi Filip
Yes please submit this as an official public feature.
Thank you
Fabian
Hello, Fabian,
This could indeed be added as a feature request, by either making a submission in our feedback forum:
https://feedback.telerik.com/kendo-react-ui
or I can directly convert this to an official public feature request for you.Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.
Hi Filip
Thanks for the explanation. Could this be added as a feature to the menu?
I think it is a common requirement to set the active parent menu in code based on the route.
As for your suggestion I don't know how to do that but i had another idea.
I can get the textContent and look up the corresponding path in a hash array and then compare t hat to the r oute
However i noticed now the Menu isn't rendered again after the inital render. Is there a way to put the menu into controlled mode so that every time the path changes it is re-rendered?
Hi, Fabian,
Thank you for the provided clarification. Currently setting the active class on the menu based on the route is not supported. A possible approach based on the provided code would be to set the data-route attribute manually with a DOM manipulation.
I hope this helps.
Regards,
FilipProgress Telerik
Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.
Hi Filip
Thank you for this example. It's not quite what i was looking for.
Here's my senario
The user can come into the app using many different urls
e.g.
https://vdt2010.ds.city.vancouver.bc.ca:3000/CAMS/locations
https://vdt2010.ds.city.vancouver.bc.ca:3000/CAMS/todos
So if they come via locations then the locations menu should be active. if they come via todos then todos menu should be active.
i tried this code but the data-route attribute doesn't seem to exist. is there any way i can set the active menu based on the current route?
Thank you
Fabian
Hi, Fabian,
I am glad to hear that the solution worked. It is possible to achieve this by using the cssClass property and binding it to the active class. I made an example showcasing this approach:
https://stackblitz.com/edit/react-zg2pmx-7yhm6x?file=app/MenuNavContainer.jsx
Then the class has to be reset on the onSelect event.
I hope this helps.
Regards,
FilipProgress Telerik
Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.
Hi Filip
That worked. However when the app starts I'd like to highlight the menu of the page the user gets to.
Is there a way to set the active menu in code?
Thank you
Fabian
Hi, Fabian,
A possible solution would be to use the onSelect event of the Menu and dynamically add and remove a class that will apply the needed styles.
Please have in mind that this will work only for the top-level MenuItems as the other will not be visible.
Here is a demo that showcases this approach:
https://stackblitz.com/edit/react-zg2pmx-ak6yp4?file=app/MenuNavContainer.jsx
I hope this helps.
Regards,
FilipProgress Telerik
Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.