fix backward compat of menu api (#1925)
This commit is contained in:
parent
85937c2369
commit
837549bf6e
@ -4,6 +4,7 @@ from __future__ import annotations
|
|||||||
from typing import Any, List, Optional, Union
|
from typing import Any, List, Optional, Union
|
||||||
|
|
||||||
from reflex.components.component import Component
|
from reflex.components.component import Component
|
||||||
|
from reflex.components.forms.button import Button
|
||||||
from reflex.components.libs.chakra import ChakraComponent
|
from reflex.components.libs.chakra import ChakraComponent
|
||||||
from reflex.vars import Var
|
from reflex.vars import Var
|
||||||
|
|
||||||
@ -96,10 +97,13 @@ class Menu(ChakraComponent):
|
|||||||
children = []
|
children = []
|
||||||
|
|
||||||
if button:
|
if button:
|
||||||
children.append(MenuButton.create(button))
|
if not isinstance(button, (MenuButton, Button)):
|
||||||
|
children.append(MenuButton.create(button))
|
||||||
|
else:
|
||||||
|
children.append(button)
|
||||||
if not items:
|
if not items:
|
||||||
items = []
|
items = []
|
||||||
children.append(MenuList.create(*items))
|
children.append(MenuList.create(items=items))
|
||||||
return super().create(*children, **props)
|
return super().create(*children, **props)
|
||||||
|
|
||||||
|
|
||||||
@ -124,20 +128,25 @@ class MenuList(ChakraComponent):
|
|||||||
tag = "MenuList"
|
tag = "MenuList"
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def create(cls, *children, **props) -> ChakraComponent:
|
def create(
|
||||||
|
cls, *children, items: Optional[list] = None, **props
|
||||||
|
) -> ChakraComponent:
|
||||||
"""Create a MenuList component, and automatically wrap in MenuItem if not already one.
|
"""Create a MenuList component, and automatically wrap in MenuItem if not already one.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
*children: The children of the component.
|
*children: The children of the component.
|
||||||
|
items: A list of item to add as child of the component.
|
||||||
**props: The properties of the component.
|
**props: The properties of the component.
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
The MenuList component.
|
The MenuList component.
|
||||||
"""
|
"""
|
||||||
if len(children) != 0:
|
if len(children) == 0:
|
||||||
|
if items is None:
|
||||||
|
items = []
|
||||||
children = [
|
children = [
|
||||||
child if isinstance(child, MenuItem) else MenuItem.create(child)
|
child if isinstance(child, MenuItem) else MenuItem.create(child)
|
||||||
for child in children
|
for child in items
|
||||||
]
|
]
|
||||||
return super().create(*children, **props)
|
return super().create(*children, **props)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user