Conversation
Codecov Report
@@ Coverage Diff @@
## master #47 +/- ##
===========================================
- Coverage 100.00% 96.55% -3.45%
===========================================
Files 4 5 +1
Lines 143 174 +31
Branches 55 68 +13
===========================================
+ Hits 143 168 +25
- Misses 0 6 +6
📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more |
| count={{ | ||
| show: true, | ||
| max: 5, | ||
| strategy: (val) => |
There was a problem hiding this comment.
一定要用专业名词吗,可以简单点吗,比如 getCount
There was a problem hiding this comment.
一定要用专业名词吗,可以简单点吗,比如 getCount
其实习惯了就好了 😂
There was a problem hiding this comment.
词不达意才更麻烦. 词越精确越好, 只不过我们非英语母语而已.
There was a problem hiding this comment.
这个和 @MadCcc 讨论下来,count 本身就是属性名里面再套一个 count 就重复了。所以复用了 Tree TreeSelect Cascader 的 strategy 的 API 名。
There was a problem hiding this comment.
这个可以参考 echarts,每个配置都有 formatter 自定义返回,对于图表或者组件,自定义方法的使用场景非常多,api 应该有个规范
There was a problem hiding this comment.
复用没问题,关键复用前第一次这个地方用的合不合适,比如 Table 的 dataIndex 对应的 render,这个就没定义成 strategy
按照 Naming Standard,render 系列命名需要带上 render 或为 xxxRender。其次,在固定规则外,复用现有命名 API,不额外创造。这个是符合我们的命名规范的。
There was a problem hiding this comment.
There was a problem hiding this comment.
感觉这个有问题啊,当 {max: 2} 用户只能输入2个字符,当 {max: 2, strategy:()=> 2},用户应该一个字符都不能输入
There was a problem hiding this comment.
用户自己写了 2 那就认为当前输入的值长度为 2,自然是可以继续输入的。因为永远都不会超出长度。可以看一下 ant-design/ant-design#37733 过一下为什么要交给用户处理的上下文。
| count={{ | ||
| show: true, | ||
| max: 5, | ||
| exceedFormatter: (val, { max }) => { |
There was a problem hiding this comment.
exceed 只体现了超出,没说明超出哪个,api 应该加上 max
There was a problem hiding this comment.
这个感觉没必要,exceed 本来就是超出,能超出的自然只有 max 了
There was a problem hiding this comment.
这个strategy会写到文档里,或者还会增加一个 demo,用户能认知strategy 可以解决什么问题,在这基础上,如果 api 名称为 getMax: (value) => number 则是 max 的自定义方法,一举两得。
如果要通过自定义方法的返回控制用户是否可以继续输入,或者右侧显示 1/2内容,都可以收成一个方法
There was a problem hiding this comment.
// 当超出
max范围时处理逻辑,允许开发者额外定制裁剪逻辑。该方法会略过composition事件以防止被输入法卡住的情况。
exceedFormatter?: ExceedFormatter;
最早就是一个,后来发现有输入法收不起来,所以拆了一个裁剪方法。
在 composition 阶段,用户输入超出长度是正常的。裁剪只有在 composition 结束时才能处理。比如 你好 限制 2,在输入 nihao 的时候长度是 5 ,你不能拦住它输入。输入完后才能裁剪。
| if ( | ||
| !compositionRef.current && | ||
| countConfig.exceedFormatter && | ||
| countConfig.max && | ||
| countConfig.strategy(currentValue) > countConfig.max | ||
| ) { | ||
| cutValue = countConfig.exceedFormatter(currentValue, { | ||
| max: countConfig.max, | ||
| }); | ||
| } |
There was a problem hiding this comment.
useCount 里是合成 countConfig 的,它本身不处理 change 逻辑~
| prefixCls="rc-input" | ||
| defaultValue="🔥" | ||
| count={{ | ||
| show: true, |
There was a problem hiding this comment.
这个不应该默认是 true 吗,因为外层 count={{}} 是真值
There was a problem hiding this comment.
不是的,原本是 showCount 默认为真。现在改名叫 count 是做计数使用。可以配置 strategy + max 仅做限制而不展示数字。
| import Input from '../src'; | ||
|
|
||
| const getSegments = (val: string) => [ | ||
| ...new (Intl as any).Segmenter().segment(val), |
There was a problem hiding this comment.
Segmenter 这个可以改 tsconfig "lib": ["dom", "es2017", "es2022"]

ref ant-design/ant-design#37733
贴一下之前同步会讨论的结论:
showCount的计算逻辑还原给原生的计算逻辑。让count和maxLength保持同步。该 PR:
count接口:exceedFormatter