-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
Input component does not accept documented event names #18654
Comments
As discussed in the framework team meeting, we should show using camelCase event names for actual events, i.e. There are some directly handled actions:
Overall the docs on this should be scrapped & rewritten from scratch to describe these in an Octaney way |
thank you! i spent a pretty good amount of time losing my mind over this. the ember guides should 100% be updated to reflect this. https://guides.emberjs.com/release/components/built-in-components/
|
looks like focusing in and out requires everything to be fully lowercase, the camel case version doesn't work.
|
Using
Arguments should also be preferred over using the |
@gvocale If you change your code to: <Input @enter={{action 'onEnter'}} @key-up={{this.onKeyUp}} /> then it would work as you expected. And
The Additional work which mentioned in the above description is here: and here is the reason why I can walk through you what happened, but I can not explain why it is behaving like that. I believe this is one of a few "mysterious" things that often make people confused and ember.js should fix them ASAP. At last, I highly recommend rewriting your code to: {{! @enter is a "magical thing" that ember.js does for us, not a native event }}
<Input @enter={{fn this.onEnter}} {{on "keyup" (fn this.onKeyUp)}} /> and actions could be written as : @action
onEnter(_value: string, event: KeyboardEvent): void {
console.log('onEnter: ', event);
}
@action
onKeyUp(event: KeyboardEvent): void {
console.log('onKeyUp: ', event);
} Because this way should be last long enough, and I truly think it has a better consistency and easy to understand. |
@MelSumner did you end up getting any more info on this issue? Melanie and I created an app for demonstrating/testing the behavior and it was confusing enough that I didn’t know what to put in the Guides. The comments in this thread help! Demo app: https://github.com/jenweber/octane-input-testing |
My understanding was that |
That shouldn’t be needed, and if that is the case it definitely is a bug. I think some folks may be doing it because they are converting from |
I would love to know the reason its needed to help my understanding of what |
All the event names that always worked on the classic However, this is complicated by the fact that there are patterns that worked by accident. For example, (This is a great illustration for why glimmer components use |
This: @logOne={{fn this.log 1}} means the same thing as this would in javascript: logOne = function(...args) {
return this.log(1, ...args);
} That is all |
We discussed this issue in today's Framework Team meeting and @locks will be working on solidifying what we want to teach people as well as which of this behavior is unexpected. Godfrey shared some insights that the inconsistency is possibly due to clobbering events and actions in the Input component. |
@cah-briangantzler @kevinhinterlong
Actually it has nothing to do with the
When passing actions to This line checks if a found "action" ( If we wrap the action with UPDATE: (passing an action w/o (passing an action w |
Thanks for the explanation. Yes the action appears to be wrapping the function in a property. I dont know why. We found this when using sinon. To mock the action, you have to mock the getter as if it is a property instead of a function. It looks like that decision is also confusing input. |
I've stuck on this too. As a new ember developer I was really under impression that Here are my tests: Thanks. |
This should be fixed by #18997, which |
To be clear, the previously documented approach is correct – i.e. The "camel case" approach is not correct as it "works" by "overriding" the private event handling hook as arguments are simply "splatted" onto the component instance. And to be extra clear, there is no "magic" with the casing and they are not interchangeable – As far as passing strings ( |
We can probably close this? However some of the confusion has since propagated into the learning materials, so we probably need to unroll them and track that effort somewhere (cc @emberjs/learning-team-managers). So sorry for the bug/confusion, and not being able to investigate earlier. Many thanks @chriskrycho for investigating/fixing the bug! |
PRs for furture reference: For the Guides followup work, I am moving this to ember-learn/guides-source#1543 |
Thanks everyone for the help, discussion, and fixes! If anyone is interested to help with the guides writing/edits, please let me know! |
Is this intended behavior, or a bug?
A contributor fixed an issue with our checkbox examples in the Guides, and in testing their work, I found that none of the Input types accept dasherized names, or
enter
, unless you use the action handler. However, it stated in the guides that they do, and the API docs suggest it as well.In a fresh 3.15 app:
To do:
The text was updated successfully, but these errors were encountered: