mirror of
https://github.com/facebook/docusaurus.git
synced 2025-08-06 10:20:09 +02:00
fix(v2): Do not automatically change tab when a non-existing option is selected (#2893)
This commit is contained in:
parent
4278cebf67
commit
8aa520c314
2 changed files with 32 additions and 1 deletions
|
@ -26,7 +26,8 @@ function Tabs(props) {
|
||||||
const relevantTabGroupChoice = tabGroupChoices[groupId];
|
const relevantTabGroupChoice = tabGroupChoices[groupId];
|
||||||
if (
|
if (
|
||||||
relevantTabGroupChoice != null &&
|
relevantTabGroupChoice != null &&
|
||||||
relevantTabGroupChoice !== selectedValue
|
relevantTabGroupChoice !== selectedValue &&
|
||||||
|
values.some((value) => value.value === relevantTabGroupChoice)
|
||||||
) {
|
) {
|
||||||
setSelectedValue(relevantTabGroupChoice);
|
setSelectedValue(relevantTabGroupChoice);
|
||||||
}
|
}
|
||||||
|
|
|
@ -348,6 +348,36 @@ You may want choices of the same kind of tabs to sync with each other. For examp
|
||||||
<TabItem value="mac">Use Command + V to paste.</TabItem>
|
<TabItem value="mac">Use Command + V to paste.</TabItem>
|
||||||
</Tabs>
|
</Tabs>
|
||||||
|
|
||||||
|
For all tab groups that have the same `groupId`, the possible values do not need to be the same. If one tab group with chooses an value that does not exist in another tab group with the same `groupId`, the tab group with the missing value won't change its tab. You can see that from the following example. Try to select Linux, and the above tab groups doesn't change.
|
||||||
|
|
||||||
|
```jsx
|
||||||
|
<Tabs
|
||||||
|
groupId="operating-systems"
|
||||||
|
defaultValue="win"
|
||||||
|
values={[
|
||||||
|
{label: 'Windows', value: 'win'},
|
||||||
|
{label: 'macOS', value: 'mac'},
|
||||||
|
{label: 'Linux', value: 'linux'},
|
||||||
|
]}>
|
||||||
|
<TabItem value="win">I am Windows.</TabItem>
|
||||||
|
<TabItem value="mac">I am macOS.</TabItem>
|
||||||
|
<TabItem value="linux">I am Linux.</TabItem>
|
||||||
|
</Tabs>
|
||||||
|
```
|
||||||
|
|
||||||
|
<Tabs
|
||||||
|
groupId="operating-systems"
|
||||||
|
defaultValue="win"
|
||||||
|
values={[
|
||||||
|
{label: 'Windows', value: 'win'},
|
||||||
|
{label: 'macOS', value: 'mac'},
|
||||||
|
{label: 'Linux', value: 'linux'},
|
||||||
|
]}>
|
||||||
|
<TabItem value="win">I am Windows.</TabItem>
|
||||||
|
<TabItem value="mac">I am macOS.</TabItem>
|
||||||
|
<TabItem value="linux">I am Linux.</TabItem>
|
||||||
|
</Tabs>
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
Tab choices with different `groupId`s will not interfere with each other:
|
Tab choices with different `groupId`s will not interfere with each other:
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue