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.

Tabs isLazy behavior

See original GitHub issue

🚀 Feature request

Possibly change isLazy behavior to mount on first select and never unmount. If we want to keep the current behavior, consider adding a new prop.

🧱 Problem Statement / Justification

I read through https://github.com/chakra-ui/chakra-ui/issues/1384 to understand the problem isLazy is trying to solve. There are two distinct features asked for in that issue:

  • Do not mount all tabs at once, since they might do data loading.
  • Mark individual tab panels as lazy. This was a later feature request, not added in the linked PR.

The solution to the problem above was to mount on select and unmount on a different tab being selected. I think this can be improved to further reduce data loading.

Currently a lazy tab will unmount whenever it’s unselected, causing it to load data on being selected again. A true lazy tab will only mount once, on first selection. This mount-on-first-selection behavior makes the second feature request above unnecessary.

✅ Proposed solution or API

Pretty simple. Each tab panel has an internal flag (useRef) to keep track of whether it has ever been selected.

  • If it has not been selected and it’s not active, render null
  • Otherwise set the flag to true and render its children as normal.

↩️ Alternatives

If we don’t want to change the isLazy behavior, we could add a new prop.

Can anyone think of a use case where the current behavior is preferred over the one I’m suggesting?

📝 Additional Information

N/A

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:5 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
with-heartcommented, Apr 16, 2021

@stellarhoof No prob! I think what you added probably makes more sense as the default for the reasons you originally provided, but we can’t change that default until we make a major release.

For the time being, once the PR is merged <Tabs isLazy unmountHiddenPanels={false}> will enable the behavior you added

1reaction
stellarhoofcommented, Apr 16, 2021

@with-heart That’s a good point. Thanks for catching that.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Tabs - Chakra UI
A React component that helps you build accessible tabs, by providing keyboard ... of each tab until that tab is selected, you can...
Read more >
Is there a way to force tab unmount in ChakraUI tabs ...
isLazy ={true}. Docs for the lazyBehavior prop say: The lazy behavior of tab panels' content when not active. Only works when isLazy={true}.
Read more >
Stream TABS Early Access OST - Simulation Placement V2 (1) by ...
Stream TABS Early Access OST - Simulation Placement V2 (1) by Mimikyu on desktop and mobile. Play over 265 million tracks for free...
Read more >
All About Laziness: What Causes It and What to Do About It
... percent of Millennials — believe that the typical U.S. citizen is lazy. ... Other researchers have noted that laziness is a behavioral...
Read more >
Browser-level image lazy loading for the web - web.dev
... eager : Default loading behavior of the browser, which is the same as not ... Is lazy loading for iframes also supported...
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