11import type { Service } from "@zag-js/core"
22import { mergeProps } from "@zag-js/core"
3+ import { createNormalizer } from "@zag-js/types"
34import {
45 ariaAttr ,
56 dataAttr ,
@@ -23,6 +24,9 @@ import { parts } from "./menu.anatomy"
2324import * as dom from "./menu.dom"
2425import type { ItemProps , ItemState , MenuApi , MenuSchema , OptionItemProps , OptionItemState } from "./menu.types"
2526
27+ // We need to avoid mixing framework-agnostic logic with framework-specific prop handling
28+ const identityProps = createNormalizer < PropTypes > ( ( v ) => v )
29+
2630export function connect < T extends PropTypes > ( service : Service < MenuSchema > , normalize : NormalizeProps < T > ) : MenuApi < T > {
2731 const { context, send, state, computed, prop, scope } = service
2832
@@ -62,11 +66,12 @@ export function connect<T extends PropTypes>(service: Service<MenuSchema>, norma
6266 }
6367 }
6468
65- function getItemProps ( props : ItemProps ) {
69+ function getItemProps ( props : ItemProps , normalized = true ) {
6670 const { closeOnSelect, valueText, value } = props
6771 const itemState = getItemState ( props )
6872 const id = dom . getItemId ( scope , value )
69- return normalize . element ( {
73+
74+ const itemProps = identityProps . element ( {
7075 ...parts . item . attrs ,
7176 id,
7277 role : "menuitem" ,
@@ -111,6 +116,8 @@ export function connect<T extends PropTypes>(service: Service<MenuSchema>, norma
111116 send ( { type : "ITEM_CLICK" , target, id, closeOnSelect } )
112117 } ,
113118 } )
119+
120+ return normalized ? normalize . element ( itemProps ) : itemProps
114121 }
115122
116123 return {
@@ -178,12 +185,13 @@ export function connect<T extends PropTypes>(service: Service<MenuSchema>, norma
178185 } ,
179186
180187 getTriggerItemProps ( childApi ) {
181- const triggerProps = childApi . getTriggerProps ( )
182- return mergeProps ( getItemProps ( { value : triggerProps . id } ) , triggerProps ) as T [ "element" ]
188+ const triggerProps = childApi . getTriggerProps ( false )
189+ const itemProps = getItemProps ( { value : triggerProps . id } , false )
190+ return normalize . element ( mergeProps ( itemProps , triggerProps ) )
183191 } ,
184192
185- getTriggerProps ( ) {
186- return normalize . button ( {
193+ getTriggerProps ( normalized = true ) {
194+ const triggerProps = identityProps . button ( {
187195 ...( isSubmenu ? parts . triggerItem . attrs : parts . trigger . attrs ) ,
188196 "data-placement" : context . get ( "currentPlacement" ) ,
189197 type : "button" ,
@@ -257,6 +265,8 @@ export function connect<T extends PropTypes>(service: Service<MenuSchema>, norma
257265 }
258266 } ,
259267 } )
268+
269+ return normalized ? normalize . button ( triggerProps ) : triggerProps
260270 } ,
261271
262272 getIndicatorProps ( ) {
0 commit comments