-
Notifications
You must be signed in to change notification settings - Fork 907
feat(useOverlay): add on
method to listen emits from component
#5244
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
base: v4
Are you sure you want to change the base?
Conversation
on
method to listen emits from component
commit: |
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 |
const overlay = getOverlay(id) | ||
|
||
if (!overlay.emits) overlay.emits = {} | ||
overlay.emits[event as string] = callback |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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>
π Linked issue
Resolved #5233
β Type of 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