Skip to content

fix(sender): support formatResult for content slot type - #1986

Merged
kimteayon merged 1 commit into
ant-design:mainfrom
wenzeyu8888-rgb:fix/sender-content-format-result
Jul 21, 2026
Merged

fix(sender): support formatResult for content slot type#1986
kimteayon merged 1 commit into
ant-design:mainfrom
wenzeyu8888-rgb:fix/sender-content-format-result

Conversation

@wenzeyu8888-rgb

@wenzeyu8888-rgb wenzeyu8888-rgb commented Jul 17, 2026

Copy link
Copy Markdown
Contributor

Issue

Closes #1956

🎓 OSS26 轻训营 · 个人认领题(Good First Issue)
关联原始 issue:#1638

Background

In slot mode, the source code made a special case for content type slots, skipping the formatResult formatting logic. This caused content slots to return raw textContent instead of a formatted value, making them inconsistent with other slot types (input, select, tag, custom) which all honor formatResult.

Problem

In packages/x/components/sender/hooks/use-slot-config-state.ts (~L171), the getNodeTextValue function short-circuited on content type:

if (!slotConfig || slotConfig.type === 'content') {
  return textContent;  // ← bypassed formatResult
}

Solution

Removed the special-case early return for content type. Now content slots go through the same formatResult pipeline as other types, using the DOM textContent as the input value (since content slots are contenteditable and their live value lives in the DOM, not in state).

if (!slotConfig) {
  return textContent;
}
const slotValue =
  slotConfig.type === 'content' ? textContent : (stateRef.current[slotKey] ?? ''
return slotConfig.formatResult?.(slotValue) ?? slotValue;

Acceptance Criteria

  • slot + formatResult demo
  • Unit test asserting content is correctly formatted by formatResult
  • Updated documentation

Changes

File Change
hooks/use-slot-config-state.ts Core fix: route content type through formatResult
__tests__/use-slot-config-state.test.ts 3 new unit tests for content + formatResult
__tests__/slot.test.tsx 2 new component integration tests
demo/slot-format-result.tsx + .md New demo showcasing formatResult on content/select slots
index.zh-CN.md / index.en-US.md Updated API docs & demo index

Test Results

All 195 sender tests passed (0 failures).

Summary by CodeRabbit

  • 新功能

    • formatResult 现支持格式化所有词槽类型,包括内容词槽。
    • 新增词槽格式化示例,可查看格式化后的读取值和提交结果。
  • 文档

    • 更新 Sender 文档,补充 formatResult 的适用范围及示例说明。
  • Bug 修复

    • 修复内容词槽配置 formatResult 时未应用格式化结果的问题。

Previously, the  function in
short-circuited on  type slots, returning raw  and
bypassing . This made  slots inconsistent with
other slot types (input, select, tag, custom) which all honor .

This fix removes the special-case early return for  type and
routes it through the same  pipeline, using the DOM
 as the input value (since content slots are
contenteditable and their live value lives in the DOM, not in state).

Changes:
- Modified  to apply  to content type
- Added unit tests in
- Added component integration tests in
- Added demo  showcasing formatResult on content slots
- Updated API docs in  and

Closes ant-design#1956
@dosubot dosubot Bot added documentation Improvements or additions to documentation javascript Pull requests that update Javascript code labels Jul 17, 2026
@coderabbitai

coderabbitai Bot commented Jul 17, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 64a2d333-c54b-4971-b742-c4abc46e6626

📥 Commits

Reviewing files that changed from the base of the PR and between 17db20b and e7e6643.

⛔ Files ignored due to path filters (2)
  • packages/x/components/sender/__tests__/__snapshots__/demo-extend.test.ts.snap is excluded by !**/*.snap
  • packages/x/components/sender/__tests__/__snapshots__/demo.test.ts.snap is excluded by !**/*.snap
📒 Files selected for processing (7)
  • packages/x/components/sender/__tests__/slot.test.tsx
  • packages/x/components/sender/__tests__/use-slot-config-state.test.ts
  • packages/x/components/sender/demo/slot-format-result.md
  • packages/x/components/sender/demo/slot-format-result.tsx
  • packages/x/components/sender/hooks/use-slot-config-state.ts
  • packages/x/components/sender/index.en-US.md
  • packages/x/components/sender/index.zh-CN.md

📝 Walkthrough

Walkthrough

Sender 的 content 插槽现在会应用 formatResult。变更包含取值逻辑、单元测试、格式化演示页面,以及中英文文档更新。

Changes

Sender content 格式化

Layer / File(s) Summary
content 取值与格式化
packages/x/components/sender/hooks/use-slot-config-state.ts, packages/x/components/sender/__tests__/*
content 插槽从 DOM 获取文本后统一经过 formatResult;测试覆盖格式化、原始文本和 DOM 优先取值。
格式化功能演示
packages/x/components/sender/demo/slot-format-result.*
新增示例,展示多个插槽的格式化结果、getValue() 读取和提交反馈。
示例与 API 文档
packages/x/components/sender/index.*.md
新增格式化示例,并说明 formatResult 适用于包括 content 在内的所有插槽类型。

Estimated code review effort: 3 (Moderate) | ~20 minutes

Sequence Diagram(s)

sequenceDiagram
  participant User
  participant Sender
  participant getNodeTextValue
  participant formatResult
  User->>Sender: 编辑 content 插槽
  User->>Sender: 点击 Get Value 或提交
  Sender->>getNodeTextValue: 读取插槽值
  getNodeTextValue->>formatResult: 格式化 content 值
  formatResult-->>Sender: 返回格式化文本
  Sender-->>User: 展示 getValue 或提交结果
Loading

Possibly related PRs

  • ant-design/x#1981:同样更新 content 插槽的 formatResult 处理、测试、示例和文档。

Suggested labels: bug

Poem

小兔蹦蹦改代码,
content 也戴上格式帽。
方括号里藏新意,
getValue 轻轻报到。
测试文档齐欢笑。

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed 标题简洁且准确概括了本次修复的核心:为 Sender 的 content slot 支持 formatResult。
Linked Issues check ✅ Passed 实现了 #1956 的核心需求:content slot 现已走 formatResult,并补充了 demo、单测和文档。
Out of Scope Changes check ✅ Passed 未见明显越界修改,新增内容均围绕 content slot 的 formatResult 支持、测试、演示和文档更新。
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@wenzeyu8888-rgb

Copy link
Copy Markdown
Contributor Author

#1956

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request enables the 'formatResult' option to apply to all slot types, including the 'content' type, in the 'Sender' component. Previously, 'content' type slots bypassed 'formatResult' and returned raw text content. The changes update 'useSlotConfigState' to retrieve the DOM text content for 'content' slots and pass it through 'formatResult' if defined. Additionally, a new demo ('slot-format-result'), corresponding documentation updates, and comprehensive unit tests have been added to verify this behavior. There are no review comments, so I have no feedback to provide on reviewer comments.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

@dosubot dosubot Bot added the lgtm This PR has been approved by a maintainer label Jul 21, 2026
@kimteayon
kimteayon merged commit be739c5 into ant-design:main Jul 21, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation javascript Pull requests that update Javascript code lgtm This PR has been approved by a maintainer

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Good First Issue] Sender 词槽(slot)模式的 content 支持 formatResult

2 participants