Default Tab Selection #4237
-
I am currently looking for a way to disable the default Tab selection from Twilio Paste. The current scenario I have is when I have a Tab selected and it becomes unavailable, it automatically reverts the selected Tab to the most recently selected Tab prior to the current. Is there any way that I can disable this functionality? I can try and provide more context if necessary but would appreciate any help with this. Thank you! |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 6 replies
-
Disclaimer: This is a very experimental bot using OpenAI's GPT-4. The answers may not be correct, a human will review the answer and update it if necessary. Sorry, I don't know how to help with that. I did do a search though, and I managed to find these other Discussions that might be similar or related to your question. Give them a read to see if they answer your question. If they do, head back here and update this discussion and mark it as answered, pointing others to the related discussion:
|
Beta Was this translation helpful? Give feedback.
-
You can programmatically set the selected tab to Here's an example: import {
useTabPrimitiveState,
TabPrimitiveList,
TabPrimitive,
TabPrimitivePanel,
} from '@twilio-paste/core/tabs-primitive';
const Example = () => {
const tab = useTabPrimitiveState();
// Function to deselect the current tab
const deselectTab = () => {
tab.select(null);
};
return (
<>
<TabPrimitiveList {...tab} aria-label="My tabs">
<TabPrimitive {...tab}>Tab 1</TabPrimitive>
<TabPrimitive {...tab}>Tab 2</TabPrimitive>
<TabPrimitive {...tab}>Tab 3</TabPrimitive>
</TabPrimitiveList>
<TabPrimitivePanel {...tab}>Tab 1 Content</TabPrimitivePanel>
<TabPrimitivePanel {...tab}>Tab 2 Content</TabPrimitivePanel>
<TabPrimitivePanel {...tab}>Tab 3 Content</TabPrimitivePanel>
<button onClick={deselectTab}>Deselect Tab</button>
</>
);
}; This code uses the To continue talking to Dosu, mention @dosu. Help Dosu learn! Give it feedback: Great Response | Irrelevant Answer | Incorrect Sources | Too Verbose | Hallucination | Other |
Beta Was this translation helpful? Give feedback.
-
Hi @richiethie, Dosu was on the right track by using the state. We discourage using primitives though as they are unstyled. I have created a working CodeSandbox that when selecting the second tab and then using the disabled button allows you to select any tab you like. Just a note, an active tab is mandatory as a tab panel should always be displayed for the component. The hook utilizes the baseId and "should" append the tab index so set the ids of the tabs. I put it in quotes because in this sandbox, for some reason it is adding 2 to the index. Be sure to use the hook and set it on the component: const { ...tabState } = useTabState({
baseId: "hook-example",
});
<Tabs state={tabState}> The you will be able to use the <Button
variant="primary"
onClick={() => {
// only update the selected tab if you are currently on the one that will be disabled
if (tabState.selectedId === "hook-example-4") {
tabState.select("hook-example-6");
}
setIsSuperNetworkDisabled(!isSuperNetworkDisabled);
}}
>
Toggle Super Network Disabled
</Button> Let us know if this is what you were looking for or you need further help. |
Beta Was this translation helpful? Give feedback.
Hi @richiethie, Dosu was on the right track by using the state. We discourage using primitives though as they are unstyled. I have created a working CodeSandbox that when selecting the second tab and then using the disabled button allows you to select any tab you like. Just a note, an active tab is mandatory as a tab panel should always be displayed for the component.
The hook utilizes the baseId and "should" append the tab index so set the ids of the tabs. I put it in quotes because in this sandbox, for some reason it is adding 2 to the index.
Be sure to use the hook and set it on the component: