Skip to content

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

TypeScript

docs(Tokenizer, PowerSearch): document and test the existing startIcon prop (#4262)

Ojas Mutreja3cbbe6652e1e
diff --git a/.changeset/docs-tokenizer-powersearch-document-and-test-the-jmwj.md b/.changeset/docs-tokenizer-powersearch-document-and-test-the-jmwj.md
new file mode 100644
index 0000000000..74b1abbc30
--- /dev/null
+++ b/.changeset/docs-tokenizer-powersearch-document-and-test-the-jmwj.md
@@ -0,0 +1,8 @@
+---
+'@astryxdesign/core': patch
+---
+
+[docs] docs(Tokenizer, PowerSearch): document and test the existing startIcon prop
+@HelloOjasMutreja
+
+Both components have shipped a working `startIcon?: ReactNode | IconType` prop for a while (`PowerSearch` forwards it verbatim to the internal `Tokenizer`, and it's already exercised in Storybook), but neither's `.doc.mjs` documented it and neither had test coverage — so it was invisible to `astryx component <Name> --dense`, the docsite props table, and anyone (human or AI) relying on those as the source of truth. No behavior change; adds the missing props-table entries (en/zh/dense) and colocated tests confirming the icon renders and forwards correctly.
diff --git a/packages/core/src/PowerSearch/PowerSearch.doc.mjs b/packages/core/src/PowerSearch/PowerSearch.doc.mjs
index 5f9d388713..ff22d7ebbc 100644
--- a/packages/core/src/PowerSearch/PowerSearch.doc.mjs
+++ b/packages/core/src/PowerSearch/PowerSearch.doc.mjs
@@ -83,6 +83,13 @@ export const docs = {
description:
'Validation status object with type and optional message.',
},
+ {
+ name: 'startIcon',
+ type: 'ReactNode | IconType',
+ description:
+ 'Icon to display at the start of the input, before any filter tokens. Forwarded to the internal Tokenizer. Accepts a semantic icon name, an SVG icon component, or a ReactNode directly.',
+ slotElements: [{__element: 'Icon', props: {icon: 'search', size: 'sm'}}],
+ },
{
name: 'maxTokenLength',
type: 'number',
@@ -235,6 +242,12 @@ export const docsZh = {
type: "{type: 'warning' | 'error' | 'success', message?: string}",
description: '带有类型和可选消息的验证状态对象。',
},
+ {
+ name: 'startIcon',
+ type: 'ReactNode | IconType',
+ description:
+ '在输入框开头(筛选 token 之前)显示的图标,转发给内部的 Tokenizer。接受语义图标名称、SVG 图标组件或直接传入 ReactNode。',
+ },
{
name: 'maxTokenLength',
type: 'number',
@@ -318,6 +331,7 @@ export const docsDense = {
isReadOnly: 'Prevent adding, editing, or removing filters.',
isDisabled: 'Disables entire component.',
status: 'Validation status object w/ type + optional message.',
+ startIcon: 'Icon at input start, before filter tokens. Forwarded to internal Tokenizer.',
maxTokenLength: 'Max char length for filter value display in tokens.',
popoverSaveButtonLabel: 'Label for save button in edit popover.',
timezoneID: 'Timezone ID for date formatting (e.g. "America/New_York").',
diff --git a/packages/core/src/PowerSearch/PowerSearch.test.tsx b/packages/core/src/PowerSearch/PowerSearch.test.tsx
index a0c5a368d0..96d50c10b0 100644
--- a/packages/core/src/PowerSearch/PowerSearch.test.tsx
+++ b/packages/core/src/PowerSearch/PowerSearch.test.tsx
@@ -16,6 +16,7 @@ import userEvent from '@testing-library/user-event';
import {PowerSearch} from './PowerSearch';
import {__resetLiveRegionsForTest} from '../hooks/useAnnounce';
import type {PowerSearchConfig, PowerSearchFilter} from './types';
+import {TestIcon} from '../__tests__/TestIcon';
// =============================================================================
// Test infrastructure
@@ -157,6 +158,25 @@ describe('PowerSearch', () => {
expect(screen.getByRole('combobox')).toHaveFocus();
});
+ describe('startIcon', () => {
+ it('does not render a start icon when omitted', () => {
+ render(<PowerSearch config={config} filters={[]} onChange={() => {}} />);
+ expect(document.querySelector('svg')).not.toBeInTheDocument();
+ });
+
+ it('forwards startIcon to the internal Tokenizer', () => {
+ render(
+ <PowerSearch
+ config={config}
+ filters={[]}
+ onChange={() => {}}
+ startIcon={<TestIcon data-testid="start-icon" />}
+ />,
+ );
+ expect(screen.getByTestId('start-icon')).toBeInTheDocument();
+ });
+ });
+
describe('paste behavior', () => {
it('pasting a field name shows matching field suggestions', async () => {
const user = userEvent.setup();
diff --git a/packages/core/src/Tokenizer/Tokenizer.doc.mjs b/packages/core/src/Tokenizer/Tokenizer.doc.mjs
index e6d9d6d1d1..bda860352e 100644
--- a/packages/core/src/Tokenizer/Tokenizer.doc.mjs
+++ b/packages/core/src/Tokenizer/Tokenizer.doc.mjs
@@ -165,6 +165,13 @@ export const docs = {
type: '(query: string) => void',
description: 'Callback fired when the search query text changes.',
},
+ {
+ name: 'startIcon',
+ type: 'ReactNode | IconType',
+ description:
+ 'Icon to display at the start of the input, before any tokens. Accepts a semantic icon name, an SVG icon component, or a ReactNode directly.',
+ slotElements: [{__element: 'Icon', props: {icon: 'search', size: 'sm'}}],
+ },
{
name: 'endContent',
type: 'ReactNode',
@@ -370,6 +377,12 @@ export const docsZh = {
type: '(query: string) => void',
description: '\u641c\u7d22\u67e5\u8be2\u6587\u672c\u53d8\u66f4\u65f6\u89e6\u53d1\u7684\u56de\u8c03\u3002',
},
+ {
+ name: 'startIcon',
+ type: 'ReactNode | IconType',
+ description:
+ '\u5728\u8f93\u5165\u6846\u5f00\u5934\uff08token \u4e4b\u524d\uff09\u663e\u793a\u7684\u56fe\u6807\u3002\u63a5\u53d7\u8bed\u4e49\u56fe\u6807\u540d\u79f0\u3001SVG \u56fe\u6807\u7ec4\u4ef6\u6216\u76f4\u63a5\u4f20\u5165 ReactNode\u3002',
+ },
{
name: 'endContent',
type: 'ReactNode',
@@ -460,6 +473,7 @@ export const docsDense = {
size: 'Input+token size.',
debounceMs: 'Search debounce delay ms. 0 for sync sources.',
onChangeQuery: 'Fired on search query text change.',
+ startIcon: 'Icon at input start, before tokens. Icon name, SVG component, or ReactNode.',
endContent: 'Content at input row end. For buttons, counts, controls.',
handleRef: 'Imperative handle for focus() and blur() control.',
xstyle: 'StyleX layout styles (margins, positioning). Must be stylex.create() value.',
diff --git a/packages/core/src/Tokenizer/Tokenizer.test.tsx b/packages/core/src/Tokenizer/Tokenizer.test.tsx
index 9f201217f5..c096e00e40 100644
--- a/packages/core/src/Tokenizer/Tokenizer.test.tsx
+++ b/packages/core/src/Tokenizer/Tokenizer.test.tsx
@@ -15,6 +15,7 @@ import userEvent from '@testing-library/user-event';
import {Tokenizer} from './Tokenizer';
import {__resetLiveRegionsForTest} from '../hooks/useAnnounce';
import type {SearchSource, SearchableItem} from '../Typeahead/types';
+import {TestIcon} from '../__tests__/TestIcon';
function politeRegion(): HTMLElement | null {
return document.querySelector('[data-astryx-live-region="polite"]');
@@ -827,6 +828,51 @@ describe('Tokenizer', () => {
});
});
+ describe('startIcon', () => {
+ it('does not render a start icon when omitted', () => {
+ render(
+ <Tokenizer
+ label="Members"
+ searchSource={userSource}
+ value={[]}
+ onChange={() => {}}
+ />,
+ );
+ expect(document.querySelector('svg')).not.toBeInTheDocument();
+ });
+
+ it('renders a ReactNode start icon before the tokens', () => {
+ render(
+ <Tokenizer
+ label="Members"
+ searchSource={userSource}
+ value={[{id: '1', label: 'Alice'}]}
+ onChange={() => {}}
+ startIcon={<TestIcon data-testid="start-icon" />}
+ />,
+ );
+ const icon = screen.getByTestId('start-icon');
+ const token = screen.getByText('Alice');
+ expect(icon).toBeInTheDocument();
+ expect(
+ icon.compareDocumentPosition(token) & Node.DOCUMENT_POSITION_FOLLOWING,
+ ).toBeTruthy();
+ });
+
+ it('renders an IconType (SVG component) start icon', () => {
+ render(
+ <Tokenizer
+ label="Members"
+ searchSource={userSource}
+ value={[]}
+ onChange={() => {}}
+ startIcon={TestIcon}
+ />,
+ );
+ expect(document.querySelector('svg')).toBeInTheDocument();
+ });
+ });
+
describe('disabledMessage', () => {
const h = {hidden: true} as const;
const isOpen = (el: Element) => el.matches(':popover-open');