Skip to content

An open source design system that's fully customizable and agent ready

TypeScript

fix(richtext): declare the rich-text-editor theme target's visual props (#6976)

Cindy Zhangbc18d617dbc6
diff --git a/packages/richtext/src/RichTextEditor.doc.mjs b/packages/richtext/src/RichTextEditor.doc.mjs
index a2af3cd302..3508dd504d 100644
--- a/packages/richtext/src/RichTextEditor.doc.mjs
+++ b/packages/richtext/src/RichTextEditor.doc.mjs
@@ -159,7 +159,16 @@ export const docs = {
},
],
theming: {
- targets: [{className: 'astryx-rich-text-editor', visualProps: []}],
+ targets: [
+ {
+ className: 'astryx-rich-text-editor',
+ // RichTextEditor.tsx reflects both through
+ // themeProps('rich-text-editor', {size, status}) as `data-size` and
+ // `data-status`, the same axes TextArea declares for the input visuals
+ // this field container shares.
+ visualProps: ['size', 'status'],
+ },
+ ],
},
usage: {
description:
diff --git a/packages/richtext/src/RichTextEditor.test.tsx b/packages/richtext/src/RichTextEditor.test.tsx
index cc06dcc919..b42c4e4791 100644
--- a/packages/richtext/src/RichTextEditor.test.tsx
+++ b/packages/richtext/src/RichTextEditor.test.tsx
@@ -4,8 +4,8 @@
* @file RichTextEditor.test.tsx
* @input Uses vitest, @testing-library/react, RichTextEditor + RichTextView
* @output Unit tests for the opt-in Lexical editor components, including
- * accessible label wiring, shared input visuals/status variants,
- * placeholder semantics, canonical link-dialog layout, top-toolbar
+ * accessible label wiring, shared input visuals/status variants, theme-target
+ * metadata, placeholder semantics, canonical link-dialog layout, top-toolbar
* ordering and horizontal scrolling, and the read-only vs disabled split
* with editable-state sync across prop toggles
* @position Testing; validates RichTextEditor.tsx and RichTextView.tsx
@@ -46,6 +46,7 @@ import {
NEW_TAB_LINK_ATTRIBUTES,
} from './RichTextEditorAutoLinkPlugin';
import {sanitizeUrl, validateUrl} from './linkUtils';
+import {docs as richTextEditorDoc} from './RichTextEditor.doc.mjs';
// Closed popover-backed tooltips are intentionally hidden from the default
// accessibility tree until their trigger opens them.
@@ -283,6 +284,30 @@ const HELLO_STATE = JSON.stringify({
});
describe('RichTextEditor', () => {
+ it('declares exactly the visual props its theme target reflects', () => {
+ // The core theming guards walk packages/core/src (and Lab) only, so
+ // nothing else compares this package's doc metadata with its
+ // themeProps() call. Set equality fails on drift in either direction: a
+ // reflected axis left undeclared, or a declared axis nothing reflects.
+ const target = richTextEditorDoc.theming?.targets.find(
+ ({className}) => className === 'astryx-rich-text-editor',
+ );
+ const {container} = render(
+ <RichTextEditor label="Notes" size="lg" status={{type: 'error'}} />,
+ );
+ const wrapper = container.querySelector('.astryx-rich-text-editor');
+ expect(wrapper).not.toBeNull();
+
+ const reflected = [...(wrapper?.attributes ?? [])]
+ .filter(({name}) => name.startsWith('data-'))
+ .map(({name}) => name.slice('data-'.length))
+ .sort();
+ expect([...(target?.visualProps ?? [])].sort()).toEqual(reflected);
+ // The reflected values are the props, not stale defaults.
+ expect(wrapper).toHaveAttribute('data-size', 'lg');
+ expect(wrapper).toHaveAttribute('data-status', 'error');
+ });
+
it('keeps TextArea-style input visuals alongside consumer props', () => {
const {container} = render(
<RichTextEditor
diff --git a/packages/richtext/src/doc-mjs.d.ts b/packages/richtext/src/doc-mjs.d.ts
new file mode 100644
index 0000000000..4e13637288
--- /dev/null
+++ b/packages/richtext/src/doc-mjs.d.ts
@@ -0,0 +1,23 @@
+// Copyright (c) Meta Platforms, Inc. and affiliates.
+
+/**
+ * @file Ambient module declaration for `*.doc.mjs` imports.
+ *
+ * Package tests import `{Name}.doc.mjs` files directly to assert that their
+ * documented metadata stays in sync with what the component renders (see the
+ * theme-target test in RichTextEditor.test.tsx). Without this declaration,
+ * TypeScript has no way to type a `.mjs` import and the package typecheck
+ * fails with TS7016 ("Could not find a declaration file for module").
+ * Mirrors packages/core/src/doc-mjs.d.ts, which this package cannot see.
+ */
+
+declare module '*.doc.mjs' {
+ import type {
+ ComponentDoc,
+ ComponentTranslationDoc,
+ } from '@astryxdesign/cli/authoring';
+
+ export const docs: ComponentDoc;
+ export const docsZh: ComponentDoc;
+ export const docsDense: ComponentTranslationDoc;
+}