Tabs (Astro)

Tabs (Astro)

Display long content blocks in a tabbed interface for enhanced readability.

:choco-info: Reference Bootstrap

Choco-theme respects all Bootstrap Tab documentation. Any HTML on the referenced page is valid and will work with choco-theme.

:choco-info: Astro Only Documentation Below

The documentation below covers how to use the <Tab /> Astro Component from choco-astro.

Overview

The scenario keyword for Id's in the examples can be changed to anything, as long as it is consistent. It is important to note that if more than one tabbed interface is present on the page, they can not share the same Id's. Doing so will result in the tabs not working correctly.

Tabs With Anchor Navigation (Default)

By default, when a user clicks on a tab, the url will be appended with the hash so that it can be copied and navigated to. On load, this link will open the selected tab and scroll to it. Click a tab in the example below and inspect the url to see it change.

import TabsPane from '@choco/components/tabs/TabsPane.astro'; import TabsPaneContainer from '@choco/components/tabs/TabsPaneContainer.astro'; import TabsTabContainer from '@choco/components/tabs/TabsTabContainer.astro'; export const tabs1 = [ { id: 'scenario-one', title: 'Scenario 1', isActive: true }, { id: 'scenario-two', title: 'Scenario 2' }, { id: 'scenario-three', title: 'Scenario 3' } ]; Scenario 1 Content Scenario 2 Content Scenario 3 Content

Tabs Without Anchor Navigation

Sometimes, we do not want tabs to be navigatable. To do this, pass in the updateAnchor: false as seen in the example below. Click on the Scenario 5 tab in the example below and notice the hash in the url does not change.

import TabsPane from '@choco/components/tabs/TabsPane.astro'; import TabsPaneContainer from '@choco/components/tabs/TabsPaneContainer.astro'; import TabsTabContainer from '@choco/components/tabs/TabsTabContainer.astro'; export const tabs2 = [ { id: 'scenario-four', title: 'Scenario 4', isActive: true }, { id: 'scenario-two', title: 'Scenario 5', updateAnchor: false } ]; Scenario 4 Content Scenario 5 Content

Trigger Tabs for Chocolatey Versions

Sometimes, multiple tabs in different spots of the page need triggered at the same time. An example of this use case would be on docs.chocolatey.org and separating Chocolatey v1 information from Chocolatey v2. In the example below, clicking the "v2" tab will trigger the other tab container to also navigate to the "v2" tab. This preference is stored as a cookie, and triggered on load as well.

This is achieved by passing in multi="version" to the <TabsTabContainer /> component.

Chocolatey v2 Content Image

Chocolatey v1 Content Image

Chocolatey v2 Content Commands

Chocolatey v1 Content Commands

import TabsPane from '@choco/components/tabs/TabsPane.astro'; import TabsPaneContainer from '@choco/components/tabs/TabsPaneContainer.astro'; import TabsTabContainer from '@choco/components/tabs/TabsTabContainer.astro'; export const tabs3 = [ { id: 'choco-v2-image', title: 'Chocolatey CLI v2.x', isActive: true }, { id: 'choco-v1-image', title: 'Chocolatey CLI v1.x' } ]; Chocolatey v2 Content Image Chocolatey v1 Content Image export const tabs4 = [ { id: 'choco-v2-commands', title: 'Chocolatey CLI v2.x', isActive: true }, { id: 'choco-v1-commands', title: 'Chocolatey CLI v1.x' } ]; Chocolatey v2 Content Commands Chocolatey v1 Content Commands