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

feat: Support requiredMarkType #26309

Merged
merged 9 commits into from
Aug 21, 2020
Merged

feat: Support requiredMarkType #26309

merged 9 commits into from
Aug 21, 2020

Conversation

zombieJ
Copy link
Member

@zombieJ zombieJ commented Aug 20, 2020

[中文版模板 / Chinese template]

🤔 This is a ...

  • New feature
  • Bug fix
  • Site / documentation update
  • Demo update
  • Component style update
  • TypeScript definition update
  • Bundle size optimization
  • Performance optimization
  • Enhancement feature
  • Internationalization
  • Refactoring
  • Code style optimization
  • Test Case
  • Branch merge
  • Other (about what?)

🔗 Related issue link

💡 Background and solution

截屏2020-08-20 下午5 09 47

📝 Changelog

Language Changelog
🇺🇸 English Form support style of required mark with requiredMark.
🇨🇳 Chinese Form 添加 requiredMark 属性以支持设置必选样式。

☑️ Self Check before Merge

⚠️ Please check all items below before review. ⚠️

  • Doc is updated/provided or not needed
  • Demo is updated/provided or not needed
  • TypeScript definition is updated/provided or not needed
  • Changelog is provided or not needed

View rendered components/form/demo/required-mark.md
View rendered components/form/index.en-US.md
View rendered components/form/index.zh-CN.md

@pr-triage pr-triage bot added the PR: draft label Aug 20, 2020
@zombieJ
Copy link
Member Author

zombieJ commented Aug 20, 2020

有点纠结这个 API 名字,更好的应该是 requiredType 但是现在有个 hideRequiredMark 属性不得不用这个名字。我有一个想法是直接 Deprecated 掉 hideRequiredMark。然后直接 requiredType = null 来实现同样的效果,这样也免得又两个相互作用的 API。

cc @ant-design/ant-design-collaborators

@ant-design-bot
Copy link
Contributor

ant-design-bot commented Aug 20, 2020

@ant-design-bot
Copy link
Contributor

ant-design-bot commented Aug 20, 2020

@@ -75,6 +75,7 @@ const localeValues: Locale = {
back: '返回',
},
Form: {
optional: '(可选)',
Copy link
Member

Choose a reason for hiding this comment

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

最好 Form 级别也可配,有些地方用 选填

Copy link
Member Author

@zombieJ zombieJ Aug 20, 2020

Choose a reason for hiding this comment

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

这个是 locale,属性来自 Form 的 requiredMarkType,预览好了我贴一下链接方便理解。

Copy link
Member

Choose a reason for hiding this comment

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

我意思是每个 Form 对这个属性可以有控制权。

@xrkffgg
Copy link
Member

xrkffgg commented Aug 20, 2020

我的想法:


  1. 必填 显* requiredType="required"
  2. 必填 不显 * requiredType="required" + hideRequiredMark={false}
  3. 选填 不显* requiredType="optional"

requiredType 也可以改成一个 boolean 的,叫 ifRequired 类似

Item 继承 Form,可单独配置。


不过,这样好像把 required 从 rules 提出来了。。。。

@07akioni
Copy link
Contributor

07akioni commented Aug 20, 2020

requiredType 字面上容易让人脑补出其他意思。

如果未来能传 ReactNode 建议直接用 requireMark。

requiredMarkType 建议,用户都写了那么多代码了,而且还有智能提示,还是看的明白比较重要。

@github-actions
Copy link
Contributor

github-actions bot commented Aug 20, 2020

Size Change: +592 B (0%)

Total Size: 787 kB

Filename Size Change
./dist/antd-with-locales.min.js 311 kB +244 B (0%)
./dist/antd.compact.min.css 65.2 kB +41 B (0%)
./dist/antd.dark.min.css 66.5 kB +47 B (0%)
./dist/antd.min.css 65.2 kB +45 B (0%)
./dist/antd.min.js 279 kB +215 B (0%)

compressed-size-action

@afc163
Copy link
Member

afc163 commented Aug 20, 2020

- requireMarkType
+ requiredMarkType

@codesandbox-ci
Copy link

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

Latest deployment of this branch, based on commit d764bb9:

Sandbox Source
antd reproduction template Configuration

@codesandbox-ci
Copy link

codesandbox-ci bot commented Aug 20, 2020

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

Latest deployment of this branch, based on commit ab5bd14:

Sandbox Source
antd reproduction template Configuration

@kerm1it
Copy link
Member

kerm1it commented Aug 20, 2020

requiredMarktrue 为 显示,false 为隐藏,optional 为可选,后期如果想自定义可以扩展为 function

@zombieJ
Copy link
Member Author

zombieJ commented Aug 20, 2020

requiredMark 感觉可以的,hideRequiredMark 从文档里移除但是不 warning。

@hengkx
Copy link
Member

hengkx commented Aug 20, 2020

文档移除还是废弃掉吧 不然感觉有歧义

@zombieJ
Copy link
Member Author

zombieJ commented Aug 21, 2020

文档移除还是废弃掉吧 不然感觉有歧义

隔几个版本再 warning,否则用户升级一脸懵逼怎么到处都是 warning 也不好。

@codecov
Copy link

codecov bot commented Aug 21, 2020

Codecov Report

Merging #26309 into feature will increase coverage by 0.01%.
The diff coverage is 100.00%.

Impacted file tree graph

@@             Coverage Diff             @@
##           feature   #26309      +/-   ##
===========================================
+ Coverage    99.56%   99.57%   +0.01%     
===========================================
  Files          375      375              
  Lines         7316     7335      +19     
  Branches      1997     2005       +8     
===========================================
+ Hits          7284     7304      +20     
+ Misses          32       31       -1     
Impacted Files Coverage Δ
components/form/context.tsx 100.00% <ø> (ø)
components/locale-provider/index.tsx 100.00% <ø> (ø)
components/locale/default.tsx 100.00% <ø> (ø)
components/locale/zh_CN.tsx 100.00% <ø> (ø)
components/form/Form.tsx 100.00% <100.00%> (ø)
components/form/FormItem.tsx 100.00% <100.00%> (+0.77%) ⬆️
components/form/FormItemLabel.tsx 100.00% <100.00%> (ø)
components/locale-provider/LocaleReceiver.tsx 100.00% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 55c1dd0...ab5bd14. Read the comment docs.

@zombieJ zombieJ marked this pull request as ready for review August 21, 2020 03:40
@zombieJ
Copy link
Member Author

zombieJ commented Aug 21, 2020

done

// Optional mark
.@{form-item-prefix-cls}-optional {
display: inline-block;
margin-left: @margin-xss;
Copy link
Member

Choose a reason for hiding this comment

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

这个 有对应的 RTL 吗?

Copy link
Member Author

Choose a reason for hiding this comment

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

👌

Copy link
Member

Choose a reason for hiding this comment

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

我启动看一下

@xrkffgg
Copy link
Member

xrkffgg commented Aug 21, 2020

我直接改了

@kerm1it
Copy link
Member

kerm1it commented Aug 21, 2020

记得 changeLog 更新一下。

@@ -65,17 +82,18 @@ const InternalForm: React.ForwardRefRenderFunction<unknown, FormProps> = (props,
const { __INTERNAL__ } = wrapForm;
__INTERNAL__.name = name;

const formContextValue = React.useMemo(
const formContextValue = useMemo<FormContextProps>(
Copy link
Contributor

Choose a reason for hiding this comment

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

这地方有必要 useMemo 吗?感觉不是很费性能。是内部还依赖这个值的引用?

Copy link
Member Author

Choose a reason for hiding this comment

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

之前有相关 issue 中间加了 memo 还是会被上层 context 变化触发渲染

Copy link
Contributor

Choose a reason for hiding this comment

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

之前有相关 issue 中间加了 memo 还是会被上层 context 变化触发渲染

没理解,加了还触发的意思不就是加不加都差不多嘛?是说不加才触发渲染吗

@zombieJ zombieJ merged commit 60771a0 into feature Aug 21, 2020
@zombieJ zombieJ deleted the requiredMarkType branch August 21, 2020 04:58
@zombieJ zombieJ mentioned this pull request Aug 22, 2020
1 task
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.

7 participants