diff --git a/packages/x/components/sender/__tests__/slot.test.tsx b/packages/x/components/sender/__tests__/slot.test.tsx index 1dfa46c1c..d6077b8d4 100644 --- a/packages/x/components/sender/__tests__/slot.test.tsx +++ b/packages/x/components/sender/__tests__/slot.test.tsx @@ -29,6 +29,13 @@ const contentSlotConfigWithValue: SlotConfigType = { props: { defaultValue: 'Content Value', placeholder: 'Enter content 2' }, }; +const contentSlotConfigWithFormatResult: SlotConfigType = { + type: 'content', + key: 'content-format', + props: { defaultValue: 'Content Value', placeholder: 'Enter content' }, + formatResult: (value: any) => `<${value}>`, +}; + const selectSlotConfig: SlotConfigType = { type: 'select', key: 'select1', @@ -281,6 +288,14 @@ describe('Sender Slot Component', () => { expect(clearedValue?.slotConfig).toEqual([]); expect(clearedValue?.skill).toBe(undefined); }); + it('should apply formatResult for content slot value', () => { + const ref = createRef(); + render(); + + const fullValue = ref.current?.getValue(); + expect(fullValue?.value).toBe(''); + expect(fullValue?.slotConfig[0].value).toBe(''); + }); describe('ref insert can be used', () => { it('should insert slots default selection range', () => { const ref = createRef(); diff --git a/packages/x/components/sender/demo/slot-filling.tsx b/packages/x/components/sender/demo/slot-filling.tsx index 378db8b5b..4f27923b3 100644 --- a/packages/x/components/sender/demo/slot-filling.tsx +++ b/packages/x/components/sender/demo/slot-filling.tsx @@ -10,6 +10,7 @@ const otherSlotConfig: SlotConfig = [ type: 'content', key: 'location', props: { defaultValue: 'Beijing', placeholder: '[Please enter the location]' }, + formatResult: (value: any) => `destination ${value} `, }, { type: 'text', value: 'by' }, { diff --git a/packages/x/components/sender/index.en-US.md b/packages/x/components/sender/index.en-US.md index d7c34a238..9a2f093ff 100644 --- a/packages/x/components/sender/index.en-US.md +++ b/packages/x/components/sender/index.en-US.md @@ -121,7 +121,7 @@ type ActionsComponents = { | --- | --- | --- | --- | --- | | type | Node type, determines the rendering component type, required | 'text' \| 'input' \| 'select' \| 'tag' \| 'content' \| 'custom' | - | 2.0.0 | | key | Unique identifier, can be omitted when type is text | string | - | - | -| formatResult | Format the final result, applies to all slot types (including `content`) | (value: any) => string | - | 2.0.0 | +| formatResult | Format the final result. Applies to all slot types; for `content` slots, it receives the edited text content. | (value: any) => string | - | 2.0.0 | ##### text node properties diff --git a/packages/x/components/sender/index.zh-CN.md b/packages/x/components/sender/index.zh-CN.md index 73d1cef94..abb2dbaf5 100644 --- a/packages/x/components/sender/index.zh-CN.md +++ b/packages/x/components/sender/index.zh-CN.md @@ -123,7 +123,7 @@ type ActionsComponents = { | --- | --- | --- | --- | --- | | type | 节点类型,决定渲染组件类型,必填 | 'text' \| 'input' \| 'select' \| 'tag' \| 'content' \| 'custom' | - | 2.0.0 | | key | 唯一标识,type 为 text 时可省略 | string | - | - | -| formatResult | 格式化最终结果,对所有词槽类型(含 `content`)生效 | (value: any) => string | - | 2.0.0 | +| formatResult | 格式化最终结果,对所有词槽类型生效;用于 `content` 词槽时,接收编辑后的文本内容。 | (value: any) => string | - | 2.0.0 | ##### text 节点属性