An open source design system that's fully customizable and agent ready
TypeScript
fix(CodeBlock): the collapsed disclosure chevron mirrors in RTL (#9294)
Cindy Zhangc9f16ef38d3e
diff --git a/.changeset/codeblock-rtl-collapse-chevron.md b/.changeset/codeblock-rtl-collapse-chevron.mdnew file mode 100644index 0000000000..ea1da415f7--- /dev/null+++ b/.changeset/codeblock-rtl-collapse-chevron.md@@ -0,0 +1,7 @@+---+'@astryxdesign/core': patch+---++[fix] CodeBlock: in right-to-left layouts the collapsed disclosure chevron now points toward the inline end (left), as other disclosure chevrons do. Expanded, it still points down.++@cixzhangdiff --git a/packages/core/src/CodeBlock/CodeBlock.test.tsx b/packages/core/src/CodeBlock/CodeBlock.test.tsxindex 2e944236fd..ce57449aad 100644--- a/packages/core/src/CodeBlock/CodeBlock.test.tsx+++ b/packages/core/src/CodeBlock/CodeBlock.test.tsx@@ -15,6 +15,7 @@ import {describe, it, expect, vi, beforeEach, afterEach} from 'vitest';import {act, render, screen, fireEvent, waitFor} from '@testing-library/react';import userEvent from '@testing-library/user-event';import {CodeBlock} from './CodeBlock';+import {rtlStyles} from '../utils';import {__resetLiveRegionsForTest} from '../hooks/useAnnounce';import {dracula} from '../theme/syntax';import {InternationalizationProvider} from '../i18n';@@ -290,6 +291,35 @@ describe('CodeBlock', () => {}});+ // design:bidirectionality DR4: the collapsed disclosure chevron points+ // toward the inline end, so it mirrors in RTL. jsdom does not apply the+ // compiled StyleX CSS, so this pins the structure the mirror relies on: the+ // chevron renders inside an element carrying the shared rtlStyles.mirror.+ it('wraps the disclosure chevron in the shared RTL mirror', () => {+ const {className: mirrorClassName} = stylex.props(rtlStyles.mirror);+ const mirrorClasses = mirrorClassName?.split(' ') ?? [];+ expect(mirrorClasses.length).toBeGreaterThan(0);+ render(+ <div dir="rtl">+ <CodeBlock+ code={LONG_CODE}+ language="javascript"+ title="example"+ isCollapsible+ />+ </div>,+ );+ const header = screen+ .getAllByRole('button')+ .find(el => el.hasAttribute('aria-expanded'));+ const chevron = header?.querySelector('.astryx-icon');+ expect(chevron).not.toBeNull();+ const wrapper = chevron?.parentElement;+ for (const className of mirrorClasses) {+ expect(wrapper).toHaveClass(className);+ }+ });+it('does NOT collapse the block when the copy button is clicked', () => {render(<CodeBlockdiff --git a/packages/core/src/CodeBlock/CodeBlock.tsx b/packages/core/src/CodeBlock/CodeBlock.tsxindex 96d665dad6..a412a83adf 100644--- a/packages/core/src/CodeBlock/CodeBlock.tsx+++ b/packages/core/src/CodeBlock/CodeBlock.tsx@@ -32,7 +32,7 @@ import {durationVars,easeVars,} from '../theme/tokens.stylex';-import {isRenderable, mergeProps} from '../utils';+import {isRenderable, mergeProps, rtlStyles} from '../utils';import {useClipboard} from '../hooks/useClipboard';import {useScrollableArea} from '../hooks/useScrollableArea';import {Icon} from '../Icon';@@ -1159,7 +1159,11 @@ export function CodeBlock({stylex.props(styles.headerTitle),)}>{canCollapse && (- <span {...stylex.props(styles.collapseChevron)}>+ // The collapsed chevron points toward the inline end, so it mirrors+ // in RTL (design:bidirectionality DR4). The mirror sits on this box+ // so the glyph's own rotation still eases: rotated down when+ // expanded, a mirrored glyph still points down.+ <span {...stylex.props(styles.collapseChevron, rtlStyles.mirror)}><Iconicon="chevronRight"size="xsm"