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

[Bug] Event names with colons aren't handled. #42

Open
rbanks54 opened this issue Nov 14, 2023 · 5 comments
Open

[Bug] Event names with colons aren't handled. #42

rbanks54 opened this issue Nov 14, 2023 · 5 comments
Labels
enhancement New feature or request open to ideas Something I don't know how to fix but if someone has ideas I'm game to explore options

Comments

@rbanks54
Copy link

Consider a component that supports v-model usage. It needs to provide two things for the syntactic sugar to work. A modelValue prop, and an update:modelValue event.

What I can't work out, is how to get the event binding working so that the update:modelValue event can be listened to in Angular. I think the colon in the event name is making a mess of things and I had a look at the ngvue source code, but I can't see where I'd potentially update things to fix it.

It's pretty easy to replicate this by changing the example applications to emit an update:description event instead of an update-description event. You'll see the vue devtools no longer showing the event binding

image
@jaredmcateer
Copy link
Owner

jaredmcateer commented Nov 14, 2023

Unfortunately it's not possible with Angular's attribute normalization. It will take attributes like

  • v-on-model-update
  • v-on-model:update
  • VOnModelUpdate
  • v_on_model_update

and convert them to vOnModelUpdate

It's annoying but the workaround I've used in the past when I couldn't change the component I wanted to use is to create a thin vue component wrapper with a v-props-model / v-on-update pairing.

@jaredmcateer jaredmcateer added the open to ideas Something I don't know how to fix but if someone has ideas I'm game to explore options label Nov 14, 2023
@rbanks54
Copy link
Author

rbanks54 commented Nov 14, 2023

I wonder if we could do something in the vue app instance when it's created. Add a general listener/hook for events from the component, and if any events come through with a colon in the name, re-emit them for angular consumption using an angular compatible name. e.g. button:clicked -> ButtonClicked.

@jaredmcateer
Copy link
Owner

🤔 I don't think there is a way to catch all events from a component though. I've done a little searching around and there is no obvious solutions.

The best I've come up with is that ngVue would need to provide a separate directive for models like

  • v-model="{ prop: model, update: handleUpdate }" -> :modelValue="model" / @update:modelValue="handleUpdate"
    or a custom prop name
  • v-model-title="{ prop: model, update: handleUpdate }" -> :title="model" / @update:title="handleUpdate"

Though I would probably change v-model to something else to disassociate it from the standard Vue directive

@rbanks54
Copy link
Author

rbanks54 commented Nov 15, 2023

I don't think there is a way to catch all events from a component though

The Vue devtools captures component events. I might have dig through the code to see what they do.

That said, I think the idea of a directive to make v-model work is a much better choice. It makes things explicit, eliminates the complexity of a generic event listener, and we only listen for the events we need. How about a directive name such as ng-v-model to make it obvious?

@jaredmcateer
Copy link
Owner

I think the dev tools have non-production internal hooks they can use to dig in but they are not present in production bundles.

I'm not a fan of ng-v-model because ng- is typically an angular built in namespace, ngv-model might work though. Actually kind of kicking myself I hadn't changed the directive to this when I rewrote the library.

I am currently working on a tight deadline with my regular job and then on vacation for December. Earliest I could start work on this is in January. If you're so inclined to work on it and post a PR I'd be able to make time to review it otherwise this will have to wait until I'm back.

@jaredmcateer jaredmcateer added the enhancement New feature or request label Nov 20, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request open to ideas Something I don't know how to fix but if someone has ideas I'm game to explore options
Projects
None yet
Development

No branches or pull requests

2 participants