Skip to content

Support nested elements containing 'ui-sref' #592

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

Closed
wants to merge 5 commits into from

Conversation

sebnilsson
Copy link

Stopped event-propagation in the click-handler for uiSref-directive to support nested tags with ui-sref-attribute.

<div ui-sref="root">
    Root-item description
    <div ui-sref="root.child">
        Child-detail
    </div>
</div>

Clicking the "Child-details"-link will fire the root.child-sref as expected, but also the root-sref immediately after, resulting in the root-state always being shown.

@timkindberg
Copy link
Contributor

I'm curious if, while good for this scenario, it may create problems for other scenarios. I'm wondering if we need to handle it in a different way... like it seems in a lot of cases you want your events to bubble, so we'd essentially be turning that off for good and I just can't tell if that's going to be ok.

@sebnilsson
Copy link
Author

That's the beautiful thing about Pull-requests, to get feedback on the feedback... now that you mention it, it may just have solved my specific case.

Is there another way to flag the click as sref-nav-executing (or something), but then "release" that status when all ui-sref-listeners are done triggered, so you can click them again?

@timkindberg
Copy link
Contributor

Yeah its almost as if we need the event to be like:

  1. ok what dom element did I originate in? Text node, cool.
  2. Go up one.
  3. ok where am I now? On a ui-sref, ok this is my ui-sref, I will ignore all others. // set some flag?
  4. Go up, go up, go up, etc. Ok where am I now? On another ui-sref, ok I'll just ignore this one, because I already hit one.

@sebnilsson Pretty sure that's what you were thinking too.

@timkindberg
Copy link
Contributor

I don't follow but feel free to implement a solution and we can review.

@sebnilsson
Copy link
Author

Sorry for the previous, confusing comment. I'm happy with this Pull Request now :)

@timkindberg
Copy link
Contributor

Oh I was confused because I'm on mobile which doesn't show that you've updated the code. So now that I reviewed the code I agree it seems much better now. Just need @nateabele to review.

@nateabele
Copy link
Contributor

Alternatively:

    <div ui-sref="root.child" ng-click="$event.stopPropagation()">
        Child-detail
    </div>

Problem solved. Bonus: we're saved from the tedium & risk inherent in trying to guess at every future use case of everyone who ever uses this library. 🍻

@sebnilsson
Copy link
Author

That is of course a lot simpler, but shouldn't it be the default behavior? Maybe it's just my, so far, limited use of the framework, but is there any scenario when you actually want an ui-sref to fire multiple times inside nested elements?

@nateabele
Copy link
Contributor

The inherent assumption here is that order of priority is deterministic and fixed. While it is likely that what you mention above is often the case, (a) it would be significantly harder for people to work around the behavior in counter-examples than it would for you to use the solution I've suggested, and (b) I can't imagine that people are nesting uiSref directives terribly often in the first place.

@sebnilsson
Copy link
Author

I trust your judgement, but intuitively it feels like an ui-sref-directive should act like an <a href>-tag, where the first "catching" a-tag wins the click.

@timkindberg
Copy link
Contributor

@sebnilsson totally see your point, but also agree with @nateabele. How often do people nest anchor tags, I'm not sure I've ever done that. Don't think we don't appreciate your contributions though, sometimes things just need to be sat on for a while before we realize the right path forward.

@sebnilsson
Copy link
Author

I totally agree, just trying to bring the problem to the surface.

As for when you use nested anchor-tags: we use it to show larger boxes of company-info, where clicking the whole box goes into to the company-page, but clicking individual small icons inside the box gets you to the specific sub-area of the company-page, like ratings, videos, images and so on.

Hope this whole thing has stimulated some thought around the problem, at least :)

@nateabele
Copy link
Contributor

@sebnilsson Indeed. I think it warrants a note in the FAQ, explaining how the event cascade can be manipulated.

@nateabele nateabele closed this Nov 28, 2013
@timkindberg
Copy link
Contributor

Will do.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants