Skip to content

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

TypeScript

fix(richtext): document the four RichTextEditor props its doc file omitted (#7610)

Cindy Zhangbf913272638b
diff --git a/.changeset/richtext-editor-doc-field-props.md b/.changeset/richtext-editor-doc-field-props.md
new file mode 100644
index 0000000000..f5c7360c52
--- /dev/null
+++ b/.changeset/richtext-editor-doc-field-props.md
@@ -0,0 +1,7 @@
+---
+'@astryxdesign/richtext': patch
+---
+
+[docs] The `RichTextEditor` docs now list `isOptional`, `isRequired`, `labelTooltip` and `namespace`, four props the editor already accepted, so `astryx component RichTextEditor` and the docsite props table show the Required/Optional indicator, `aria-required`, the label tooltip and the Lexical namespace.
+
+@cixzhang
diff --git a/packages/richtext/src/RichTextEditor.doc.mjs b/packages/richtext/src/RichTextEditor.doc.mjs
index 84f171f1a8..26f4da583c 100644
--- a/packages/richtext/src/RichTextEditor.doc.mjs
+++ b/packages/richtext/src/RichTextEditor.doc.mjs
@@ -36,6 +36,26 @@ export const docs = {
type: 'string',
description: 'Description text displayed between the label and editor.',
},
+ {
+ name: 'isOptional',
+ type: 'boolean',
+ description:
+ 'Displays an "Optional" indicator next to the label. Mutually exclusive with isRequired.',
+ default: 'false',
+ },
+ {
+ name: 'isRequired',
+ type: 'boolean',
+ description:
+ 'Displays a "Required" indicator next to the label and sets aria-required on the editable surface. Mutually exclusive with isOptional.',
+ default: 'false',
+ },
+ {
+ name: 'labelTooltip',
+ type: 'string',
+ description:
+ 'Tooltip text displayed in an info icon at the end of the label.',
+ },
{
name: 'defaultValue',
type: 'string',
@@ -158,6 +178,12 @@ export const docs = {
'Minimum height of the editable content surface. Numbers are pixels; strings are used as CSS lengths. Content continues growing beyond this height.',
default: "'4.5rem'",
},
+ {
+ name: 'namespace',
+ type: 'string',
+ description: 'The Lexical composer namespace, used for editor identity.',
+ default: "'astryx-editor'",
+ },
{
name: 'xstyle',
type: 'StyleXStyles',
diff --git a/packages/richtext/src/RichTextEditor.test.tsx b/packages/richtext/src/RichTextEditor.test.tsx
index 98f8120045..fe82f6cfda 100644
--- a/packages/richtext/src/RichTextEditor.test.tsx
+++ b/packages/richtext/src/RichTextEditor.test.tsx
@@ -33,7 +33,11 @@ import {
} from 'lexical';
import {HeadingNode} from '@lexical/rich-text';
import {TRANSFORMERS, $convertFromMarkdownString} from '@lexical/markdown';
-import {RichTextEditor, type RichTextEditorRef} from './RichTextEditor';
+import {
+ RichTextEditor,
+ type RichTextEditorProps,
+ type RichTextEditorRef,
+} from './RichTextEditor';
import {RichTextView} from './RichTextView';
import {
markdownToEditorStateJSON,
@@ -42,6 +46,7 @@ import {
import {RichTextEditorToolbar} from './RichTextEditorToolbar';
import {registerIcons, resetIcons} from '@astryxdesign/core/Icon';
import {EDGE_COMP_ATTR} from '@astryxdesign/core/Layout';
+import type {BaseProps} from '@astryxdesign/core';
import {Theme, defineTheme} from '@astryxdesign/core/theme';
import {rtlStyles} from '@astryxdesign/core/utils';
import {InternationalizationProvider} from '@astryxdesign/core/i18n';
@@ -289,6 +294,52 @@ const HELLO_STATE = JSON.stringify({
});
describe('RichTextEditor', () => {
+ it('documents every prop the editor declares', () => {
+ // The doc file is what `astryx component RichTextEditor` and the docsite
+ // read, so a prop missing from it is invisible to builders. The compile-time
+ // check below fails when RichTextEditorProps gains a prop this list lacks;
+ // the runtime check fails when the doc file lacks a listed prop.
+ const ownProps = [
+ 'label',
+ 'isLabelHidden',
+ 'description',
+ 'isOptional',
+ 'isRequired',
+ 'defaultValue',
+ 'onChange',
+ 'placeholder',
+ 'isReadOnly',
+ 'isDisabled',
+ 'status',
+ 'statusVariant',
+ 'size',
+ 'nodes',
+ 'toolbar',
+ 'plugins',
+ 'hasMarkdownShortcuts',
+ 'markdownExtensions',
+ 'transformers',
+ 'hasAutoFocus',
+ 'tabEscapeHint',
+ 'maxLength',
+ 'width',
+ 'minHeight',
+ 'labelTooltip',
+ 'namespace',
+ ] as const satisfies ReadonlyArray<keyof RichTextEditorProps>;
+ type Unlisted = Exclude<
+ keyof RichTextEditorProps,
+ keyof BaseProps | 'ref' | (typeof ownProps)[number]
+ >;
+ const everyPropListed: [Unlisted] extends [never] ? true : Unlisted = true;
+ expect(everyPropListed).toBe(true);
+
+ const docProps =
+ 'props' in richTextEditorDoc ? richTextEditorDoc.props : [];
+ const documented = new Set(docProps.map(({name}) => name));
+ expect(ownProps.filter(name => !documented.has(name))).toEqual([]);
+ });
+
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