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:
@@ -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?.()
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user