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 ,
@@ -22,6 +23,9 @@ import { parts } from "./menu.anatomy"
2223import * as dom from "./menu.dom"
2324import type { ItemProps , ItemState , MenuApi , MenuSchema , OptionItemProps , OptionItemState } from "./menu.types"
2425
26+ // We need to avoid mixing framework-agnostic logic with framework-specific prop handling
27+ const identityProps = createNormalizer < PropTypes > ( ( v ) => v )
28+
2529export function connect < T extends PropTypes > ( service : Service < MenuSchema > , normalize : NormalizeProps < T > ) : MenuApi < T > {
2630 const { context, send, state, computed, prop, scope } = service
2731
@@ -61,11 +65,12 @@ export function connect<T extends PropTypes>(service: Service<MenuSchema>, norma
6165 }
6266 }
6367
64- function getItemProps ( props : ItemProps ) {
68+ function getItemProps ( props : ItemProps , normalized = true ) {
6569 const { closeOnSelect, valueText, value } = props
6670 const itemState = getItemState ( props )
6771 const id = dom . getItemId ( scope , value )
68- return normalize . element ( {
72+
73+ const itemProps = identityProps . element ( {
6974 ...parts . item . attrs ,
7075 id,
7176 role : "menuitem" ,
@@ -110,6 +115,8 @@ export function connect<T extends PropTypes>(service: Service<MenuSchema>, norma
110115 send ( { type : "ITEM_CLICK" , target, id, closeOnSelect } )
111116 } ,
112117 } )
118+
119+ return normalized ? normalize . element ( itemProps ) : itemProps
113120 }
114121
115122 return {
@@ -177,12 +184,13 @@ export function connect<T extends PropTypes>(service: Service<MenuSchema>, norma
177184 } ,
178185
179186 getTriggerItemProps ( childApi ) {
180- const triggerProps = childApi . getTriggerProps ( )
181- return mergeProps ( getItemProps ( { value : triggerProps . id } ) , triggerProps ) as T [ "element" ]
187+ const triggerProps = childApi . getTriggerProps ( false )
188+ const itemProps = getItemProps ( { value : triggerProps . id } , false )
189+ return normalize . element ( mergeProps ( itemProps , triggerProps ) )
182190 } ,
183191
184- getTriggerProps ( ) {
185- return normalize . button ( {
192+ getTriggerProps ( normalized = true ) {
193+ const triggerProps = identityProps . button ( {
186194 ...( isSubmenu ? parts . triggerItem . attrs : parts . trigger . attrs ) ,
187195 "data-placement" : context . get ( "currentPlacement" ) ,
188196 type : "button" ,
@@ -256,6 +264,8 @@ export function connect<T extends PropTypes>(service: Service<MenuSchema>, norma
256264 }
257265 } ,
258266 } )
267+
268+ return normalized ? normalize . button ( triggerProps ) : triggerProps
259269 } ,
260270
261271 getIndicatorProps ( ) {
0 commit comments