ui icon indicating copy to clipboard operation
ui copied to clipboard

feat(useOverlay): add `on` method to listen emits from component

Open edimitchel opened this issue 2 months ago โ€ข 5 comments

๐Ÿ”— Linked issue

Resolved #5233

โ“ Type of change

  • [ ] ๐Ÿ“– Documentation (updates to the documentation or readme)
  • [ ] ๐Ÿž Bug fix (a non-breaking change that fixes an issue)
  • [ ] ๐Ÿ‘Œ Enhancement (improving an existing functionality)
  • [x] โœจ New feature (a non-breaking change that adds functionality)
  • [ ] ๐Ÿงน Chore (updates to the build process or auxiliary tools and libraries)
  • [ ] โš ๏ธ Breaking change (fix or feature that would cause existing functionality to change)

๐Ÿ“š Description

Introducing this new on method permits to easy bind emits event before opening for let developer to only think about props in create/open/patch methods.

๐Ÿ“ Checklist

  • [x] I have linked an issue or discussion.
  • [x] I have updated the documentation accordingly.

edimitchel avatar Oct 15 '25 23:10 edimitchel

npm i https://pkg.pr.new/@nuxt/ui@5244

commit: 8dde938

pkg-pr-new[bot] avatar Oct 15 '25 23:10 pkg-pr-new[bot]

I forget the API instance documentation + Caveats section miss a warning about the limitation of the composable.

We need to discuss about its limitation is caused by typescript limitations

edimitchel avatar Oct 16 '25 07:10 edimitchel

@genu can you take a look?

edimitchel avatar Oct 31 '25 00:10 edimitchel

Thanks for this @edimitchel I think it looks good. The on syntax makes better sense and its cleaner.

I think it may be even a good idea to deprecate the old way of handling events. Having multiple ways could be confusing.

What do you think about that?

We could maybe, add a deprecated message for now, if possible, when users try to handle events like this:

const modal = overlay.create(LazyModalExample, {
  props: {
    count: count.value,
    onClose: (value: number) => {
      console.log('Modal closed with value:', value)
    }
  }
})

Otherwise, we could depreciate them in a future version as a breaking change

genu avatar Nov 03 '25 13:11 genu

@edimitchel Let me know if you need some help with this

genu avatar Nov 14 '25 12:11 genu

Here we are, I made it (sorry for the delay, I didn't take time for doing this small change). I didn't achieve to add a TS deprecation as it's on props I have to track but this is dynamic and not manageable from our side.

Let me know if you see something wrong.

edimitchel avatar Nov 22 '25 23:11 edimitchel

I'm not sure it's good now but I'm now not very confident with this feature because of TypeScript limitation which will make the on unusable when there is more than 5 props on the component

edimitchel avatar Nov 27 '25 14:11 edimitchel