Skip to main content

Overview

The CodeGroup plugin allows you to create tabbed code blocks, perfect for showing the same code in different languages or displaying multiple related files. Each tab can have its own language and syntax highlighting.

Installation

Basic Usage

Pass the plugin to createYooptaEditor; do not pass plugins to <YooptaEditor>.

Features

  • Multiple Tabs: Display code in multiple tabs
  • Syntax Highlighting: Powered by Shiki
  • Per-Tab Languages: Each tab can have different language
  • Active Tab State: Track which tab is active
  • Theme Support: Consistent theming across tabs

Structure

The CodeGroup plugin consists of nested elements:

Configuration

Options

string
default:"github-dark"
Shiki theme for all code blocks in the group
object

Element Props

code-group-container

string | null
ID of the currently active tab
string
default:"github-dark"
Theme for all code blocks

code-group-content

string | null
ID linking content to its tab heading
string
default:"typescript"
Programming language for this code block

Commands

addTabItem

Add a new tab to the code group.

Keyboard Behavior

  • Enter on Tab Heading: Creates a new tab
  • Enter in Code Content: Inserts newline (not a new block)
  • Backspace: Prevents deletion at content start
  • Cmd/Ctrl+A: Selects entire code content

Initial Structure

When created, the plugin initializes with:

Custom Rendering

Use Cases

Multi-Language Examples

Show same code in JavaScript, Python, Go, etc.

Related Files

Display multiple files that work together

Before/After

Show code before and after refactoring

API Responses

Different response formats (JSON, XML, etc.)

Best Practices

Use descriptive names for tabs (e.g., “package.json”, “server.ts”)
Group related code in logical language combinations
Keep number of tabs reasonable (2-5) for better UX
Ensure code in different tabs is related or equivalent