Drawer auto-close behaviour on 'mobile' mode #3387
-
Hi all, I'm trying to implement the following behaviour:
I've checked the docs and can't really find this specific example, just ones where the page header (that sits above the drawers) contains a 'menu' button that toggles the drawer that sits underneath it. In my case, I use the menu as a list that when an item is selected it shows the content via a refreshable update on the content panel (i.e. I don't navigate just refresh the underlying content which shows the button on top to show the menu again). I thought about:
Thanks for any ideas |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 2 replies
-
Can you, please, share a minimal example of your layout? I'm struggling to reproduce every moving part with all the props and classes you're describing. That's a bit inefficient. Apart from that, there's the possibility to duplicate menu items: You can either hide or show them depending on the screen size and let them behave differently. It's a rather hacky workaround, but might just be what you need. |
Beta Was this translation helpful? Give feedback.
-
Here is what you have at the moment: @ui.refreshable
def content(text: str):
ui.button("Menu", on_click=drawer.toggle).classes("lg:hidden")
ui.label(text)
with ui.left_drawer(bordered=True) as drawer:
ui.button("A", on_click=lambda: content.refresh("A"))
ui.button("B", on_click=lambda: content.refresh("B"))
ui.button("C", on_click=lambda: content.refresh("C"))
content('Hi!') Duplicating the buttons as suggested above would look like this: @ui.refreshable
def content(text: str):
ui.button("Menu", on_click=drawer.toggle).classes("lg:hidden")
ui.label(text)
with ui.left_drawer(bordered=True) as drawer:
with ui.column().classes('max-lg:hidden'):
ui.button("A", on_click=lambda: content.refresh("A"))
ui.button("B", on_click=lambda: content.refresh("B"))
ui.button("C", on_click=lambda: content.refresh("C"))
with ui.column().classes('lg:hidden'):
ui.button("A", on_click=lambda: (content.refresh("A"), drawer.hide()))
ui.button("B", on_click=lambda: (content.refresh("B"), drawer.hide()))
ui.button("C", on_click=lambda: (content.refresh("C"), drawer.hide()))
content('Hi!') I'd be interested in a more elegant solution though. 😄 |
Beta Was this translation helpful? Give feedback.
Here is what you have at the moment:
Duplicating the buttons as suggested above would look like this: