Skip to content

Commit

Permalink
feat: 优化 extra 占位问题
Browse files Browse the repository at this point in the history
  • Loading branch information
honkinglin committed May 16, 2022
1 parent c971468 commit 1b7457d
Show file tree
Hide file tree
Showing 4 changed files with 434 additions and 542 deletions.
40 changes: 22 additions & 18 deletions src/form/form-item.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,29 @@ export default defineComponent({
this.CLASS_NAMES.formItem,
this.FORM_ITEM_CLASS_PREFIX + this.name,
{
[this.CLASS_NAMES.formItemWithHelp]: this.help,
[this.CLASS_NAMES.formItemWithExtra]: this.renderTipsInfo(),
[this.CLASS_NAMES.formItemWithHelp]: this.helpNode,
[this.CLASS_NAMES.formItemWithExtra]: this.extraNode,
},
];
},
helpNode() {
let helpVNode: VNode = null;
if (this.help) {
helpVNode = <div class={this.CLASS_NAMES.help}>{this.help}</div>;
}
return helpVNode;
},
extraNode() {
const parent = this.form;
const list = this.errorList;
if (parent.showErrorMessage && list && list[0] && list[0].message) {
return <div class={this.CLASS_NAMES.extra}>{list[0].message}</div>;
}
if (this.successList.length) {
return <div class={this.CLASS_NAMES.extra}>{this.successList[0].message}</div>;
}
return null;
},
labelClasses() {
const { FROM_LABEL } = this;
const parent = this.form;
Expand Down Expand Up @@ -255,21 +273,6 @@ export default defineComponent({
</div>
);
},
renderTipsInfo(): VNode {
const parent = this.form;
let helpVNode: VNode = <div class={this.CLASS_NAMES.help}></div>;
if (this.help) {
helpVNode = <div class={this.CLASS_NAMES.help}>{this.help}</div>;
}
const list = this.errorList;
if (parent.showErrorMessage && list && list[0] && list[0].message) {
return <div class={this.CLASS_NAMES.extra}>{list[0].message}</div>;
}
if (this.successList.length) {
return <div class={this.CLASS_NAMES.extra}>{this.successList[0].message}</div>;
}
return helpVNode;
},
getDefaultIcon(): TNodeReturnValue {
const resultIcon = (Icon: IconConstructor) => (
<span class={this.CLASS_NAMES.status}>
Expand Down Expand Up @@ -371,7 +374,8 @@ export default defineComponent({
{this.$slots.default ? this.$slots.default() : null}
{this.getSuffixIcon()}
</div>
{this.renderTipsInfo()}
{this.helpNode}
{this.extraNode}
</div>
</div>
);
Expand Down
Loading

0 comments on commit 1b7457d

Please sign in to comment.