ant-design Additional Properties for MenuItem

z9ju0rcb  于 3个月前  发布在  其他
关注(0)|答案(1)|浏览(39)

What problem does this feature solve?

I want to use the Menu component in ways, where I generate items based on other data and have custom actions, that should happen, when such an item is clicked.
The natural way for me, would be to assign an action handler (or click handler) to each item. This handler could be called from the onClick method of menu component since it passes the item.
The problem is that the MenuItem does not support additional properties (TS throws an error about this). I think it would be nice to either be able to add arbitrary properties to MenuItem or to make Menu component generic and pass type of menu item as generic parameter. I guess that the solution with arbitrary additional fields is very easy to implement and does not have any danger of breaking other functionality.

The current workaround is to cast to "any", which is OK but not so nice. Another workaround is to maintain a separate index for metadata based on item key and then retrieve this data in the onClick handler. But all of this is rather extra code.

What does the proposed API look like?

Add { [key:string]: any} or { onClick: ({ item, key, keyPath, domEvent }) => void } to the MenuItem

yiytaume

yiytaume1#

Actually, casting to any does not work because apparently it is not the original item that is passed into the menu click handler.

相关问题