fix(web): type select change

This commit is contained in:
JzoNg 2026-04-23 17:49:24 +08:00
parent 7c348e994c
commit 1a0776ce9b
2 changed files with 27 additions and 0 deletions

View File

@ -149,6 +149,30 @@ describe('ShortcutsPopupPlugin', () => {
})
})
it('does not close on mousedown inside a Base UI portal overlay', async () => {
render(<MinimalEditor />)
const ce = screen.getByTestId(CONTENT_EDITABLE_ID)
ce.focus()
fireEvent.keyDown(document, { key: '/', ctrlKey: true })
expect(await screen.findByText(SHORTCUTS_EMPTY_CONTENT)).toBeInTheDocument()
const portal = document.createElement('div')
portal.setAttribute('data-base-ui-portal', '')
const portalChild = document.createElement('button')
portalChild.textContent = 'portal-child'
portal.appendChild(portalChild)
document.body.appendChild(portal)
fireEvent.mouseDown(portalChild)
await waitFor(() => {
expect(screen.getByText(SHORTCUTS_EMPTY_CONTENT)).toBeInTheDocument()
})
portal.remove()
})
// ─── Container / portal ───
it('portals into provided container when container is set', async () => {
render(<MinimalEditor withContainer />)

View File

@ -273,6 +273,9 @@ export default function ShortcutsPopupPlugin({
/* v8 ignore next 2 -- outside-click listener can race with ref cleanup during close/unmount; null-ref path is a safety guard. @preserve */
if (!portalRef.current)
return
const target = e.target as HTMLElement | null
if (target?.closest('[data-base-ui-portal]'))
return
if (!portalRef.current.contains(e.target as Node))
closePortal()
}