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

fix(Form): fix requiredMark default value #1776

Merged
merged 2 commits into from
Nov 11, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion src/form/form-item-props.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export default {
/** 字段标签名称 */
label: {
type: [String, Function] as PropType<TdFormItemProps['label']>,
default: '',
},
/** 表单字段标签对齐方式:左对齐、右对齐、顶部对齐。默认使用 Form 的对齐方式,优先级高于 Form.labelAlign */
labelAlign: {
Expand All @@ -38,7 +39,10 @@ export default {
type: [String, Number] as PropType<TdFormItemProps['name']>,
},
/** 是否显示必填符号(*),优先级高于 Form.requiredMark */
requiredMark: Boolean,
requiredMark: {
type: Boolean,
default: undefined,
},
/** 表单字段校验规则 */
rules: {
type: Array as PropType<TdFormItemProps['rules']>,
Expand All @@ -56,6 +60,7 @@ export default {
/** 校验状态图标,值为 `true` 显示默认图标,默认图标有 成功、失败、警告 等,不同的状态图标不同。`statusIcon` 值为 `false`,不显示图标。`statusIcon` 值类型为渲染函数,则可以自定义右侧状态图标。优先级高级 Form 的 statusIcon */
statusIcon: {
type: [Boolean, Function] as PropType<TdFormItemProps['statusIcon']>,
default: undefined,
},
/** 是否显示校验成功的边框,默认不显示 */
successBorder: Boolean,
Expand Down
12 changes: 10 additions & 2 deletions src/form/props.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@ export default {
default: () => ({}),
},
/** 是否禁用整个表单 */
disabled: Boolean,
disabled: {
type: Boolean,
default: undefined,
},
/** 表单错误信息配置,示例:`{ idcard: '请输入正确的身份证号码', max: '字符长度不能超过 ${max}' }` */
errorMessage: {
type: Object as PropType<TdFormProps['errorMessage']>,
Expand Down Expand Up @@ -54,7 +57,10 @@ export default {
default: true,
},
/** 是否显示必填符号(*),默认显示 */
requiredMark: Boolean,
requiredMark: {
type: Boolean,
default: undefined,
},
/** 重置表单的方式,值为 empty 表示重置表单为空,值为 initial 表示重置表单数据为初始值 */
resetType: {
type: String as PropType<TdFormProps['resetType']>,
Expand All @@ -71,6 +77,7 @@ export default {
/** 表单校验不通过时,是否自动滚动到第一个校验不通过的字段,平滑滚动或是瞬间直达。值为空则表示不滚动 */
scrollToFirstError: {
type: String as PropType<TdFormProps['scrollToFirstError']>,
default: '' as TdFormProps['scrollToFirstError'],
validator(val: TdFormProps['scrollToFirstError']): boolean {
if (!val) return true;
return ['', 'smooth', 'auto'].includes(val);
Expand All @@ -84,6 +91,7 @@ export default {
/** 校验状态图标,值为 `true` 显示默认图标,默认图标有 成功、失败、警告 等,不同的状态图标不同。`statusIcon` 值为 `false`,不显示图标。`statusIcon` 值类型为渲染函数,则可以自定义右侧状态图标 */
statusIcon: {
type: [Boolean, Function] as PropType<TdFormProps['statusIcon']>,
default: undefined,
},
/** 【讨论中】当校验结果只有告警信息时,是否触发 `submit` 提交事件 */
submitWithWarningMessage: Boolean,
Expand Down
3 changes: 3 additions & 0 deletions src/form/type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ export interface TdFormProps<FormData extends Data = Data> {
rules?: { [field in keyof FormData]: Array<FormRule> };
/**
* 表单校验不通过时,是否自动滚动到第一个校验不通过的字段,平滑滚动或是瞬间直达。值为空则表示不滚动
* @default ''
*/
scrollToFirstError?: '' | 'smooth' | 'auto';
/**
Expand Down Expand Up @@ -136,6 +137,7 @@ export interface TdFormItemProps {
help?: string | TNode;
/**
* 字段标签名称
* @default ''
*/
label?: string | TNode;
/**
Expand All @@ -156,6 +158,7 @@ export interface TdFormItemProps {
requiredMark?: boolean;
/**
* 表单字段校验规则
* @default []
*/
rules?: Array<FormRule>;
/**
Expand Down
32 changes: 8 additions & 24 deletions src/time-picker/__tests__/index.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -122,18 +122,10 @@ describe('TimePicker', () => {
popupProps: {
visible: true,
},
disableTime: (h) => {
const disableHour = [1, 2, 3];
if (h > 4) {
return {
hour: disableHour,
minute: [1, 2, 3, 4, 5],
};
}
return {
hour: disableHour,
};
},
disableTime: () => ({
hour: [1, 2, 3],
minute: [1, 2, 3, 4, 5],
}),
});
const panelNode = document.querySelector('.t-time-picker__panel');

Expand All @@ -156,18 +148,10 @@ describe('TimePicker', () => {
visible: false,
},
hideDisabledTime: false,
disableTime: (h) => {
const disableHour = [1, 2, 3];
if (h > 4) {
return {
hour: disableHour,
minute: [1, 2, 3, 4, 5],
};
}
return {
hour: disableHour,
};
},
disableTime: () => ({
hour: [1, 2, 3],
minute: [1, 2, 3, 4, 5],
}),
},
});
await wrapper.setProps({
Expand Down