-
Notifications
You must be signed in to change notification settings - Fork 258
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.trigger('compositionstart')
not work
#391
Comments
Uh oh... regression. |
@lmiller1990 interesting, at first I was inclined to agree, in a Vue app in the browser the events emitted by inner components/elements should not escape the component, and we would expect this to fail: const input = wrapper.find('input')
await input.trigger('input')
expect(wrapper.emitted()).toHaveProperty('input') But this would pass: const input = wrapper.find('input')
await input.trigger('input')
expect(input.emitted()).toHaveProperty('input') However, in this case since the |
Hm. Looking that export const useCommonBindings = () => {
const { emit } = getCurrentInstance()!
const onCompositionStart = (evt) => {
emit('compositionStart', evt)
}
return { onCompositionStart }
} <input @compositionstart="onCompositionStart" />
const { onCompositionStart } = useCommonBindings(props, inputConfig, inputRef) Further reduced: <input @compositionstart="(evt) => emit('compositionStart', evt)" />
EDIT: EDIT: @danranVm is correct - this appears to be incorrect behavior. The event can be captured in a browser as expected. See this pen. Note to trigger the event you need to enter some text using an input device (I used Japanese input). I think we need to revert or change how emit works - maybe just a clean revert of #354? Unless I am missing something - perhaps I misunderstood the original PR and what problem is solved. |
I see the problem now. I think the issue is the difference between DOM events and Vue component custom events. DOM events bubble up through parent elements in the DOM until propagation is stopped. Vue events occur on the component and no further unless they're manually re-emitted by the parent. I made a code sandbox to illustrate: https://codesandbox.io/s/amazing-knuth-hm91e?file=/src/App.vue In this example a native event ( #354 doesn't handle native DOM events properly in this regard, I naively assumed the VTU I do think whatever solution VTU adopts needs to treat both event types the way they occur in the browser, |
I think you are correct regarding custom vs native. Do you think it would be difficult to make this fix? Note we have the dom-event-types lib that may help with thisl |
Well, after a brief investigation it appears the Vue devtools hooks only captures custom events. |
I'm going to try adding a native event listener to the element of each |
Ohhhh true, why would it capture non custom events? Interesting. I think we can just do what we did before for native events. See this file. We would need to check if it's an native event or not (using dom-event-types). The reason we moved to using devtools was to be able to capture events from Thoughts? If you have something better, by all means go with that. But this approach is definitely confirmed to work for native events. |
I made a PR that I think should add native events to |
I found a fix - but @danranVm I think you will need to change your assertion to I will ping you again when this is fixed and released. Probably rc.2 will be this weekend. Thanks! |
@lmiller1990 Okay, I will try again in rc.2. Thanks! |
@danranVm it's out now, please try rc.2 Note you will likely need |
Tks, after modifying according to your suggestion, it can work. |
The code works in
rc0
, but fails inrc1
.repo: https://github.com/IduxFE/idux
The text was updated successfully, but these errors were encountered: