Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

antd v5: Controlled components will treat null as empty value and null can not be used as an option value. #777

Open
wants to merge 7 commits into
base: master
Choose a base branch
from

Conversation

shezhangzhang
Copy link
Contributor

Changes:

  1. null cannot be used as an option value.
  2. allowClear triggerChange will pass the null to onChange() instead of undefined.
  3. add a new example: null-controlled example. (placeholder will show up)
  4. change some test case for null as an option value.
  5. add prettier latest (2.x) version to devDependencies, because the current prettier version added by umi-utils is 1.x, which can't deal with typescirpt import type syntax (prettier 1.x error: SyntaxError: '=' expected).
  6. add node children & options null value wanrning (/utils/warningPropsUtils.ts).

Chinese (中文):

  1. null 不能作为选项的 value 了。
  2. allowClear 触发清空更新会传递 null 作为空值而不是 undefined
  3. 新增了一个 null 作为 value 初始值的例子(占位符会正确出现,移除了之前的特殊处理逻辑)。
  4. 修改了 null 不能作为 value 相关的几个测试用例。
  5. 添加了 prettier 的最新版本(2.x)到 devDependencies,因为当前由 umi-utils 安装的的 prettier 版本是 1.x, 不能正确处理 typescript 的 import type 语法(prettier 1.x 会报错:SyntaxError: '=' expected)。
  6. 添加了 null 作为 value 出现在 options 中的告警(在 /utils/warningPropsUtils.ts 中)。

@vercel
Copy link

vercel bot commented Jun 13, 2022

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Updated
select ✅ Ready (Inspect) Visit Preview Jun 14, 2022 at 11:47AM (UTC)

return values;
}, [internalValue, convert2LabelValues, mode]);

// Fill label with cache to avoid option remove
const [mergedValues, getMixedOption] = useCache(rawLabeledValues, valueOptions);

const displayValues = React.useMemo(() => {
// `null` need show as placeholder instead
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since when null as value will returns [], this logic code is no looger needed. When value={null}, the placeholder will show up correctly.
因为 null 作为空值已经做了返回 [] 的处理,所以这段特殊处理此 issue 的逻辑已经不需要了,value={null} 时 placeholder 会正确显示。

@codecov
Copy link

codecov bot commented Jun 13, 2022

Codecov Report

Merging #777 (007c0f0) into master (446dd09) will increase coverage by 0.00%.
The diff coverage is 100.00%.

❗ Current head 007c0f0 differs from pull request most recent head ecf8223. Consider uploading reports for the commit ecf8223 to get more accurate results

@@           Coverage Diff           @@
##           master     #777   +/-   ##
=======================================
  Coverage   99.50%   99.51%           
=======================================
  Files          25       25           
  Lines        1020     1029    +9     
  Branches      341      337    -4     
=======================================
+ Hits         1015     1024    +9     
  Misses          4        4           
  Partials        1        1           
Impacted Files Coverage Δ
src/Select.tsx 100.00% <100.00%> (ø)
src/utils/warningPropsUtil.ts 98.59% <100.00%> (+0.28%) ⬆️
src/Selector/Input.tsx 100.00% <0.00%> (ø)
src/Selector/index.tsx 100.00% <0.00%> (ø)

📣 Codecov can now indicate which changes are the most critical in Pull Requests. Learn more

@zombieJ
Copy link
Member

zombieJ commented Jun 13, 2022

先到 FAQ 里 PR 一下,说明一下 null 值在 antd 中的定义,以及为什么要这么做哈~

@afc163
Copy link
Member

afc163 commented Jun 13, 2022

这是 break change,至少 4.x 中不能改。

@shezhangzhang
Copy link
Contributor Author

嗯嗯,这应该是 V5 的 break change。4.x 我先写个 FAQ:null & undefined controlled components 的PR,然后再在这里提个 null warning 的 PR 上来先哇

@shezhangzhang shezhangzhang changed the title Controlled components will treat null as empty value and null can not be used as an option value. antd v5: Controlled components will treat null as empty value and null can not be used as an option value. Jun 16, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants