mirror of
https://github.com/ant-design/ant-design.git
synced 2024-11-28 21:19:37 +08:00
fix: TextArea value get cut if ime mode (#28456)
close #27686 close #28417 close #27116
This commit is contained in:
parent
0721ef3cfb
commit
8f1466a30f
@ -92,12 +92,10 @@ const TextArea = React.forwardRef<TextAreaRef, TextAreaProps>(
|
|||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
|
|
||||||
let val = fixControlledValue(value) as string;
|
const val = fixControlledValue(value) as string;
|
||||||
|
|
||||||
// Max length value
|
// Max length value
|
||||||
const hasMaxLength = Number(maxLength) > 0;
|
const hasMaxLength = Number(maxLength) > 0;
|
||||||
// fix #27612 将value转为数组进行截取,解决 '😂'.length === 2 等emoji表情导致的截取乱码的问题
|
|
||||||
val = hasMaxLength ? [...val].slice(0, maxLength).join('') : val;
|
|
||||||
|
|
||||||
// TextArea
|
// TextArea
|
||||||
const textareaNode = (
|
const textareaNode = (
|
||||||
@ -116,7 +114,7 @@ const TextArea = React.forwardRef<TextAreaRef, TextAreaProps>(
|
|||||||
|
|
||||||
// Only show text area wrapper when needed
|
// Only show text area wrapper when needed
|
||||||
if (showCount) {
|
if (showCount) {
|
||||||
const valueLength = [...val].length;
|
const valueLength = hasMaxLength ? Math.min(Number(maxLength), [...val].length) : [...val].length;
|
||||||
const dataCount = `${valueLength}${hasMaxLength ? ` / ${maxLength}` : ''}`;
|
const dataCount = `${valueLength}${hasMaxLength ? ` / ${maxLength}` : ''}`;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
@ -140,7 +140,7 @@ describe('TextArea', () => {
|
|||||||
it('maxLength', () => {
|
it('maxLength', () => {
|
||||||
const wrapper = mount(<TextArea maxLength={5} showCount value="12345678" />);
|
const wrapper = mount(<TextArea maxLength={5} showCount value="12345678" />);
|
||||||
const textarea = wrapper.find('.ant-input-textarea');
|
const textarea = wrapper.find('.ant-input-textarea');
|
||||||
expect(wrapper.find('textarea').prop('value')).toBe('12345');
|
expect(wrapper.find('textarea').prop('value')).toBe('12345678');
|
||||||
expect(textarea.prop('data-count')).toBe('5 / 5');
|
expect(textarea.prop('data-count')).toBe('5 / 5');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user