简体   繁体   English

Material UI 选项卡:在选项卡之间切换后,选项卡中的更改将被丢弃

[英]Material UI Tabs: After switch between tabs, changes in tabs discarded

I use material ui tab component.我使用材料 ui 选项卡组件。 after switch between tabs, changes in tabs discarded.In fact, after switching between tabs, the tabs are rendered again.在选项卡之间切换后,选项卡中的更改将被丢弃。实际上,在选项卡之间切换后,选项卡会再次呈现。 Suppose I have a textField in one of the tabs.假设我在其中一个选项卡中有一个 textField。 I enter some inside this textField.我在这个 textField 中输入一些内容。 After going to another tab and returning, the value inside the textField is cleared.转到另一个选项卡并返回后,textField 中的值被清除。 How can I prevent this?我怎样才能防止这种情况发生?

Basically, After switching tabs in Material UI, invisible tabs will be destroyed and removed from DOM.基本上,在 Material UI 中切换选项卡后,不可见的选项卡将被销毁并从 DOM 中删除。 So, You have to write some logics by yourself(And maybe not using TabPanel component).因此,您必须自己编写一些逻辑(并且可能不使用TabPanel组件)。

First -> You need to save the current tab's value in your state首先-> 您需要将当前选项卡的值保存在 state 中

Second -> Create a hidden class第二->创建一个hidden的class

 .hidden { display: none; }

Third -> You need to check if the active tab is the same as index of your tab, you need to assign hidden class to it.第三-> 您需要检查活动选项卡是否与选项卡的索引相同,您需要为其分配hidden的 class。

PS: If you look carefully, the main idea of this method is preventing inactive tabs from displaying not rendering PS:仔细看,这个方法的主要思想是防止inactive tabs显示渲染

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM