Skip to content

Commit

Permalink
fix: fix decorator attrs is not passed down correctly (#2369)
Browse files Browse the repository at this point in the history
  • Loading branch information
muuyao authored Oct 31, 2021
1 parent 4b3d092 commit fee4af0
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 8 deletions.
21 changes: 14 additions & 7 deletions packages/vue/src/__tests__/field.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,18 @@ Vue.component('VoidField', VoidField)
Vue.component('Field', Field)
Vue.component('ReactiveField', ReactiveField as unknown as Vue)

const Decorator: FunctionalComponentOptions = {
functional: true,
render(h, context) {
return h('div', context.data, context.children)
const Decorator = defineComponent({
props: ['label'],
render(h) {
return h(
'div',
{
attrs: this.$attrs,
},
[this.label, this.$slots.default]
)
},
}
})

const Input = defineComponent({
props: ['value'],
Expand Down Expand Up @@ -64,7 +70,7 @@ test('render field', async () => {
const atBlur = jest.fn()
const atFocus = jest.fn()

const { getByTestId, queryByTestId } = render(
const { getByTestId, queryByTestId, queryByText } = render(
defineComponent({
name: 'TestComponent',
setup() {
Expand All @@ -82,7 +88,7 @@ test('render field', async () => {
template: `<FormProvider :form="form">
<Field
name="aa"
:decorator="[Decorator]"
:decorator="[Decorator, {label: 'aa-decorator'}]"
:component="[Input, { onChange }]"
/>
<ArrayField name="bb" :decorator="[Decorator]">
Expand Down Expand Up @@ -146,6 +152,7 @@ test('render field', async () => {
expect(form.query('aa').get('value')).toEqual('123')
expect(form.query('kk').get('value')).toEqual('123')
expect(getByTestId('mm-children')).not.toBeUndefined()
expect(queryByText('aa-decorator')).not.toBeNull()
})

test('render field with html attrs', async () => {
Expand Down
4 changes: 3 additions & 1 deletion packages/vue/src/components/ReactiveField.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,9 @@ export default observer(
{
style,
class: classes,
attrs: decoratorData,
attrs: {
...decoratorData,
},
},
{
default: () => childNodes,
Expand Down

0 comments on commit fee4af0

Please sign in to comment.