-
Notifications
You must be signed in to change notification settings - Fork 6
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
preventDefault #5
Comments
Exemplary import { helper } from '@ember/component/helper';
export const preventDefault = ([handler]) => event => {
event.preventDefault();
if (handler) handler(event);
};
export default helper(preventDefault); |
I'd vaguely prefer a wrapping helper over adding a hash argument. Either of these seem good to me: <a href="/" {{on "click" (prevent-default this.someAction)}}>Click me</a>
<a href="/" {{on "click" this.someAction}} {{on "click" (prevent-default)}}>Click me</a>
|
what if someone always wants to prevent default? <a href="/" {{pdon "click" this.someAction}}>Click me</a> idk |
<a href="/" {{on-local "click" this.someAction}}>Click me</a> -> local = preventDefault & stopPropagation <a href="/" {{on "local:click" this.someAction}}>Click me</a> |
<a href="/" {{on "click" (dom-event this.someAction stop=true prevent=true)}} >Click me</a> |
Personally I am also leaning more towards the wrapping helper syntax. I am just not 100 % sure, whether these helpers should be included in this addon. I could add a config so that they may be stripped from the build.
<a
href="/"
{{on "click" (prevent-default (stop-propagation this.someAction))}}
>
Click me
</a> <a
href="/"
{{on "click" this.someAction}}
{{on "click" (prevent-default)}}
{{on "click" (stop-propagation)}}
>
Click me
</a> <a
href="/"
{{on "click" this.someAction}}
{{on "click" (prevent-default (stop-propagation))}}
>
Click me
</a> Besides Tangentially related: There's been some talk about how we might want to swap out the underlying event system in the future. If we also add |
* feat(prevent-default): add `prevent-default` template helper Closes #5. * docs(README): add `preventDefault`
{{action}}
supports apreventDefault
option to automatically callevent.preventDefault()
:We could either add the same option to
{{on}}
:Or explore alternative solutions. For instance, we could create a
prevent-default
helper:Currently all named parameters are passed through to
addEventListener
as event options. Adding apreventDefault
would mean that we introduce special handling for some options.The text was updated successfully, but these errors were encountered: