fix(default): support DropdownMenuItem onSelect (#4787)

fix(ui): add onSelect compat wrapper for DropdownMenuItem

Bridges Base UI DropdownMenu with Radix-style onSelect so existing consumers work without migration.
This commit is contained in:
Li Duoyang
2026-05-12 16:23:24 +08:00
committed by GitHub
parent 7fe896d2f8
commit 2b89989f62
4 changed files with 95 additions and 1 deletions
+25
View File
@@ -0,0 +1,25 @@
import type * as React from 'react'
export type DropdownMenuItemSelectEvent = React.MouseEvent<HTMLElement> & {
preventBaseUIHandler?: () => void
}
export type DropdownMenuItemSelectHandler = (
event: DropdownMenuItemSelectEvent
) => void
export function handleDropdownMenuItemSelect(
event: DropdownMenuItemSelectEvent,
onClick?: React.MouseEventHandler<HTMLElement>,
onSelect?: DropdownMenuItemSelectHandler
) {
onClick?.(event)
if (!event.defaultPrevented) {
onSelect?.(event)
}
if (event.defaultPrevented) {
event.preventBaseUIHandler?.()
}
}