Skip to content

Conversation

edimitchel
Copy link

@edimitchel edimitchel commented Oct 15, 2025

πŸ”— 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)
  • ✨ 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

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

@github-actions github-actions bot added the v4 #4488 label Oct 15, 2025
@edimitchel edimitchel changed the title refactor: implement event handler system for overlay components with … refactor: implement event handler system for overlay components Oct 15, 2025
@edimitchel edimitchel changed the title refactor: implement event handler system for overlay components feat(useOverlay): add on method to listen emits from component Oct 15, 2025
@pkg-pr-new
Copy link

pkg-pr-new bot commented Oct 15, 2025

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

commit: f7a2b45

@edimitchel
Copy link
Author

edimitchel commented Oct 16, 2025

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

@genu genu self-requested a review October 19, 2025 14:53
const overlay = getOverlay(id)

if (!overlay.emits) overlay.emits = {}
overlay.emits[event as string] = callback
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
overlay.emits[event as string] = callback
// For close events, preserve the default close behavior by chaining callbacks
if (event === 'close') {
const existingHandler = overlay.emits[event as string]
if (existingHandler) {
overlay.emits[event as string] = (...args: Parameters<typeof callback>) => {
callback(...args)
existingHandler(...args)
}
} else {
overlay.emits[event as string] = callback
}
} else {
overlay.emits[event as string] = callback
}

The on() method replaces the default close event handler instead of preserving it, which breaks automatic overlay closure when registering close event listeners.

View Details

Analysis

useOverlay.on() replaces default close handler breaking automatic overlay closure

What fails: useOverlay.on('close', callback) in src/runtime/composables/useOverlay.ts:214 replaces the default close handler instead of chaining it, preventing automatic overlay closure when user callbacks don't explicitly call modal.close()

How to reproduce:

const { create } = useOverlay()
const modal = create(Component)
modal.open()

// Register close handler that doesn't call modal.close()
modal.on('close', (value) => {
  console.log('Close event received:', value)
  // No modal.close() call here
})

// When component emits close event, overlay stays open
component.$emit('close', 'result') // Overlay remains open

Result: Overlay stays open because default (value) => close(id, value) handler is replaced by user callback

Expected: Overlay should close automatically even when user callback doesn't call modal.close(), preserving the default close behavior established in create() at line 118

Root cause: Line 214 uses direct assignment overlay.emits[event as string] = callback instead of chaining handlers for close events

Co-authored-by: vercel[bot] <35613825+vercel[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

v4 #4488

Projects

None yet

Development

Successfully merging this pull request may close these issues.

useOverlay: bind emits on overlay instances

1 participant