Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions packages/x/components/sender/__tests__/slot.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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<SenderRef>();
render(<Sender slotConfig={[contentSlotConfigWithFormatResult]} ref={ref} />);

const fullValue = ref.current?.getValue();
expect(fullValue?.value).toBe('<Content Value>');
expect(fullValue?.slotConfig[0].value).toBe('<Content Value>');
});
describe('ref insert can be used', () => {
it('should insert slots default selection range', () => {
const ref = createRef<SenderRef>();
Expand Down
1 change: 1 addition & 0 deletions packages/x/components/sender/demo/slot-filling.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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' },
{
Expand Down
2 changes: 1 addition & 1 deletion packages/x/components/sender/index.en-US.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion packages/x/components/sender/index.zh-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 节点属性

Expand Down