-
Notifications
You must be signed in to change notification settings - Fork 3k
ui-active-highlight directive #19
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
Comments
I agree that the directive name is bad, I do not mind changing it to be more abstract so that it is applicable to the new router. |
It would be very neat if this could be combined with ui-state-href (whatever syntax that may end up with), so you could say something like <a ui-state-ref="contacts.detail(contactId:$contact.id)" highlight>...</a> which would highlight the link if the state linked to is (or is included in) the currently active state. This would imply that the match would be on state AND parameters. In either case it should be possible to specify if we're asking for an exact "is" state match or an "includes" match (i.e. the named state or any of it's descendants). I think this simplified 'make a link and highlight it' probably covers about 90% of cases, so maybe we can even leave any more complex cases to simply call $state.is() or $state.contains() like the sample app currently does. The only fly in the ointment is that fairly often you want the 'active' (or equivalent) CSS class on a parent of the link, not the link itself. I wonder if something like |
Nice, I like it. Wouldn't be <a ui-state-ref="contacts.detail(contactId:$contact.id)" ui-highlight>...</a> |
Do not implement this as a hilighter. There are reasons I developed
|
@ProLoser would you mind going into a bit more detail on why a highight directive or highlight option on ui-state-ref is a bad idea? It certainly seems like an extremely common case to me, so it would be nice if it was supported with the minimum amount of fuss for the developer. |
So 'highlight' is addressing only one fixed use-case. There are also other issues with the suggested implementation. Lets say we have a nav and want the active item. You proposed: <a ui-ref-highlight="some.path">...</a> This is fine, except that you are now stuck to that one tag, using fixed CSS classes, and can only toggle classes. What if I have a normal nav list and want the class on the LI? What if I want to access this behavior and use it for validation, or other checks. What if I want to do these checks from descendant elements? <li><a>...</a></li>
<li><a>...</a></li>
<li><a>...</a></li> Instead, <li ui-route="some.path" ng-class="{'active':$isRoute}">
<a ng-show="$isRoute">
...
<input ng-required="$isRoute"> Wether you use the flag to trigger a class state or visibility or validation is easily up to the developer, and the scope variable can be accessed from grandchildren. It also hooks into the href and ng-href properties if they are found on the same tag. Now, I understand concerns with the name |
Dean I think your directive is really cool and robust. I'll be honest that I had not had time to really look at it. It's clear that you've been down this road already and have already solved this issue. As long as we can bundle your route directive with the rest of the code in a way that makes it feel like part of the same family then I have a yes vote for integrating it. Sent from my iPad On Feb 24, 2013, at 10:33 PM, Dean Sofer [email protected] wrote:
|
Hmm... from what I understand by looking at ui-route it's essentially a way of looking at $location and setting a boolean in $scope when the location matches a pattern. However with the current $state code, that shouldn't really be necessary anymore -- the URL maps to a state, and then any decisions in the UI should be able to be made based on the state and it's parameters, without going back to looking at $location directly. (I don't think I understand how it's meant to be used with href / ng-href.) Using I was looking for a way to replace
with this (1)
or maybe this (2)
I.e. I want to avoid having to repeat the state name and parameters, while being able to control which element and CSS class are used for highlighting (and have reasonable defaults for those, e.g. 'active' for the CSS class and same element). I think something along the lines of (1) is more intuitive, because the focus is on the link being generated, and the highlighting is an add-on, whereas in (2) it's more difficult to see what is going on. |
I figured with how states worked this would be mostly useless. However the proposal of "li:active" etc is just a bad solution and will lead to confusion. Instead, I think that simply creating a Do me a favor, and hold off on the highlighting directive for now. Dean Sofer On Sunday, February 24, 2013 at 8:21 PM, Karsten Sperling wrote:
|
If anyone wants a directive for this until we figure out what we are gonna do with it, check out ngBoilerplate's activeIfCurrent directive. Would probably be pretty easy to modify for states. |
@timkindberg I'm not sure how that's better than ui-route? You could simply copy it over and rename it, even though this entire project is a state machine but it's called ui-router |
If you would like to go ahead and implement this directive, go ahead. But please use the pattern set out in uiRoute and not in the ngBoilerplate as it is a less versatile solution. |
Yeah I wasn't saying it was better but that it was an option. I'm not feeling strongly about it. I just stumbled across the directive at Ng boilerplate and thought looked good for a quick fix until we had figured out what we were gonna do. Last I heard you asked Karsten to hold off so I thought something was in the works. I figured once it was finished that would be the official way to do it. Sorry if I misunderstood. |
No nothing was in the works, I was just busy and wanted to review the I realize I probably sound obsessive at this point.
|
Ha ha that's ok. I don't have time at the moment either. Hence the half |
Is the right time to rethink the issue? About @ProLoser's approach of using something similar to this: <li ui-route="some.path" ng-class="{'active':$isRoute}">
<a ng-show="$isRoute">
...
<input ng-required="$isRoute"> I have some concerns on the implementation, as it relies on the scope inheritance: This means that it could not work when using directives with isolated scopes, and end-users may not know why... Any thought on this? Anyway, if you think that it is ok I could try to implement it (although using |
Your point about scope isolation is applicable to ANY scope variable. This includes $index, or iterators, etc. If the developer is using scope isolation and they want to access scope variables they should explicitly list every variable they want access to. Otherwise, I do not think that your concern is valid. Dean Sofer On Thursday, April 11, 2013 at 2:54 PM, Luis Ramón López wrote:
|
What I don't quite see is how having a separate directive is better than just calling Maybe if we had |
To clarify my previous comment, I think one key feature for a directive to "carry it's weight" in these scenarios is to be able to avoid the repetition of state name and parameters for the case of generating and highlighting the same link. |
Huh? You mean you don't want to have to specify the url it needs to look for? Or are you referring to being able to change $isRoute to something else? |
Oh sorry I missed your second comment before responding. I agree, if people can do |
Ideally we could let the user choose between doing href='' for you or not, so for the case where you want to e.g. highlight an LI, you'll have the directive on the LI, and use Maybe if ui-ref looks at the element, and if it is an A and has no explicit href attribute, then set the href attribute as well? |
Is there currently a solution to doing this conditional Is there any way to fix this? Or is there an alternative solution to this problem that's specific to this |
|
Nice, thanks! Is there a way to do this when the target URL contains parameters? E.g.
Say you have a list of users and you click one, and that list stays on screen while the user's Thanks again! EDIT: Never mind, figured you could use a combination of |
You can publish $state on $rootScope with a module config function for example, otherwise a controller will do just fine as well. |
I think we can call this closed by ae360fc |
10 months in the making... |
It would be useful to use this on abstract states (e.g, highlight a user icon if I'm viewing a list of users or an individual user) |
@hcliff Yup, we'll get there eventually. Any time you wanna pony up with a PR, I'll be happy to give you some pointers. |
@ksperling said somewhere at some point:
I propose a directive called ui-active-highlight, it would add an "active" class onto the element whenever the state in the parameter was active.
Refer to the ui-route directive authored by @ProLoser
The text was updated successfully, but these errors were encountered: