Skip to content
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

:target doesn’t work because preventDefault is called #75

Closed
chasenlehara opened this Issue Dec 21, 2017 · 5 comments

Comments

Projects
None yet
2 participants
@chasenlehara
Copy link
Member

commented Dec 21, 2017

Given a template like this:

<a href="#hash-in-the-url">Link</a>
<p id="hash-in-the-url">Target</p>

…and some CSS:

p:target {background: yellow;}

…and some JS:

import route from 'can-route';
import 'can-route-pushstate';
route('/{page}', { page: 'home' });

One would expect that clicking on the link would cause the paragraph to light up yellow, when unfortunately preventDefault() gets called on the event:

// If a route matches update the data.
var curParams = route.deparam(url);
if (curParams.hasOwnProperty('route')) {
// Makes it possible to have a link with a hash.
includeHash = true;
window.history.pushState(null, null, node.href);
// Test if you can preventDefault
// our tests can't call .click() b/c this
// freezes phantom.
if (e.preventDefault) {
e.preventDefault();

@Psykoral

This comment has been minimized.

Copy link

commented Dec 21, 2017

Thanks @chasenlehara I'll keep an eye on this issue, I'm relying on this browser feature working correctly ;)

@chasenlehara

This comment has been minimized.

Copy link
Member Author

commented Dec 22, 2017

Sorry I didn’t get back to you sooner; we just talked about this issue this afternoon and I’m going to try to get a fix out tomorrow.

@chasenlehara chasenlehara self-assigned this Dec 22, 2017

@chasenlehara chasenlehara added the bug label Dec 22, 2017

chasenlehara added a commit that referenced this issue Dec 22, 2017

Don’t preventDefault() when clicking a link that just changes the hash
If the user clicks on a link that’s on the same page but just a different #hash, don’t prevent default so the browser can handle the click.

Fixes #75

chasenlehara added a commit that referenced this issue Dec 22, 2017

Don’t preventDefault() when clicking a link that just changes the hash
If the user clicks on a link that’s on the same page but just a different #hash, don’t prevent default so the browser can handle the click.

Fixes #75

chasenlehara added a commit that referenced this issue Dec 22, 2017

Don’t preventDefault() when clicking a link that just changes the hash
If the user clicks on a link that’s on the same page but just a different #hash, don’t prevent default so the browser can handle the click.

Fixes #75
@chasenlehara

This comment has been minimized.

Copy link
Member Author

commented Dec 22, 2017

@Psykoral I have a PR open to fix this and I’ll get it merged & released on Tuesday.

@Psykoral

This comment has been minimized.

Copy link

commented Dec 23, 2017

you rule!!!

@chasenlehara

This comment has been minimized.

Copy link
Member Author

commented Dec 26, 2017

This should be fixed in 3.2.3

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.