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

Need event.preventDefault in tab click event #842

Closed
slubowsky opened this issue Aug 12, 2016 · 3 comments
Closed

Need event.preventDefault in tab click event #842

slubowsky opened this issue Aug 12, 2016 · 3 comments

Comments

@slubowsky
Copy link

The anchors in tabs handle normal clicks like this:
``(click)="tabz.active = true"but clicks on remove are handled like this:(click)="$event.preventDefault(); removeTab(tabz);"`

Not sure under what circumstances exactly (couldn't reproduce in simple plunker) but after updating to RC 5 clicking on tabs in my application cause the app to reload (after my selected function completes). Adding $event.preventDefault(); to the anchor click function should prevent this behavior.
(Tested using jQuery

$('a').click(function( event ) {
  event.preventDefault();
});

and that fixed the issue...)

@valorkin
Copy link
Member

(click)="removeTab(tabz); return false;"
should do the trick

@slubowsky
Copy link
Author

slubowsky commented Sep 14, 2016

I was referring to the ng2-bootstrap code in the tabset.component.ts template, not my code.

<a href class="nav-link"
            [class.active]="tabz.active" [class.disabled]="tabz.disabled"
            (click)="tabz.active = true">
            <span [ngTransclude]="tabz.headingRef">{{tabz.heading}}</span>
            <span *ngIf="tabz.removable">
              <span (click)="$event.preventDefault(); removeTab(tabz);" class="glyphicon glyphicon-remove-circle"></span>
            </span>
</a>

Where on remove it does $event.preventDefault(); for you but for regular clicks it doesn't. Shouldn't it?

At the time I think I was trying to get it working using $event.preventDefault(); in my click handler but that didn't work. Returning false from a handler seems to.

@valorkin
Copy link
Member

@slubowsky oh, I know where the issue could be

jtomaszewski pushed a commit to jtomaszewski/ng2-bootstrap that referenced this issue Oct 22, 2016
fixes valor-software#766, fixes valor-software#842
* chore(package): update typescript to version 2.0.3

https://greenkeeper.io/

* Add customClass property to the Tab directive to make it easy to add class names to the outputted nav-items

* tslint fix

* Clicking on some tabs would sometime result in reloading the application (tested in Chrome). This will probably fix issue valor-software#842 which sounds exactly like the scenario this fixes for me.
Gxerxes pushed a commit to Gxerxes/ng2-bootstrap that referenced this issue Oct 28, 2016
fixes valor-software#766, fixes valor-software#842
* chore(package): update typescript to version 2.0.3

https://greenkeeper.io/

* Add customClass property to the Tab directive to make it easy to add class names to the outputted nav-items

* tslint fix

* Clicking on some tabs would sometime result in reloading the application (tested in Chrome). This will probably fix issue valor-software#842 which sounds exactly like the scenario this fixes for me.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants