Skip to content

[Bug 上报] Textarea 组件 show-word-limit 字数显示异常 #1003

Description

@myltx

Wot Design Uni 版本号

^1.7.1

平台

h5, 微信小程序

复现Demo地址(如不提供,将被直接关闭)

https://github.com/myltx/wot-design-ui-demo/tree/wot-Textarea

重现步骤

使用Textarea组件时,启用了show-word-limit,调用接口返回的值为null时,显示字数限制为4,测试过程中使用 undefined 显示是正常的,然后查看源码发现问题出在了组件中 formatValue函数处理的时候返回将 null,转换成了字符串 'null',导致在计算 currentLength 的时候显示字数限制为4。

期望的结果是什么?

期望在 Textarea 值为 null 的时候,可以正确显示字数限制为 0

实际的结果是什么?

2025-04-11.10-39-48.mp4

环境信息

在h5、微信小程序中都做了测试,都有这个问题。

其他补充信息

No response

Activity

  1. petercat-assistant commented on Apr 11, 2025

    @petercat-assistant

    感谢您报告这个问题。根据您提供的信息,Textarea 组件在启用 show-word-limit 时,如果接口返回的值为 null,字数限制显示为 4,而不是预期的 0。这是由于 formatValue 函数将 null 转换为了字符串 'null',从而导致计算 currentLength 时出现错误。

    为了修复这个问题,您可以尝试在 formatValue 函数中添加一个检查,以确保在处理 null 值时返回空字符串或其他适当的默认值。这样可以避免将 null 转换为字符串 'null'。

    如果您需要进一步的帮助或希望我们为您创建一个问题报告,请告诉我!如果您有权限进行代码修改,也可以尝试自行修复并提交一个 Pull Request。

  2. added a commit that references this issue on Apr 11, 2025
    db0a546
  3. added a commit that references this issue on May 6, 2025
    60f2fe6
  4. github-actions commented on Aug 26, 2025

    @github-actions
    Contributor

    此 issue 已被自动锁定,因为关闭后没有任何近期活动。如果有相关 bug,请重新创建一个新 issue。

  5. locked and limited conversation to collaborators on Aug 26, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions