Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
445 commits
Select commit Hold shift + click to select a range
7c159e2
feat: add theme
Sep 11, 2025
27304e2
Merge branch 'feature_markdown' of https://github.com/ant-design/x in…
Sep 11, 2025
fd57c0b
feat: antd
kimteayon Sep 11, 2025
1e47480
Merge branch 'feature_markdown' of https://github.com/ant-design/x in…
kimteayon Sep 11, 2025
9b8e92f
fix: fix test case
Sep 11, 2025
e427267
Merge branch 'feature_markdown' of https://github.com/ant-design/x in…
Sep 11, 2025
291d164
feat(XMarkdown): Support openLinksInNewTab (#1164)
Div627 Sep 12, 2025
9754513
feat(use-x-chat): add updating status (#833)
wzc520pyfm Sep 12, 2025
7083878
fix(ThoughtChain): fix the issue where title block-level elements can…
IsDyh01 Sep 12, 2025
bd067c5
chore: changelog of 1.6.1 (#1173)
kimteayon Sep 12, 2025
752f8b7
chore: net merge main
kimteayon Sep 12, 2025
6b6f2f5
chore: net merge main
kimteayon Sep 12, 2025
ab1b4b6
chore: next merge main
kimteayon Sep 12, 2025
f153ddf
chore: next merge main
kimteayon Sep 12, 2025
b7c2d2c
chore: next merge main
kimteayon Sep 12, 2025
a075caa
chore: next merge main
kimteayon Sep 12, 2025
128938b
chore: next merge main
kimteayon Sep 12, 2025
ed7fa58
chore: next merge main
kimteayon Sep 12, 2025
9e1161b
chore: next merge main
kimteayon Sep 12, 2025
c342a0a
chore: next merge main
kimteayon Sep 12, 2025
ca4665a
chore: auto merge branches (#1174)
github-actions[bot] Sep 12, 2025
0a430ef
fix: fix Mermaid render
Sep 12, 2025
a2c0288
Merge remote-tracking branch 'origin/next' into feature_markdown
Sep 12, 2025
47a44f2
feat: remove console
Sep 12, 2025
33c185d
fix: fix build error
Sep 14, 2025
4347728
docs: remove performance docs
Sep 14, 2025
b595e74
fix: fix test error
Div627 Sep 14, 2025
1fab58e
chore: changelog of 2.0.0-alpha.7 & fixed Semantic of Xmardown (#1178)
kimteayon Sep 15, 2025
5b26594
fix: update snapshot
Sep 15, 2025
a481d65
docs: remove numbers in footnote
Sep 16, 2025
02d2600
fix: markdown theme & Unified Type Naming (#1182)
kimteayon Sep 16, 2025
7079224
docs: repair the type error in the useXChat document (#1183)
IsDyh01 Sep 16, 2025
a27e8ef
Merge branch 'feature_markdown' into fix/xmarkdown-mermaid
Sep 16, 2025
b64a24f
feat: container
Sep 16, 2025
507a5a8
Merge branch 'next' into fix/xmarkdown-mermaid
kimteayon Sep 16, 2025
0523e6a
docs: 移除非必要的 return
Sep 16, 2025
952f223
Merge branch 'fix/xmarkdown-mermaid' of https://github.com/yuguaa/x i…
Sep 16, 2025
acb6253
Merge pull request #1170 from yuguaa/fix/xmarkdown-mermaid
Div627 Sep 16, 2025
21262ea
chore: update playground (#1184)
kimteayon Sep 16, 2025
2869170
feat: plugins type modify
Sep 16, 2025
478e246
Merge remote-tracking branch 'origin/next' into feature_markdown
Sep 16, 2025
4d4f9c1
docs: 依赖 antd & docs
Sep 17, 2025
da7c3ed
fix: fix lint error
Sep 17, 2025
1855211
chore: update site config (#1186)
kimteayon Sep 17, 2025
3d08cd1
feat: update antd version
Sep 17, 2025
df07e9f
feat: 依赖调整
Sep 17, 2025
a19bba2
chore: bump ora from 8.2.0 to 9.0.0 (#1189)
dependabot[bot] Sep 18, 2025
719ceca
chore: bump jsdom from 26.1.0 to 27.0.0 (#1180)
dependabot[bot] Sep 18, 2025
3c77906
Merge branch 'next' into feature_markdown
kimteayon Sep 18, 2025
718f340
Add comprehensive FAQ questions with Chinese and English versions cov…
Copilot Sep 18, 2025
4c4ea9d
docs & type: fix lint error
Sep 18, 2025
b40c27c
Merge branch 'feature_markdown' of github.com:ant-design/x into featu…
Sep 18, 2025
ae60867
chore: update tbox website (#1191)
iamkun-2 Sep 18, 2025
230707b
chore: update tbox website next (#1192)
iamkun-2 Sep 18, 2025
17e60a6
feat: revert version
Sep 18, 2025
66a7af6
chore: update og:image (#1193)
kimteayon Sep 18, 2025
41a14d3
feat: modify dompurify config and user config
Sep 18, 2025
de07ed4
feat: update antd version
Sep 18, 2025
e014a36
feat: all update antd alpha3
Sep 18, 2025
3e91988
fix: update playground & fix Actions Semantic & update OpenAI model …
kimteayon Sep 18, 2025
5cd3e89
Feat(XMarkdown): 类型调整 & 文档补充 & 依赖 antd (#1187)
Div627 Sep 18, 2025
6c078e3
feat: animation 调整 & 类型修改
Sep 19, 2025
72eb01f
Merge remote-tracking branch 'origin/next' into feature_markdown
Sep 19, 2025
6266e7c
fix: fix ts lint
Sep 19, 2025
ce70c81
feat: remove html tags
Sep 19, 2025
c3d6e77
fix: fix lint error
Sep 19, 2025
fb16f1a
type: modify type
Sep 19, 2025
3ec61d2
fix: fix lint error
Sep 19, 2025
35300b0
fix: fix lint error
Sep 19, 2025
6ed9e16
fix: fix lint error
Sep 19, 2025
847bf44
fix: fix lint error
Sep 19, 2025
bfa5c7e
fix: fix CR
Sep 19, 2025
9952117
docs: change
Sep 19, 2025
9a78a09
Feature(XMarkdown):动画调整 & 导出类型修改 (#1198)
Div627 Sep 19, 2025
38e3a6b
docs: component docs
Sep 19, 2025
e34d5c0
Merge remote-tracking branch 'origin/next' into feature_markdown
Sep 19, 2025
15434aa
Docs(XMarkdown): Component Docs (#1199)
Div627 Sep 21, 2025
2af79c9
chore(ci): use setup-utoo (#1197)
elrrrrrrr Sep 22, 2025
34e0845
chore: bump tbox-nodejs-sdk from 0.0.14 to 0.0.17 (#1190)
dependabot[bot] Sep 22, 2025
c65aaeb
feat: add Bubble extra & update playground & useXChat setMessage can …
kimteayon Sep 22, 2025
9470360
feat: playground
kimteayon Sep 22, 2025
3155df3
feat: playground
kimteayon Sep 22, 2025
9e81cc2
feat: playground
kimteayon Sep 22, 2025
02b9d56
Merge pull request #1203 from ant-design/next-alpha
anxLiang Sep 22, 2025
20814da
feat: modify animation
Sep 22, 2025
5a9bee0
Merge remote-tracking branch 'origin/next' into feature_markdown
Sep 22, 2025
2ccaa15
docs: format
Sep 22, 2025
80e80d4
feat: change startWith to indexOf
Sep 22, 2025
1e41fd3
fix: fix test case
Sep 22, 2025
c7e8bf5
docs: 更换图标 (#1205)
kimteayon Sep 22, 2025
024751b
fix: fix lint error
Sep 22, 2025
6d62c9b
docs: change docs
Sep 22, 2025
36d243f
feat: change style
Sep 22, 2025
4b05f95
Feature(XMarkdown):Animation (#1204)
Div627 Sep 22, 2025
2e1fe3e
chore: bump tbox-nodejs-sdk from 0.0.17 to 0.0.18 (#1206)
dependabot[bot] Sep 23, 2025
e816ef9
chore: bump actions/github-script from 7 to 8 (#1159)
dependabot[bot] Sep 23, 2025
e236a98
docs: Update README (#1208)
afc163 Sep 23, 2025
801283e
docs: add packages badges (#1209)
afc163 Sep 23, 2025
e3aa4a5
feat: 支持遍历children
Div627 Sep 23, 2025
7a59208
Merge remote-tracking branch 'origin/next' into feature_markdown
Div627 Sep 23, 2025
2680e05
fix: fix cr
Div627 Sep 23, 2025
54e19ae
feat: animation support div and remove table style
Div627 Sep 23, 2025
d6a1efc
feat: changelog
Div627 Sep 24, 2025
07b7c33
docs: revert changelog
Div627 Sep 24, 2025
38a05ab
Merge pull request #1212 from ant-design/feature_markdown
Div627 Sep 24, 2025
ea82ed9
chore: changelog of 2.0.0-alpha.9 (#1214)
Div627 Sep 24, 2025
05eeb85
chore: merge next-alpha to next (#1210)
kimteayon Sep 24, 2025
e3d29b9
透传CascaderProps其他参数 (#1110)
guxingke201 Sep 25, 2025
42d9561
docs: 中英文空格
Div627 Sep 26, 2025
ff2ea75
chore: x-markdown path modify
Div627 Sep 26, 2025
76d7152
chore: editbutton url
Div627 Sep 26, 2025
ab35180
fix(docs): fixed the incorrect Semantic DOM component names in the th…
IsDyh01 Sep 26, 2025
682160f
docs: update the XProvider theme demo (#1216)
kimteayon Sep 26, 2025
3afde7e
Merge branch 'next' into feature_markdown_docs
kimteayon Sep 26, 2025
45563c2
chore: change x-sdk path
Div627 Sep 28, 2025
f6825ff
Merge remote-tracking branch 'origin/feature_markdown_docs' into feat…
Div627 Sep 28, 2025
52163a6
docs: fix docs cr
Div627 Sep 28, 2025
d9fde69
Merge pull request #1217 from ant-design/feature_markdown_docs
Div627 Sep 28, 2025
16f27b4
feat: Sender focus add slot (#1221)
kimteayon Sep 29, 2025
4e35f49
feat: Semantic type of Attachments and FileCard (#1220)
kimteayon Sep 29, 2025
c4e1c57
docs: SeeConf link (#1224)
kimteayon Sep 30, 2025
4cbab45
chore: bump peter-evans/commit-comment from 3 to 4 (#1230)
dependabot[bot] Oct 8, 2025
3ebf7ab
chore: bump @types/jsdom from 21.1.7 to 27.0.0 (#1229)
dependabot[bot] Oct 8, 2025
02c4b71
chore: bump father from 4.6.3 to 4.6.5 (#1181)
dependabot[bot] Oct 8, 2025
206960f
chore: bump @happy-dom/jest-environment from 18.0.1 to 19.0.2 (#1228)
dependabot[bot] Oct 8, 2025
2589152
chore: bump happy-dom from 18.0.1 to 19.0.2 (#1227)
dependabot[bot] Oct 8, 2025
67c54ce
docs: update site home page (#1233)
kimteayon Oct 10, 2025
81a9665
docs: fix the component names in semanticDom (#1232)
IsDyh01 Oct 10, 2025
181d86b
chore: bump @happy-dom/jest-environment from 19.0.2 to 20.0.0 (#1236)
dependabot[bot] Oct 10, 2025
5a89718
chore: bump happy-dom from 19.0.2 to 20.0.0 (#1237)
dependabot[bot] Oct 10, 2025
4db72e5
fix: Optimize sender input parameters: onPasteFile (#1242)
kimteayon Oct 13, 2025
1168ad2
fix: Fix document references to internationalization & Add internati…
kimteayon Oct 13, 2025
25e22d1
chore: ignore scripts (#1247)
elrrrrrrr Oct 14, 2025
a63602e
fix: antd-token-previewer updated (#1246)
anxLiang Oct 14, 2025
28b8fe9
feat(FileCaed): support jfif format (#1248)
IsDyh01 Oct 14, 2025
202ccf8
fix: x-sdk requestFallback error (#1244)
kimteayon Oct 15, 2025
8f26bdf
feat: Bubble.System & Bubble.Divider (#1239)
anxLiang Oct 15, 2025
9fad224
feat: add sources component (#1250)
hy993658052 Oct 16, 2025
8f16477
feat: add and update SDK demos & add useXConversations activeConver…
kimteayon Oct 20, 2025
485b4a4
fix(XMarkdown): openLinksInNewTab 属性配置失效 (#1253)
Div627 Oct 20, 2025
d51be74
fix: onRequest messages& isResqesting & requestPlaceholder & requestF…
kimteayon Oct 21, 2025
52ddf45
feat(XMarkdown): 支持通过组件匹配未完成的Markdown语法 (#1223)
Div627 Oct 22, 2025
c03ed0c
fix(XMarkdown): 动画重复渲染 (#1255)
Div627 Oct 22, 2025
410d0dd
feat(XMarkdown): latex support (#1256)
Div627 Oct 22, 2025
2d4ec87
fix(XMarkdown):格式缓存 (#1257)
Div627 Oct 23, 2025
2e3b02e
feat: Sender supports SlotConfig changes & Sender supports the functi…
kimteayon Oct 24, 2025
f223e53
fix: skip render animation text when parent is custom component (#1260)
Div627 Oct 24, 2025
5f76b7c
feat: The source reference component implements the current data func…
kimteayon Oct 25, 2025
a91001c
docs: 新增 markdown 文档示例 (#1262)
kimteayon Oct 26, 2025
18f15ef
feat: Bubble list scroll (#1263)
kimteayon Oct 27, 2025
1d875d6
feat(XMarkdown): default KaTeX to silent error mode (#1265)
Div627 Oct 27, 2025
0345ebf
chore: chengelog of 2.0.0-alpha.11 (#1264)
kimteayon Oct 28, 2025
abe4d1b
feat: Attachments add ref fun: select to select files & fix maxcount …
kimteayon Oct 28, 2025
1245be5
docs: fix used Bubble.List demo error (#1269)
kimteayon Oct 28, 2025
8c11f36
docs: Chinese Link Processing (#1270)
kimteayon Oct 28, 2025
619b72a
fix: fix key repeat (#1273)
Div627 Oct 29, 2025
dc59552
feat(XMarkdown): add block and streamstatus to code component (#1272)
Div627 Oct 29, 2025
9c146b8
docs: Organize and optimize documents of chat provider (#1274)
kimteayon Oct 29, 2025
d512583
chore: changelog of 2.0.0-alpha.12 (#1275)
kimteayon Oct 29, 2025
458c21f
chore: next merge main
kimteayon Oct 29, 2025
3dd5bcf
fix: fix user code paragraph link renderer not work (#1276)
Div627 Oct 29, 2025
fc84567
chore: auto merge branches (#1279)
github-actions[bot] Oct 29, 2025
76a5fba
feat: ThoughtChain & Think add blink (#1278)
kimteayon Oct 30, 2025
63be53c
feat: add blink to ThoughtChain (#1286)
kimteayon Oct 31, 2025
334051c
feat: Actions fade in (#1288)
kimteayon Oct 31, 2025
158dbdc
feat: delete Bubble.List suffix (#1285)
kimteayon Oct 31, 2025
c1af24c
docs: the style with ComponentChangelog in the site (#1290)
Rain120 Oct 31, 2025
e8e3c4b
feat: Actions motions & prompts motions (#1289)
kimteayon Oct 31, 2025
9915d01
chore: changelog of 2.0.0-alpha.13 (#1292)
kimteayon Nov 3, 2025
ca3473f
fix: fix dompurifyConfig ALLOWED_TAGS wrong merge to ADD_TAGS
Nov 4, 2025
c60985a
Merge pull request #1297 from ant-design/fix_markdown_dompurify_config
Div627 Nov 4, 2025
5de6a74
fix: fix fenced code streamStatus set wrong
Nov 5, 2025
3168c22
fix: fix ci
Nov 5, 2025
af22cf7
feat: peer dependece antd
Nov 5, 2025
41160a4
chore: overrides antd
Nov 5, 2025
b5cbcdd
chore: overrides
Nov 5, 2025
d63f277
chore: antd
Nov 5, 2025
36d4dff
fix: fix ci
Nov 5, 2025
43d9753
chore: antd version
Nov 5, 2025
01f1331
chore: antd
Nov 6, 2025
2bf0dac
chore: update antd 6.00-alpha.4 (#1300)
kimteayon Nov 6, 2025
e520139
Merge remote-tracking branch 'origin/next' into fix_code_stream_status
Nov 6, 2025
3066c1b
chore: revert antd 6.0.0alpha.4 type change
Nov 6, 2025
168e750
refactor(types): rename SteamingOption to StreamingOption and modify …
Nov 6, 2025
21bf3cf
Merge pull request #1298 from ant-design/fix_code_stream_status
Div627 Nov 6, 2025
cd06a04
docs: api description
Nov 6, 2025
b5303d6
Merge remote-tracking branch 'origin/next' into refactor_markdown_str…
Nov 6, 2025
3a62423
docs: document update error (#1303)
kimteayon Nov 6, 2025
178fb15
Merge branch 'next' into refactor_markdown_streaming_type
kimteayon Nov 6, 2025
f0396f3
feat: markdown theme (#1305)
kimteayon Nov 6, 2025
7aaf38c
Merge branch 'next' into refactor_markdown_streaming_type
kimteayon Nov 6, 2025
c418a97
Merge pull request #1301 from ant-design/refactor_markdown_streaming_…
Div627 Nov 6, 2025
aa8360b
fix: fix set code streamStastus wrong when code after \n\n (#1307)
Div627 Nov 7, 2025
bedda7a
style(XMarkdown): migrate component styles from Less to CSS (#1306)
Div627 Nov 7, 2025
2b8bb68
feat: token of blinkMotion (#1318)
kimteayon Nov 11, 2025
8815a87
chore: changelog of 2.0.0-alpha.15 (#1310)
kimteayon Nov 11, 2025
b63c2c3
feat: FileCard image load (#1311)
kimteayon Nov 12, 2025
e74ba34
feat(XMarkdown): cache incomplete table & HTML tokens in useStreaming…
Div627 Nov 12, 2025
c31e2e4
fix(XMarkdown): deafult table style (#1324)
Div627 Nov 13, 2025
687543c
feat(XMarkdown): 全类型缓存映射 & 透传缓存原文本 & 文档优化 (#1325)
Div627 Nov 13, 2025
e6823c3
chore(XMarkdown): modify theme style and format docs (#1326)
Div627 Nov 16, 2025
637198c
feat(XMarkdown): pass true when disabled and checked props exist (#1328)
Div627 Nov 17, 2025
5c56b25
chore: Added notification capability and configured WearFox notificat…
kimteayon Nov 18, 2025
86632f2
feat: remove unnessary heading cache and modify demo
Div627 Nov 18, 2025
69c6ece
docs: format docs
Div627 Nov 18, 2025
074b26c
chore: test case
Div627 Nov 18, 2025
bdd8310
docs: modify custom plugin docs
Div627 Nov 19, 2025
23af599
docs: format html skeleton width
Div627 Nov 19, 2025
8db0e65
chore: main-merge-next
kimteayon Nov 19, 2025
e4161c2
chore: auto merge branches (#1336)
github-actions[bot] Nov 19, 2025
e8cf973
Merge pull request #1331 from ant-design/feature_markdown_syntax_process
Div627 Nov 19, 2025
5ee121f
docs: update Doc model from siliconcloud to bigmodel (#1335)
kimteayon Nov 19, 2025
dcc02f9
perf(XMarkdown): use useMemo to optimize docs render & reduce useless…
Div627 Nov 20, 2025
abdf9e9
refactoring: bubble delete components props & internal props enhancem…
kimteayon Nov 20, 2025
3de0690
feat: 1
kimteayon Nov 20, 2025
bacc914
feat: docs
kimteayon Nov 20, 2025
381b2cf
docs: Change demo image URL in README (#1340)
afc163 Nov 20, 2025
63843da
chore: next merge next-alpha (#1339)
kimteayon Nov 20, 2025
63aed83
Merge branch 'next' of https://github.com/ant-design/x into doc_demo
kimteayon Nov 20, 2025
62ce059
docs: update
kimteayon Nov 20, 2025
317adb6
chore: next merge main
kimteayon Nov 20, 2025
3488515
Merge branch 'next' into next-merge-main
kimteayon Nov 20, 2025
706e1c7
docs: update demo (#1341)
kimteayon Nov 20, 2025
eb42d28
chore: auto merge branches (#1342)
github-actions[bot] Nov 20, 2025
94aa5fa
docs: update demo
kimteayon Nov 20, 2025
6e81d19
docs: update demo
kimteayon Nov 20, 2025
be967ac
Merge branch 'next' into doc_demo
kimteayon Nov 20, 2025
7010ca4
Merge pull request #1343 from ant-design/doc_demo
Div627 Nov 20, 2025
c38a32e
feat: Replace the operation icons of HighlightCode and Mermaid in XMa…
buwenhao Nov 21, 2025
ea5d229
chore: remove unused devDependencies (#1350)
Div627 Nov 21, 2025
52d000d
chore: Update workflow to use test-utoo.yml (#1351)
afc163 Nov 21, 2025
a0c32c0
chore: next merge main
kimteayon Nov 21, 2025
b755ae9
docs: update demo
kimteayon Nov 21, 2025
9a92839
chore: auto merge branches (#1352)
github-actions[bot] Nov 21, 2025
288e82c
chore: auto merge branches (#1349)
github-actions[bot] Nov 21, 2025
d2691bb
chore: bump actions/checkout from 5 to 6 (#1353)
dependabot[bot] Nov 21, 2025
0a66a74
chore: bump webpack-bundle-analyzer from 4.10.2 to 5.0.0 (#1333)
dependabot[bot] Nov 21, 2025
5748393
chore(deps-dev): bump happy-dom (#1354)
dependabot[bot] Nov 21, 2025
cc84b22
chore: changelog of 2.0.0 (#1355)
kimteayon Nov 22, 2025
7e4baba
chore: fix wrong of merge (#1359)
kimteayon Nov 22, 2025
ac48377
chore: fix site home (#1361)
kimteayon Nov 22, 2025
83c9b83
docs: update badges in README.md (#1360)
afc163 Nov 22, 2025
c9d8619
chore: fix main site (#1362)
kimteayon Nov 22, 2025
a95a3a0
chore: update site-deploy (#1363)
kimteayon Nov 22, 2025
f868987
feat: The Sender component adds a length limit and the display of inp…
danjianyishangshou Nov 24, 2025
405c54c
fix: ai review and modification
danjianyishangshou Nov 24, 2025
7fb5333
Merge branch 'feature' into featrue_sender_maxLength
danjianyishangshou Nov 26, 2025
2d58ec1
Merge branch 'feature' into featrue_sender_maxLength
danjianyishangshou Nov 27, 2025
5f072dd
fix: Fix the error in merging historical version code
danjianyishangshou Nov 27, 2025
7e9a2bd
fix: lint error
danjianyishangshou Nov 27, 2025
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
70 changes: 69 additions & 1 deletion packages/x/components/sender/SlotTextArea.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ const SlotTextArea = React.forwardRef<SlotTextAreaRef>((_, ref) => {
onFocus,
onBlur,
slotConfig,
maxLength,
skill,
...restProps
} = React.useContext(SenderContext);
Expand Down Expand Up @@ -627,6 +628,16 @@ const SlotTextArea = React.forwardRef<SlotTextAreaRef>((_, ref) => {
onBlur?.(e as unknown as React.FocusEvent<HTMLTextAreaElement>);
};

// 获取当前选中文本长度
const getSelectedTextLength = (): number => {
const selection = window.getSelection();
if (selection && selection.rangeCount > 0) {
const range = selection.getRangeAt(0);
return range.toString().length;
}
return 0;
};

const onInternalInput = (e: React.FormEvent<HTMLDivElement>) => {
const newValue = getEditorValue();
removeSpecificBRs(editableRef?.current);
Expand All @@ -647,7 +658,21 @@ const SlotTextArea = React.forwardRef<SlotTextAreaRef>((_, ref) => {
}

if (text) {
insert([{ type: 'text', value: text.replace(/\n/g, '') }]);
const currentValue = getEditorValue().value;
const newText = text.replace(/\n/g, '');

// 检查最大长度限制
if (maxLength !== undefined) {
const selectedLength = getSelectedTextLength();
const remainingLength = maxLength - (currentValue.length - selectedLength);
if (remainingLength <= 0) {
return; // 已达到最大长度,不再插入
}
const truncatedText = newText.slice(0, remainingLength);
insert([{ type: 'text', value: truncatedText.replace(/\n/g, '') }]);
} else {
insert([{ type: 'text', value: newText.replace(/\n/g, '') }]);
}
}

onPaste?.(e as unknown as React.ClipboardEvent<HTMLTextAreaElement>);
Expand Down Expand Up @@ -705,6 +730,37 @@ const SlotTextArea = React.forwardRef<SlotTextAreaRef>((_, ref) => {
const editableDom = editableRef.current;
const selection = window.getSelection();
if (!editableDom || !selection) return;

// 检查最大长度限制
if (maxLength !== undefined) {
const currentValue = getEditorValue().value;
const selectedLength = getSelectedTextLength();
const remainingLength = maxLength - (currentValue.length - selectedLength);

if (remainingLength <= 0) {
return;
}

// 渐进式截断文本slot
let remainingChars = remainingLength;
slotConfig = slotConfig.map((item) => {
if (item.type === 'text' && remainingChars > 0) {
const textLength = (item.value || '').length;
if (textLength <= remainingChars) {
remainingChars -= textLength;
return item;
}
const truncated = (item.value || '').slice(0, remainingChars);
remainingChars = 0;
return { ...item, value: truncated };
}
if (item.type === 'text') {
return { ...item, value: '' };
}
return item;
});
}

const slotNode = getSlotListNode(slotConfig);
const { type, range: lastRage } = getInsertPosition(position);
let range: Range = document.createRange();
Expand Down Expand Up @@ -881,6 +937,18 @@ const SlotTextArea = React.forwardRef<SlotTextAreaRef>((_, ref) => {
onBlur={onInternalBlur}
onSelect={onInternalSelect}
onInput={onInternalInput}
onBeforeInput={(e) => {
if (maxLength !== undefined) {
const currentValue = getEditorValue().value;
const selectedLength = getSelectedTextLength();
const inputLength = (e as any).data?.length ?? 0;
const newLength = currentValue.length - selectedLength + inputLength;
if (newLength > maxLength) {
e.preventDefault();
return;
}
}
}}
{...(restProps as React.HTMLAttributes<HTMLDivElement>)}
/>
<div
Expand Down
64 changes: 64 additions & 0 deletions packages/x/components/sender/demo/max-length.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
import { Sender } from '@ant-design/x';
import { Typography } from 'antd';
import React from 'react';

const { Paragraph, Text } = Typography;

const App = () => {
const [value, setValue] = React.useState('');

return (
<div>
<Paragraph>Sender with Length Limit</Paragraph>
<Sender
value={value}
onChange={setValue}
maxLength={50}
showCount
placeholder="Please enter content, max 50 characters..."
onSubmit={(msg) => {
console.log('Submit:', msg);
setValue('');
}}
/>
<Paragraph style={{ marginTop: 40 }}>Custom Count Display</Paragraph>
<Sender
value={value}
onChange={setValue}
maxLength={50}
showCount={({ count, maxLength }) => (
<Text
style={{
position: 'absolute',
color: maxLength && count > maxLength * 0.8 ? 'red' : '#ccc',
fontSize: 10,
marginBottom: 4,
}}
>
{maxLength
? `Entered ${count} characters, limit ${maxLength} characters`
: `Entered ${count} characters`}
</Text>
)}
placeholder="Custom count display..."
onSubmit={(msg) => {
console.log('Submit:', msg);
setValue('');
}}
/>
<Paragraph style={{ marginTop: 40 }}>Count Only, No Length Limit</Paragraph>
<Sender
value={value}
onChange={setValue}
showCount
placeholder="Character count only, no length limit..."
onSubmit={(msg) => {
console.log('Submit:', msg);
setValue('');
}}
/>
</div>
);
};

export default App;
3 changes: 3 additions & 0 deletions packages/x/components/sender/index.en-US.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ coverDark: https://mdn.alipayobjects.com/huamei_iwk9zp/afts/img/A*cOfrS4fVkOMAAA
<code src="./demo/footer.tsx">Custom Footer Content</code>
<code src="./demo/send-style.tsx">Style Adjustment</code>
<code src="./demo/paste-image.tsx">Paste Files</code>
<code src="./demo/max-length.tsx">Max Length</code>

## API

Expand All @@ -50,6 +51,8 @@ Common props ref:[Common props](/docs/react/common-props)
| header | Header panel | React.ReactNode \| false \| (oriNode: React.ReactNode, info: { components: ActionsComponents; }) => React.ReactNode \| false | false | - |
| prefix | Prefix content | React.ReactNode \| false \| (oriNode: React.ReactNode, info: { components: ActionsComponents; }) => React.ReactNode \| false | false | - |
| footer | Footer content | React.ReactNode \| false \| (oriNode: React.ReactNode, info: { components: ActionsComponents; }) => React.ReactNode \| false | false | - |
| maxLength | Maximum length of input content | number | - | - |
| showCount | Whether to display character count, supports custom rendering | boolean \| ((info: { value: string; count: number; maxLength?: number }) => React.ReactNode) | false | - |
| readOnly | Whether to make the input box read-only | boolean | false | - |
| rootClassName | Root element style class | string | - | - |
| styles | Semantic style definition | [See below](#semantic-dom) | - | - |
Expand Down
24 changes: 23 additions & 1 deletion packages/x/components/sender/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ const ForwardSender = React.forwardRef<SenderRef, SenderProps>((props, ref) => {
placeholder,
onFocus,
onBlur,
showCount,
skill,
...restProps
} = props;
Expand Down Expand Up @@ -141,7 +142,7 @@ const ForwardSender = React.forwardRef<SenderRef, SenderProps>((props, ref) => {
const [innerValue, setInnerValue] = useMergedState(defaultValue || '', {
value,
});

const currentCount = innerValue.length;
const triggerValueChange: SenderProps['onChange'] = (nextValue, event, slotConfig) => {
if (slotConfig) {
setInnerValue(nextValue);
Expand Down Expand Up @@ -221,6 +222,26 @@ const ForwardSender = React.forwardRef<SenderRef, SenderProps>((props, ref) => {
: header || null;

// ============================ Footer ============================
const renderCount = () => {
if (!showCount) return null;

const countInfo = {
value: innerValue,
count: currentCount,
maxLength: restProps.maxLength,
};

if (typeof showCount === 'function') {
return showCount(countInfo);
}

return (
<div className={`${prefixCls}-count`}>
{restProps.maxLength ? `${currentCount}/${restProps.maxLength}` : currentCount}
</div>
);
};

const footerNode =
typeof footer === 'function'
? footer(actionNode, { components: sharedRenderComponents })
Expand Down Expand Up @@ -383,6 +404,7 @@ const ForwardSender = React.forwardRef<SenderRef, SenderProps>((props, ref) => {
)}
</ActionButtonContext.Provider>
</SenderContext.Provider>
{showCount && renderCount()}
</div>
);
});
Expand Down
3 changes: 3 additions & 0 deletions packages/x/components/sender/index.zh-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ coverDark: https://mdn.alipayobjects.com/huamei_iwk9zp/afts/img/A*cOfrS4fVkOMAAA
<code src="./demo/footer.tsx">自定义底部内容</code>
<code src="./demo/send-style.tsx">调整样式</code>
<code src="./demo/paste-image.tsx">黏贴文件</code>
<code src="./demo/max-length.tsx">长度限制</code>

## API

Expand All @@ -51,6 +52,8 @@ coverDark: https://mdn.alipayobjects.com/huamei_iwk9zp/afts/img/A*cOfrS4fVkOMAAA
| header | 头部面板 | React.ReactNode \| false \|(oriNode: React.ReactNode,info: { components: ActionsComponents;}) => React.ReactNode \| false; | false | - |
| prefix | 前缀内容 | React.ReactNode \| false \|(oriNode: React.ReactNode,info: { components: ActionsComponents;}) => React.ReactNode \| false; | false | - |
| footer | 底部内容 | React.ReactNode \| false \|(oriNode: React.ReactNode,info: { components: ActionsComponents;}) => React.ReactNode \| false; | false | - |
| maxLength | 输入内容最大长度 | number | - | - |
| showCount | 是否显示字符计数,支持自定义渲染 | boolean \| ((info: { value: string; count: number; maxLength?: number }) => React.ReactNode) | false | - |
| readOnly | 是否让输入框只读 | boolean | false | - |
| rootClassName | 根元素样式类 | string | - | - |
| styles | 语义化定义样式 | [见下](#semantic-dom) | - | - |
Expand Down
4 changes: 4 additions & 0 deletions packages/x/components/sender/interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,10 @@ export interface SenderProps
suffix?: BaseNode | NodeRender;
header?: BaseNode | NodeRender;
autoSize?: boolean | { minRows?: number; maxRows?: number };
maxLength?: number;
showCount?:
| boolean
| ((info: { value: string; count: number; maxLength?: number }) => React.ReactNode);
skill?: SkillType;
}

Expand Down
9 changes: 9 additions & 0 deletions packages/x/components/sender/style/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,15 @@ const genSenderStyle: GenerateStyle<SenderToken> = (token) => {
paddingBlockStart: paddingXXS,
boxSizing: 'border-box',
},
// ============================ Count ============================
[`${componentCls}-count`]: {
color: token.colorTextDescription,
fontSize: token.fontSizeSM,
lineHeight: token.lineHeightSM,
position: 'absolute',
bottom: -token.paddingXXS,
insetInlineEnd: token.paddingSM,
},
},
};
};
Expand Down