question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Switching drawer variants dynamically at runtime

See original GitHub issue

Hi,

I was wondering if you have any opinion on using drawers dynamically. I would like to use temporary for mobile, persistent for tablet and permanent for desktop.

However, a single drawer types class seems to be used throughout the contents of the drawer. For example in a persistent drawer as seen here I can count mdc-persistent-drawer__drawer, mdc-persistent-drawer__toolbar-spacer and mdc-persistent-drawer--selected all used in different child components of the parent mdc-persistent-drawer.

Doesn’t this make switching from one drawer type to another really difficult? Maybe you have some tips on how to solve a problem like this.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:3
  • Comments:8 (4 by maintainers)

github_iconTop GitHub Comments

3reactions
acdvorakcommented, Jan 17, 2019

Reopening this issue because it was brought up in https://github.com/material-components/material-components-web-codelabs/issues/78, and seems like a fairly common use case.

2reactions
cforsyth68commented, Sep 21, 2021

Not sure if this will help, but I came up with a different solution (@mui v5), please let me know what you think.

Here’s the codesandbox: https://codesandbox.io/s/responsivedrawer-material-demo-2-hnu6g

Key aspects:

import { useTheme } from "@mui/material/styles";
import useMediaQuery from "@mui/material/useMediaQuery";
//...
const theme = useTheme();
const isGreaterThanSmallBreakpoint = useMediaQuery(
  theme.breakpoints.up("sm")
);
//...
<Drawer 
   variant={isGreaterThanSmallBreakpoint ? "permanent" : "temporary"}
   //...
 /> 
Read more comments on GitHub >

github_iconTop Results From Across the Web

Drawer Navigation - Change list of items dynamically after ...
How can I change the list of options inside the drawer on runtime, after it was created? DrawerMainActivity.java Layout(template Navigation ...
Read more >
Drawer - How to change content dynamically
I want to use a devextreme widget that can contain a dynamic HTML content using devextreme components like dxbutton,dxcheckbox…
Read more >
Advanced techniques in Chakra UI - LogRocket Blog
Creating dynamic SVGs. When creating different themes for your website, you may want to dynamically change your SVGs to fit the current theme....
Read more >
Interact programmatically with the Navigation component
Programmatically create and interact with certain navigation ... You can modify an inflated navigation graph dynamically at runtime.
Read more >
Property Drawers - Unity - Manual
Now that you have the attribute, you need to make a Property Drawer that draws properties that have that attribute. The drawer must...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found