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: add hideRequiredMark attribute types and add demo #20263
feat: add hideRequiredMark attribute types and add demo #20263
Conversation
Deploy preview for ant-design ready! Built with commit cdb3a06 |
关于需求理解:Form中增加可选字段labelSelectiveFilling,类型为Boolean值,当有这个字段的时候,如果没有配置规则必填则为选填,如果配置了必填则不显示选填。@ycjcl868 |
我感觉字段名应该还需要讨论下。 |
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 cdb3a06:
|
Codecov Report
@@ Coverage Diff @@
## feat-form-rule #20263 +/- ##
==================================================
- Coverage 97.56% 97.55% -0.01%
==================================================
Files 294 294
Lines 6845 6836 -9
Branches 1880 1837 -43
==================================================
- Hits 6678 6669 -9
Misses 167 167
Continue to review full report at Codecov.
|
字段名后面再改也可以 |
2、这个 PR #20235 ,我加了 max-width,rebase 下就可以了 |
/rebase |
components/form/FormItemLabel.tsx
Outdated
@@ -64,6 +67,9 @@ const FormItemLabel: React.FC<FormItemLabelProps & { required: boolean; prefixCl | |||
title={typeof label === 'string' ? label : ''} | |||
> | |||
{labelChildren} | |||
{!required && labelSelectiveFilling && ( | |||
<span className={`${labelClsBasic}-tag`}>(选填)</span> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这里要用国际化
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
加一个中文和英文,剩下的再补充。
ant-design/components/locale/zh_CN.tsx
Lines 59 to 61 in d7d4beb
PageHeader: { | |
back: '返回', | |
}, |
components/form/Form.tsx
Outdated
@@ -71,6 +73,7 @@ const InternalForm: React.FC<FormProps> = (props, ref) => { | |||
name, | |||
labelAlign, | |||
labelCol, | |||
labelSelectiveFilling, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这个属性是什么意思?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
改成 showLabelOptionalText
,当这一项为 true 时,hideRequiredMark
默认为 true
。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这个好
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
<Form hideRequiredMark />
<Form hideRequiredMark={false} />
<Form hideRequiredMark={{ showLabelOptionalText: true }} />
这样吧,不存在既要 *
又要 (可选)
的情况。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hideRequiredMark这个功能有了吗
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
有的。
components/form/FormItemLabel.tsx
Outdated
{typeof hideRequiredMark === 'object' && | ||
Object.prototype.toString.call(hideRequiredMark) === '[object Object]' && | ||
hideRequiredMark.showLabelOptionalText && ( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
typeof hideRequiredMark === 'object'
这一段ts能识别,Object.prototype.toString.call(hideRequiredMark) === '[object Object]'
这一段才是真正判断,有好的写法吗?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
typeof hideRequiredMark === 'object'
,够用就行。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
填个null就gg了
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Object.prototype.toString.call(hideRequiredMark) === '[object Object]' && (hideRequiredMark as object).showLabelOptionalText
ts不识别或者断言?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
填 null
ts 会报错的。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
哈哈哈,呆了,前面还有类型定义 😛
components/form/FormItemLabel.tsx
Outdated
<LocaleReceiver componentName="Form" defaultLocale={defaultLocale.Form}> | ||
{(locale: { optionalText: string }) => ( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
defaultLocale时间处理建议统一收口掉?感觉自动识别时区来做默认值更好?关于本地类型也能通过cli自动生成收口在一个位置方便使用?
请问每次测试都必须全量更新快照吗?有更快的方法吗? |
|
|
||
## zh-CN | ||
|
||
隐藏必选标记 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
隐藏必选标记 | |
隐藏必选标记,展示(可选) |
PR 的标题修改一下,覆盖率需要提升上来。 |
Co-Authored-By: 偏右 <afc163@gmail.com>
Co-Authored-By: 偏右 <afc163@gmail.com>
Co-Authored-By: 偏右 <afc163@gmail.com>
components/form/context.tsx
Outdated
wrapperCol?: ColProps; | ||
} | ||
|
||
export interface HideRequiredMarkProps { | ||
showLabelOptionalText: boolean; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
labelOptionalText: string | ReactNode
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
optionalMark 如何?
只是对样式的修改,不涉及校验规则。
|
ci broken |
components/form/FormItemLabel.tsx
Outdated
@@ -22,6 +25,9 @@ const FormItemLabel: React.FC<FormItemLabelProps & { required: boolean; prefixCl | |||
required, | |||
}) => { | |||
if (!label) return null; | |||
console.log(label, required); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
console
@@ -60,4 +60,7 @@ export default { | |||
PageHeader: { | |||
back: 'Back', | |||
}, | |||
Form: { | |||
optionalText: ' (optional)', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
optionalText: ' (optional)', | |
optionalText: '(optional)', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这里是因为偏右故意加的空格
🤔 This is a ...
🔗 Related issue link
#20221
💡 Background and solution
hideRequiredMark属性本来是为了方便去掉*的,现在需要在去掉星号的同时其他未必选的label后加副标题。
📝 Changelog
☑️ Self Check before Merge