fix menu items= API (#1905)
This commit is contained in:
parent
53d205ad9f
commit
c131f76e33
@ -1,7 +1,7 @@
|
||||
"""Menu components."""
|
||||
from __future__ import annotations
|
||||
|
||||
from typing import Any, List, Union
|
||||
from typing import Any, List, Optional, Union
|
||||
|
||||
from reflex.components.component import Component
|
||||
from reflex.components.libs.chakra import ChakraComponent
|
||||
@ -74,7 +74,13 @@ class Menu(ChakraComponent):
|
||||
}
|
||||
|
||||
@classmethod
|
||||
def create(cls, *children, button=None, items=None, **props) -> Component:
|
||||
def create(
|
||||
cls,
|
||||
*children,
|
||||
button: Optional[Component] = None,
|
||||
items: Optional[List] = None,
|
||||
**props,
|
||||
) -> Component:
|
||||
"""Create a menu component.
|
||||
|
||||
Args:
|
||||
@ -117,6 +123,24 @@ class MenuList(ChakraComponent):
|
||||
|
||||
tag = "MenuList"
|
||||
|
||||
@classmethod
|
||||
def create(cls, *children, **props) -> ChakraComponent:
|
||||
"""Create a MenuList component, and automatically wrap in MenuItem if not already one.
|
||||
|
||||
Args:
|
||||
*children: The children of the component.
|
||||
**props: The properties of the component.
|
||||
|
||||
Returns:
|
||||
The MenuList component.
|
||||
"""
|
||||
if len(children) != 0:
|
||||
children = [
|
||||
child if isinstance(child, MenuItem) else MenuItem.create(child)
|
||||
for child in children
|
||||
]
|
||||
return super().create(*children, **props)
|
||||
|
||||
|
||||
class MenuItem(ChakraComponent):
|
||||
"""The trigger that handles menu selection. Must be a direct child of a MenuList."""
|
||||
|
Loading…
Reference in New Issue
Block a user