Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow Toggleable Layout to be visible by default #1066

Closed
its-ratikant opened this issue Feb 12, 2021 · 3 comments
Closed

Allow Toggleable Layout to be visible by default #1066

its-ratikant opened this issue Feb 12, 2021 · 3 comments

Comments

@its-ratikant
Copy link

Hi,

Can you please give me some hints on how to show or hide toggleable layout nav programmatically or by default open mode?

Thanks!!

@mlaursen
Copy link
Owner

Whoops... I think I'll need to add some more props to the layout to make this easier to work with in the future as well as some more Layout examples. However, you can implement this somewhat for now by using the useLayoutConfig hook in a child component of the Layout.

The only downside to this approach is that if the user resizes from a non-toggleable layout to the toggleable layout, it will still animate in since the it is temporarily set to hidden.

Here's a quick codesandbox for it and below is the code that handles the visibility:

const { showNav, visible, layout } = useLayoutConfig();

const firstRender = useRef(true);
const prevLayout = useRef(layout);
if (firstRender.current || layout !== prevLayout.current) {
  // if it's the first render OR the layout has changed, need to see if the
  // current layout is toggleable and make sure that it is visible
  prevLayout.current = layout;
  firstRender.current = false;
  if (!visible && isToggleableLayout(layout)) {
    showNav();
  }
}

@mlaursen
Copy link
Owner

I think I'll add a new prop: defaultToggleableVisible to help with this. If it is set to true, the toggleable layout will start as visible instead of hidden.

@mlaursen mlaursen changed the title Info: programmatically show/hide togglable layout navigation Allow Toggleable Layout to be visible by default Feb 12, 2021
@mlaursen mlaursen added this to the v2.6.0 milestone Feb 12, 2021
@its-ratikant
Copy link
Author

Perfect! Thanks a lot!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants