- Add syncTabsInOtherGroups function to sync tabs across groups
- When clicking a tab in a named group, all groups with same name sync
- Add E2E test for synchronization behavior
- Update documentation to explain sync purpose and usage
- Add second test fixture for testing sync between groups
Add support for named code groups via the `group-name` parameter in the code-group container syntax. This allows developers to semantically identify and potentially sync code groups across a documentation site.
Add support for named code groups via the `group-name` parameter in the code-group container syntax. This allows **synchronization of tab selections across multiple code groups** with the same name on a page.
## Feature Specification
### Purpose
When multiple code groups share the same `group-name`, selecting a tab in one group automatically selects the corresponding tab in all other groups with the same name. This is useful for documentation that shows the same tool (e.g., package managers) in multiple contexts.
### Markdown Syntax
**Current:**
@ -117,16 +121,49 @@ function createCodeGroup(md: MarkdownItAsync): ContainerArgs {
- No TypeScript interface changes needed (HTML data attributes are dynamic)
- Document the new attribute in JSDoc comments if applicable
### 3. Client-Side Changes (Optional for Future Enhancement)
@ -778,7 +778,7 @@ You can also [import snippets](#import-code-snippets) in code groups:
### Named Code Groups
You can optionally name code groups using the `group-name` parameter. This can be useful for semantic identification and potential future features like syncing tab selections across groups.
You can name code groups to synchronize tab selections across multiple groups. When you have multiple code groups with the same name on a page, selecting a tab in one will automatically select the corresponding tab in all other groups with the same name.
**Input**
@ -797,9 +797,29 @@ pnpm add vitepress
yarn add vitepress
```
:::
Later in the same page:
::: code-group group-name=package-managers
```bash [npm]
npm run docs
```
```bash [pnpm]
pnpm run docs
```
```bash [yarn]
yarn docs
```
:::
````
When you click on a tab (e.g., "pnpm") in one group, all other groups with `group-name=package-managers` will automatically switch to the same tab.
**Output**
::: code-group group-name=package-managers
@ -827,7 +847,7 @@ Valid examples:
- `group-name=installMethods`
::: tip
Named code groups add a `data-group-name` attribute to the generated HTML, which can be useful for custom styling or scripting.
This feature is especially useful in documentation where you show the same tool (like package managers or programming languages) in multiple places, providing a consistent experience for users.