← All Components
<mth-code-tabs>
Accessible multi-snippet code tab switcher supporting slotted or property-driven tabs, roving keyboard navigation, and copy-to-clipboard.
When NOT to use: Use a lightweight @methane-ui/css layout class instead of a custom element when static CSS suffices.
Live Interactive Preview
Ready · interact with <mth-code-tabs>, or toggle Theme, Direction (LTR/RTL), or props above.
Multi-Framework Playground & Snippets
<script type="module" src="@methane-ui/ui/code-tabs"></script>
<mth-code-tabs show-copy>Example</mth-code-tabs>import '@methane-ui/ui/code-tabs';
import '@methane-ui/react';
export function Example() {
return <mth-code-tabs show-copy>Example</mth-code-tabs>;
}<script setup lang="ts">
import '@methane-ui/ui/code-tabs';
</script>
<template>
<mth-code-tabs show-copy>Example</mth-code-tabs>
</template>import { Component, CUSTOM_ELEMENTS_SCHEMA } from '@angular/core';
import '@methane-ui/ui/code-tabs';
import { MthCodeTabsDirective } from '@methane-ui/angular';
@Component({
standalone: true,
schemas: [CUSTOM_ELEMENTS_SCHEMA],
imports: [MthCodeTabsDirective],
template: `<mth-code-tabs show-copy>Example</mth-code-tabs>`,
})
export class ExampleComponent {}<script lang="ts">
import '@methane-ui/ui/code-tabs';
import MthCodeTabs from '@methane-ui/svelte/MthCodeTabs.svelte';
</script>
<MthCodeTabs show-copy>Example</MthCodeTabs>Properties & Attributes
| Property | Attribute | Type | Default | Description |
|---|---|---|---|---|
value | value | string | "" | Active tab identifier. |
label | label | string | "" | Accessible label for the internal tablist. |
tabs | — | ReadonlyArray<unknown> | null | null | Optional programmatic array of code tab definitions. |
showCopy | show-copy | boolean | true | Whether to display the copy-to-clipboard button. |
Events
| Event | Detail Type | Description |
|---|---|---|
mth-change | { value: string } | Dispatched when the active code tab changes. |
mth-copy | { value: string; code: string; ok: boolean } | Dispatched after the copy button copies or attempts to copy the active snippet. |
APG Keyboard Matrix
| Key | Direction | When | Expected Behavior |
|---|---|---|---|
| ArrowRight | ltr | A code tab has focus | Moves focus and activates the next code tab |
| ArrowLeft | rtl | A code tab has focus in RTL | Moves focus and activates the next code tab |
| Home | both | Any code tab has focus | Moves focus and activates the first code tab |
| End | both | Any code tab has focus | Moves focus and activates the last code tab |
Accessibility Checklist
| Category | Requirement | Verified By |
|---|---|---|
| aria | All aria-* IDREFs resolve within the same DOM root (ADR-003). | scanSameRootAria |
| focus | delegatesFocus: true with zero host internals.role (ADR-014). | lint-plugin & spec-compiler |
| contrast | Renders legible borders, focus outlines, and selection indicators under forced-colors: active. | Playwright forced-colors matrix |
| keyboard | Implements all 4 APG keyboard transitions across LTR/RTL. | mth-code-tabs.spec.test.ts |
| i18n | Routes 7 UI/ARIA strings through @methane-ui/core i18n catalog. | Locale context test |