AmpersandJS / ampersand

Quickest way to get started with ampersand.
MIT License
812 stars 41 forks source link

Handle click on element (e.g. <span>) within an anchor <a> #103

Closed e2jk closed 9 years ago

e2jk commented 9 years ago

Without this addition, in the example below the element that is clicked is the span, thus it has no host property. The link is thus considered not to be local, meaning that app.navigate is not used and the browser sends a new GET request to the server. Now if the element is not an anchor, it will check if the parent is one, and use that as the link instead.

<div class="list-group" data-hook="blabla-list">
    <a class="blabla list-group-item" data-hook="url" href="/some_url/1">
        <img height="40" width="40" data-hook="avatar" src="some image"></img>
        <span data-hook="name">Some text</span>
    </a>
[...]
kamilogorek commented 9 years ago

This'd take care of 1 level "deep" elements. What about those with more complex hierarchies and yet being a link? Think about "card tile" for example.

lukekarrys commented 9 years ago

I've solved this (and a few other element click quirks) in a separate module that we could include here: http://npmjs.org/local-links

I know @henrikjoreteg has been using it for some stuff. Maybe he could chime in on whether it'd be a good candidate to use here?

kamilogorek commented 9 years ago

Looks nice and should resolve this issue once and for all.

lukekarrys commented 9 years ago

Looks like this was already fixed in the latest release: v3.0.0.

@e2jk You should be able to update the cli and it should work now.