From 3c580bb41bc0e71edc64b9431bfda90c26410af7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20Brand=C3=A9ho?= Date: Fri, 9 Jun 2023 21:19:25 +0200 Subject: [PATCH] fix allow_multiple & toggle_toggle conflict (#1175) --- pynecone/components/disclosure/accordion.py | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/pynecone/components/disclosure/accordion.py b/pynecone/components/disclosure/accordion.py index 584ffe99b..c053ee8d7 100644 --- a/pynecone/components/disclosure/accordion.py +++ b/pynecone/components/disclosure/accordion.py @@ -16,7 +16,7 @@ class Accordion(ChakraComponent): allow_multiple: Var[bool] # If true, any expanded accordion item can be collapsed again. - allow_toggle: Var[bool] = True # type: ignore + allow_toggle: Var[bool] # The initial index(es) of the expanded accordion item(s). default_index: Var[Optional[List[int]]] @@ -28,13 +28,23 @@ class Accordion(ChakraComponent): reduce_motion: Var[bool] @classmethod - def create(cls, *children, items=None, icon_pos="right", **props) -> Component: + def create( + cls, + *children, + items=None, + icon_pos="right", + allow_multiple: Optional[Var[bool]] = None, + allow_toggle: Optional[Var[bool]] = None, + **props + ) -> Component: """Create an accordion component. Args: children: The children of the component. items: The items of the accordion component: list of tuples (label,panel) icon_pos: The position of the arrow icon of the accordion. "right", "left" or None + allow_multiple: The allow_multiple property of the accordion. (True or False) + allow_toggle: The allow_toggle property of the accordion. (True or False) props: The properties of the component. Returns: @@ -58,6 +68,12 @@ class Accordion(ChakraComponent): AccordionPanel.create(panel), ) ) + + # if allow_multiple is True, allow_toggle is implicitely used and does not need to be defined + if allow_multiple: + props.update({"allow_multiple": allow_multiple}) + elif allow_toggle: + props.update({"allow_toggle": allow_toggle}) return super().create(*children, **props)