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

Add v-on:keyup.enter to JSX #59

Closed
nickmessing opened this issue Mar 8, 2017 · 11 comments
Closed

Add v-on:keyup.enter to JSX #59

nickmessing opened this issue Mar 8, 2017 · 11 comments

Comments

@nickmessing
Copy link
Member

nickmessing commented Mar 8, 2017

We could do something like:

render (h) {
  return <div onKeyup.enter={this.something} />
}
render (h) {
  return h('div', {
    on: {
      keyup: {
        enter: this.something
      }
    }
  }
}

to support the event modifiers, what do you think @yyx990803, @QingWei-Li, does it make any sense to you ?

@nickmessing nickmessing changed the title Add v-on:keyup.enter in JSX Add v-on:keyup.enter to JSX Mar 8, 2017
@nickmessing
Copy link
Member Author

nickmessing commented Mar 8, 2017

@LinusBorg, I've seen that you respond to questions like "How to use @event.modifier in JSX?" pretty often, do you think this idea is legit?

P.S. we can do transforms without affecting other vue repos like:

render (h) {
  return <div onKeyup.enter={this.something} onKeyup.delete={this.somethingElse} />
}
render (h) {
  return h('div', {
    on: {
      keyup (event) {
        if (/* check for enter */) this.something(event)
        if (/* check for delete */) this.somethingElse(event)
      }
    }
  }
}

This would be a change in this repo only and it would allow people to use event modifiers directly in jsx.

@nickmessing
Copy link
Member Author

nickmessing commented Mar 22, 2017

@QingWei-Li, @yyx990803, @LinusBorg.

Hey, unfortunately babylon doesn't allow . in attributes, does this syntax look readable for you?

class A {
  render () {
    return (
      <div some_thing="somethingelse">
      	<input type="text"
      		onKeypress__enter={this.someMethod}
      		onKeypress__backspace={this.someOtherMethod}
      		onClick__prevent={this.smth} />
      </div>
    )
  }
}

I mad a POC and it works.

@nickmessing
Copy link
Member Author

@yyx990803
Copy link
Member

I like the POC! It kinda sucks that we can't get the syntax to align with the template version, but I can't seem to come up with a better alternative... (the only other char that can be used inside a JSX identifier is $, but it's not visually distinct enough)

@nickmessing
Copy link
Member Author

nickmessing commented Mar 23, 2017

@yyx990803, maybe we can convince the babylon team to accept dot as a part of JSX identifier?

I'll try to do a PR for them.

@nickmessing
Copy link
Member Author

nickmessing commented Mar 24, 2017

@yyx990803 I have made a POC with XML's namespaces, using dot is a bad idea because it will result in invalid XML. Chaining doesn't work but I think about supporting things like <input onKeypress:enter-prevent />, what do you think about the dash-based chaining?

P.S. I know it is totally opposite from what is colon and dot used in vue's template syntax but I guess JSX should be different.

P.P.S. I think it should not be a part of this plugin, it should be a separate one because it is valid for any JSX and is not limited to Vue.

@yyx990803
Copy link
Member

@nickmessing I like the namespaced version - and yeah I agree it should probably be a separate plugin.

@nickmessing
Copy link
Member Author

@eakarpov
Copy link

eakarpov commented Jun 5, 2019

@nickmessing semicolons are not valid in JSX..

@nickmessing
Copy link
Member Author

nickmessing commented Jun 5, 2019

@eakarpov, yes, semicolons (;) are note, but colons (:) are according to the spec.

As you can see in the spec: https://facebook.github.io/jsx/
JSXAttributeName can be either JSXIdentifier or JSXNamespacedName
and JSXNamespacedName is just JSXIdentifier : JSXIdentifier
so colon (I assume you mean that since we discussed colons) are a valid part of JSXAttributeName as long as it's a single colon separating two JSXIdentifier.

P.S. this project and all sugars now live here: https://github.com/vuejs/jsx
P.P.S. However, they are not allowed in TSX at the moment because TSX does not fully support JSX spec.

@panksi
Copy link

panksi commented Sep 12, 2019

This doesn't work as expected,

It triggers event even when modifier is added
example:
1.
image

outputs nothing

image

outputs:
image

so Either gets ignoreed with __ or ignores the modifier with :

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

No branches or pull requests

4 participants