Skip to content

Commit

Permalink
feat: inline error
Browse files Browse the repository at this point in the history
  • Loading branch information
cole committed Jul 8, 2024
1 parent 2050fb7 commit 6556bcf
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
import { defineComponent, ref, unref } from 'vue'
import { Popover } from 'ant-design-vue'
import { pick } from 'lodash-es'
import classNames from '@/utils/classNames/bind'
import styles from './style/index.module.scss'

const cx = classNames.bind(styles)

export default defineComponent({
inheritAttrs: false,
props: {
...Popover.props,
trigger: {
type: String,
default: 'click'
},
placement: {
type: String,
default: 'topLeft'
},
errors: {
type: Array,
default: () => ([])
}
},
setup (props, { slots }) {
const sOpen = ref(false)

function onOpenChange (value) {
if (value !== unref(sOpen)) {
sOpen.value = value
}
}

return () => {
const { errors } = props

const popoverProps = {
...pick(props, Object.keys(Popover.props)),
open: errors.length !== 0 ? unref(sOpen) : false,
onOpenChange: onOpenChange
}

const popoverSlots = {
content: () => (
<div class={cx('with-help')}>
{errors}
</div>
)
}
return (
<Popover {...popoverProps} v-slots={popoverSlots}>
<div onClick={() => false}>
{slots.default && slots.default()}
</div>
</Popover>
)
}
}
})
Empty file.
7 changes: 6 additions & 1 deletion src/packages/table/editable-table/index.jsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { defineComponent, reactive, watch } from 'vue'
import { Field, Form } from '@/packages/form'
import Table from '../table'
import InlineError from './components/inline-error'
import { omit, pick } from 'lodash-es'

const editable = {
Expand Down Expand Up @@ -56,7 +57,11 @@ export default defineComponent({
fieldProps: { ...fieldProps, style: { width: '100%' } },
formItemProps: needFormItemProps
}
return <Field {...needFieldProps}/>
return (
<InlineError errors={['此项为必填项']}>
<Field {...needFieldProps}/>
</InlineError>
)
}

return () => {
Expand Down

0 comments on commit 6556bcf

Please sign in to comment.