mirror of
https://github.com/ant-design/ant-design.git
synced 2025-01-18 22:36:31 +08:00
fix: update the slice rule when the TextArea component limits maxLength (#27679)
This commit is contained in:
parent
e5319bd1df
commit
9881be97fd
@ -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) => (
|
||||
|
@ -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 />,
|
||||
|
Loading…
Reference in New Issue
Block a user