Using the Drawer for routing change the selected if the route changes?

1 Answer 113 Views
Drawer
Noah
Top achievements
Rank 2
Iron
Iron
Iron
Noah asked on 19 Jul 2022, 01:43 PM

Is there an easy way to let the router link active status inform when a drawer is selected?  I read the documentation on drawer routing, but it cheats by having the initial drawer selected arbitrarily as the first one.

What if another link on the page redirects to user to a different drawer without the user actually clicking on the drawer widget?

Or what if the initial route to the page should have the 3rd item in the drawer selected and not the first?

If the current route changes in a way other than clicking the drawer, the selected drawer doesn't change unless I manually intercept every routing event in angular and then check the route against all the drawers and finding the appropriate one.  Even then there doesn't seem to be a programmatic way to change the selected drawer other than to rebuild the entire items array with a new selected item and replace the existing one.  Basically I have to recreate the router link active logic that already exists?

Or am I misunderstanding how to use this for routing?

1 Answer, 1 is accepted

Sort by
0
Accepted
Dimiter Madjarov
Telerik team
answered on 22 Jul 2022, 07:36 AM

Hello Noah,

Yes, everything that you described in terms of Drawer functionality is correct. As the Router is not a direct dependency of the Layout package and consequently the Drawer component, all custom routing logic should be handled by the developer.

Regarding the first question, the first item is selected only for example purposes. In a real world case we could retrieve the current route e.g. by invoking this.router.url and set the corresponding item as selected.

In terms of the second scenario, yes, we would have to build the collection of current items and manually set the selected one, as the Drawer component is not aware of the occurred change.

I hope this information helps. Let me know if I could assist further in resolving this case.

Regards,
Dimiter Madjarov
Progress Telerik

The Premier Dev Conference is back! 

Coming to you live from Progress360 in-person or on your own time, DevReach for all. Register Today.


Noah
Top achievements
Rank 2
Iron
Iron
Iron
commented on 25 Jul 2022, 12:41 PM

Ok, just making sure I wasn't missing something.

If it's truly meant to be primarily used as a navigation component, it would be nice if drawer items had something like a "route" input and they just worked instead of us having to build a lot of infrastructure around getting it to actually navigate and have the proper drawer be selected.

Martin Bechev
Telerik team
commented on 28 Jul 2022, 11:53 AM

Hi Noah,

Thank you for your feedback.

We understand that providing the ability to navigate the page only by configuring the Drawer might improve the developer's experience with the widget.

However, from an architectural perspective, this would mean that the Layout package should depend on another third-party library which we aim to avoid whenever possible. That is why we left the routing implementation in the hands of the developers.

 

Tags
Drawer
Asked by
Noah
Top achievements
Rank 2
Iron
Iron
Iron
Answers by
Dimiter Madjarov
Telerik team
Share this question
or