修复 Textarea 设置为 null 时,显示字数限制显示错误问题#1004
Conversation
|
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
Walkthrough该PR对 Changes
Sequence Diagram(s)sequenceDiagram
participant C as wd-textarea 组件
participant CP as currentLength 计算属性
participant FV as formatValue 函数
C->>CP: 读取 modelValue
CP->>FV: 调用 formatValue(modelValue)
FV->>FV: 检查是否为 null/undefined
FV-->>CP: 返回格式化后的值(空字符串或原值)
CP->>CP: 用 Array.from() 计算字符长度
Possibly related issues
Possibly related PRs
Suggested reviewers
Poem
Tip ⚡💬 Agentic Chat (Pro Plan, General Availability)
📜 Recent review detailsConfiguration used: CodeRabbit UI 📒 Files selected for processing (1)
🔇 Additional comments (3)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
概述此 PR 修复了当 Textarea 组件的值为 null 时,字数限制显示错误的问题。通过修改 变更
|
| * @link https://github.com/Moonofweisheng/wot-design-uni/issues/933 | ||
| */ | ||
| return Array.from(String(formatValue(props.modelValue) || '')).length | ||
| return Array.from(String(formatValue(props.modelValue))).length |
There was a problem hiding this comment.
The change from String(formatValue(props.modelValue) || '') to String(formatValue(props.modelValue)) is correct because the formatValue function now handles null and undefined values by returning an empty string, making the || '' redundant.
✅ Deploy Preview for wot-design-uni ready!Built without sensitive environment variables
To edit notification comments on pull requests, go to your Netlify site configuration. |
🤔 这个 PR 的性质是?(至少选择一个)
🔗 相关 Issue
#1003
💡 需求背景和解决方案
需求背景
使用Textarea组件时,启用了show-word-limit,调用接口返回的值为null时,显示字数限制为4,测试过程中使用 undefined 显示是正常的,然后查看源码发现问题出在了组件中 formatValue函数处理的时候返回将 null,转换成了字符串 'null',导致在计算 currentLength 的时候显示字数限制为4。
解决方案
wd-textarea组件中的formatValue方法if (value === null || value === undefined) return ''☑️ 请求合并前的自查清单
Summary by CodeRabbit
Bug Fixes
Refactor