fix: update the slice rule when the TextArea component limits maxLength (#27679)

This commit is contained in:
jiang.he 2020-11-11 00:56:57 +08:00 committed by GitHub
parent e5319bd1df
commit 9881be97fd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 1 deletions

View File

@ -113,7 +113,8 @@ class TextArea extends React.Component<TextAreaProps, TextAreaState> {
// Max length value
const hasMaxLength = Number(maxLength) > 0;
value = hasMaxLength ? value.slice(0, maxLength) : value;
// fix #27612 将value转为数组进行截取解决 '😂'.length === 2 等emoji表情导致的截取乱码的问题
value = hasMaxLength ? [...value].slice(0, maxLength).join('') : value;
// TextArea
const textareaNode = (size?: SizeType) => (

View File

@ -141,6 +141,14 @@ describe('TextArea', () => {
expect(textarea.prop('data-count')).toBe('5 / 5');
});
// 修改TextArea value截取规则后新增单测
it('slice emoji', () => {
const wrapper = mount(<TextArea maxLength={5} showCount value="1234😂" />);
const textarea = wrapper.find('.ant-input-textarea');
expect(wrapper.find('textarea').prop('value')).toBe('1234😂');
expect(textarea.prop('data-count')).toBe('5 / 5');
});
it('className & style patch to outer', () => {
const wrapper = mount(
<TextArea className="bamboo" style={{ background: 'red' }} showCount />,