Skip to content

Commit

Permalink
feat(form): fix show-label (tusen-ai#858)
Browse files Browse the repository at this point in the history
  • Loading branch information
kev1nzh_ark committed Aug 18, 2021
1 parent 8cbc8ac commit 21a941d
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 14 deletions.
8 changes: 4 additions & 4 deletions src/form/src/FormItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ function wrapValidator (
export default defineComponent({
name: 'FormItem',
props: formItemProps,
setup (props, context) {
setup (props) {
useInjectionInstanceCollection(
formItemInstsInjectionKey,
'formItems',
Expand All @@ -158,7 +158,7 @@ export default defineComponent({
const { mergedClsPrefixRef } = useConfig(props)
const NForm = inject(formInjectionKey, null)
const formItemSizeRefs = formItemSize(props)
const formItemMiscRefs = formItemMisc(props, context.slots)
const formItemMiscRefs = formItemMisc(props)
const { validationErrored: validationErroredRef } = formItemMiscRefs
const { mergedRequired: mergedRequiredRef, mergedRules: mergedRulesRef } =
formItemRule(props)
Expand Down Expand Up @@ -416,11 +416,11 @@ export default defineComponent({
`${mergedClsPrefix}-form-item`,
`${mergedClsPrefix}-form-item--${this.mergedSize}-size`,
`${mergedClsPrefix}-form-item--${this.mergedLabelPlacement}-labelled`,
!this.mergedShowLabel && `${mergedClsPrefix}-form-item--no-label`
(!this.mergedShowLabel || this.label === false) && `${mergedClsPrefix}-form-item--no-label`
]}
style={this.cssVars as CSSProperties}
>
{this.mergedShowLabel ? (
{this.mergedShowLabel && (this.label || $slots.label) ? (
<label
class={`${mergedClsPrefix}-form-item-label`}
style={this.mergedLabelStyle as any}
Expand Down
15 changes: 5 additions & 10 deletions src/form/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export function formItemSize (props: FormItemSetupProps): {
}

// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
export function formItemMisc (props: FormItemSetupProps, slots: Slots) {
export function formItemMisc (props: FormItemSetupProps) {
const NForm = inject(formInjectionKey, null)
const mergedLabelWidthRef = computed(() => {
if (mergedLabelPlacementRef.value === 'top') return
Expand Down Expand Up @@ -73,15 +73,10 @@ export function formItemMisc (props: FormItemSetupProps, slots: Slots) {
return true
})
const mergedShowLabelRef = computed(() => {
const { showLabel, label } = props
let mergedShowLabel: boolean | undefined = true

if (NForm?.showLabel !== undefined) mergedShowLabel = NForm.showLabel
if (showLabel !== undefined) mergedShowLabel = showLabel

return label === false
? !mergedShowLabel
: mergedShowLabel && (label || slots.label)
const { showLabel } = props
if (showLabel !== undefined) return showLabel
if (NForm?.showLabel !== undefined) return NForm.showLabel
return true
})
return {
validationErrored: validationErroredRef,
Expand Down

0 comments on commit 21a941d

Please sign in to comment.