-
Notifications
You must be signed in to change notification settings - Fork 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
RFC: Nested state support for ui-sref-active #704
Comments
Nice I've at least triaged it and added to Milestone 0.4.0. Thanks. |
What about a separate directive called |
@demands Wow I haven't thought of that. It surely may be useful to apply different classes to separate the cases that a state directly active from activation of descendant states. For example, with a separate directive <div ui-sref-nested="is-child-selected" ui-sref-active="is-selected"></div> |
I kind of like this functionality but not necessarily the solution. It feels a tad odd for an official solution. Talking about @demands idea. |
What would be better? |
Perhaps its the naming that I don't like, I see the need for the two solutions. Like maybe another good idea is to have only the
|
@timkindberg the The only scenario I came up with is to apply additional styles if there is an element with For example: <li ui-sref-active="...">
<a ui-sref="..." ng-if="!disabled">Step 3</a>
<span ng-if="disabled">Step 3</span>
</li> And |
@MrOrz cool thanks. Yeah the idea for adding 'sref-active' in all cases was so you'd always have a common class among all active srefs regardless of what class name you specified, but I think its probably not so useful. If @nateabele is ok with the idea of appending the extra |
A very quick hack i've used for recursively activating the parents. I m almost sure that it is not a correct implementation, but it should give an idea: https://github.com/besnik81/ui-router/compare/patch-1 It works in very well in my case, which is similar to the following snippet. <ul>
<li ui-sref-active="active">
<a href="#">Parent</a>
<ul>
<li ui-sref-active="active">
<a href="#" ui-sref="my.state">Child</a>
</li>
</ul>
</li>
</ul> |
@besnik81 The idea that one If the <ul>
<li ui-sref-active="active">
<a ui-sref="my" style="display: none;"></a> Parent
<ul>
<li ui-sref-active="active">
<a href="#" ui-sref="my.state">Child</a>
</li>
</ul>
</li>
</ul> Not to mention that the solution I provided above cannot deal with the case where inner <ul>
<li ui-sref-active="active">
<a ui-sref="??? Dunno which to choose ???" style="display: none;"></a> Parent
<ul>
<li ui-sref-active="active">
<a href="#" ui-sref="my.state">Child</a>
</li>
<li ui-sref-active="active">
<a href="#" ui-sref="your.state">Child</a>
</li>
</ul>
</li>
</ul> So there are 2 "nested
And these two patterns are not necessarily independent! Thing's getting complicated now...... :/ |
I don't fully understand how the ideas differ |
@timkindberg The essential difference is that the state hierarchy does not necessarily correspond to the HTML hierarchy. The code I've provided focuses on activating parent nodes in the HTML, whenever a link inside that node is activated, regardless of the active state. My idea is that we need these additional classes to support CSS styling -- which in turn is using only the HTML structure. The primary use will be for styling menus. I think we can have multiple not-related states included under the same menu and still wanting to activate that menu item. The solution given by @MrOrz focuses on activating links that correspond to parent states (hope I am right here). Definitely, there are two patterns here. |
To clear the ideas (or just thinking loud): First, ui-sref will transition into a state (say app.users.list that lists the users). Clicking on a user, ui-sref="app.users.view(34)", will transition into a new child state.
|
@besnik81 ah I don't think I ever picked up on the fact that is was based off of the actual state nesting, I always was thinking in terms of how the ui-sref-active directive would interact with ui-srefs nested in the html, regardless of which states the ui-srefs pointed. I do understand now, at least how there are more things to consider, but I'm a bit lost as to how to approach it. Sounds like it's getting overly complex to me at this point. Its fine to get complex while hashing things out and discussion but we'll need to steer this way back to super simple at the end; I mean it is just a directive for highlighting something, so it needs to be dead easy. Also I'd prefer dead easy and hit 80% of use cases, rather than complex and hit 100%. |
I have a multi-level navigation that uses nested states extensively, and this PR would solve several of the UI issues I'm having. I'll have to catch up on this thread & grok the "2 patterns" so hopefully we can reach a conclusion :) |
I came up with an idea during shower :P It combines the HTML hierarchy (using scope events) and state hierarchy alltogether. Let's say we have an HTML element with
In this way the Is there any unsatisfactory scenario I have not thought of? |
@MrOrz very well thought out. One potentially missing scenario (not sure how important it is though, keeping in my the 80/20 rule). A scenario like this where the nested ui-sref point to non-nested states (but really just any nested ui-sref regardless of its state target): <ul>
<li ui-sref="stateA" ui-sref-active>
<ul>
<li ui-sref="stateB"/>
</ul>
</li>
</ul> We'd have to have a 3rd css class I think: Also I would prefer the following naming conventions:
|
Hi guys, while you think about which one is the perfect solution, can't you please implement the @MrOrz 4 lines solution? |
@gfpacheco Nope, so it's a good thing it's so easy for you to roll your own module while you wait. |
@gfpacheco I rolled my own janky solution not too long ago. Check out this gist if you'd like to copy it. |
Yes it's easy, but I'm using bower to manage 3rd paty scripts. Well, I'll uninstall it and hard code it, thanks. |
Sorry I am currently on other projects and didn't have time for a PR. FYI you can put file path in For example, a line from my
|
+1 |
Upon seeing #818 and #819 I decided to push myself to implement what we have discussed in this thread. The event names are after @timkindberg 's suggestions. The forked branch I am currently working at: https://github.com/MrOrz/ui-router/compare/704 Plunker example: http://plnkr.co/edit/YJ35VMz5AjP1nVIGvNKV?p=preview Some additional effort is made to work out the situation when an URL of a certain state is directly navigated, since AngularJS seems to instantiate Now when the following URL is directly navigated, "Bob" should be surrounded in red borders and "Users" should have pink background. I am going to add some tests, taking #819 as a precious reference. For the first time in forever, I will be writing a test! ❄️ |
This is a plunker of @besnik81 's snippet with the implementation applied. http://plnkr.co/edit/LJlUnSfdUVyTQLQxThzv?p=preview Notice that since the parent |
…f-active uiSrefActive now takes all decendant uiSrefs into consideration. uiSrefActive also adds a class with "-nested" postfix when a child state of the related uiSrefs becomes active. Closes angular-ui#704.
Sorry for this late reply. @MrOrz, if you would like to have a look at this implementation (). https://github.com/besnik81/ui-router/compare/patch-2 I did this 2 weeks ago, but apparently haven't posted correctly my comment about this. It recursively asigns classes to all parent |
@besnik81 Are you planning to send a pull request with your implementation in the future? |
@lanceschi
|
@sjdweb: thanks! It did the trick! Nice workaround while waiting for the official implementation. |
Thanks @sjdweb, just what i was looking for. |
Check out #927 for latest progress on this |
When will this be released? |
In the next release most likely... so within 4 weeks? |
Thx, looking forward to. 👍 |
My workaround: (Also how can i use html code in commments withtout it getting parsed as html? |
👏 perfect - exactly what i was looking for :-) rebuilding locally worked out nicely |
what's the suggested implementation for this? seen several linked threads but not an official stance on how to implement it. |
@jkarttunen: your solution doesn't work for me. 😦 |
@dmackerman this is probably because you didn't define $state in your view $scope : $scope.$state = $state; |
@Grsmto: I actually have it on my $rootScope - so that should work, no? $rootScope.$state = $state;
$rootScope.$stateParams = $stateParams; |
@dmackerman yes I suppose. I just tried it right at the time I wrote my comment and it works... |
@jkarttunen works for me as well in order to show a tab active for any child state. One note to others. This is a replacement of ui-sref-active attribute. |
You can also use the
|
Just to clarify to anyone coming to this thread late, like me, from an old-ish version of ui-router: the feature described in this issue is now implemented in The old I use a hierarchical ui-router paradigm in my app, with lots of abstract states, so I have a nav bar that looks like this:
The nav's children, the spans, are not actual links (and those span's ui-sref states are abstract) but I want them to activate whether the user is on the .table or .new, or any other subroutes. Not entirely DRY, but it works! |
@atesgoral 's solution worked for me. short and sweet, would like to thank for letting know about that. |
@lekhnath You're welcome :) |
the fix is in place, tho |
I was actually trying to add an active class in |
@atesgoral Please provide a working example |
http://plnkr.co/edit/V67mToDSN0SbzaGJTHw2?p=preview |
It is mentioned in #635 and #19 that
ui-sref-active
will support nested state in the future, but I could not find the details discussed anywhere. As I browse the current source code, I found that it is actually not hard to achieve, and that it would seem redundant if I create another directive just for supporting nested states.Since I need this feature right away, I've implemented a quick and dirty way to meet my need: when an extra html attribute
ui-nested
is present,ui-sref-active
would use$state.includes
instead of strict equality on the states.Demo: http://plnkr.co/edit/CWUy3T0M7dTap75hASkk?p=preview
This can be achieved by merely changing 1 line (yeah I'm only capable of making a modification <= 4 lines... :P)
https://github.com/MrOrz/ui-router/compare/ui-nested
Hope that through this little dirty hack, we can initiate a discussion on how this function should be properly implemented.
The text was updated successfully, but these errors were encountered: