smastrom / vue-collapsed

🏋️‍♂️ CSS height transition from any to auto and vice versa for Vue and Nuxt. Accordion ready.
https://vue-collapsed.pages.dev
MIT License
123 stars 8 forks source link

Added emits #10

Closed Alexnortung closed 1 year ago

Alexnortung commented 1 year ago

closes #9

netlify[bot] commented 1 year ago

Deploy Preview for vue-collapsed ready!

Name Link
Latest commit c6e5515e76663092b9d1d507df9838f9ae48600c
Latest deploy log https://app.netlify.com/sites/vue-collapsed/deploys/63bd54553e4e6c00083ff0c0
Deploy Preview https://deploy-preview-10--vue-collapsed.netlify.app/
Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site settings.

smastrom-dolly commented 1 year ago

HI @Alexnortung, sorry for getting back to you so late but I have been on work holidays. I took a look to the edits and unfortunately, this.$emit isn't the way to go as this is undefined.

According to Vue Doc the right way is to use the emit function from the setup context:

setup(props, ctx) {
// ...
props.onExpanded();
ctx.emit('expanded')
// ...

Or using destructuring as already did for slots:

setup(props, { slots, emit }) {
// ...
props.onExpanded();
emit('expand')
// ...

Strange problem now, is that I tried to emit as displayed above but the event is somehow fired twice. I found a way to ensure that any parent callback is fired once:

props.onExpand();
() => emit('expand');

But it seems kinda hacky for me and I'm not confident in pushing such implementation.

For the moment I'm closing this PR and keep into consideration your mentioned issue. Unfortunately, altough it definitely works with Vite I don't know how Nuxt and other framework will deal with that.

Thank you and have a good one!

Simone