Skip to content

Input 输入框输入表情时,长度计算错误 #7771

@hekang456

Description

@hekang456
  • I have searched the issues of this repository and believe that this is not a duplicate.

Version

undefined

Environment

any

Reproduction link

https://github.com/vueComponent/ant-design-vue

Steps to reproduce

在Input中输入表情😊的时候,长度计算会和实际输入的字符个数不一样。比如限制20个字符,输入10个表情后就不可以输入了。

What is expected?

表情能输入的个数比预期少一半

What is actually happening?

表情能正确计数。


function fixControlledValue(value: string | number) {
if (typeof value === 'undefined' || value === null) {
return '';
}
return String(value);
}
这里,'😊' 是一个字符串,包含一个笑脸表情符号。fixControlledValue('😊') 将返回这个字符串本身,因为 '😊' 已经是一个字符串了。然后,[...string] 会将字符串转换为一个字符数组(在这个上下文中,😊 被视为一个单一的字符,尽管它实际上可能由多个 Unicode 码点组成,但在 JavaScript 的字符串迭代中,它通常被视为一个单一的“字符”)。因此,.length 将返回 1,因为数组中只有一个元素(即那个笑脸表情符号)。

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions