diff --git a/.changeset/silly-lemons-draw.md b/.changeset/silly-lemons-draw.md new file mode 100644 index 00000000..2ef25ebc --- /dev/null +++ b/.changeset/silly-lemons-draw.md @@ -0,0 +1,5 @@ +--- +"@chakra-ui/vue": patch +--- + +Pass all listeners to render function in CFlex, Stack diff --git a/packages/chakra-ui-core/src/CFlex/CFlex.js b/packages/chakra-ui-core/src/CFlex/CFlex.js index d2e577a3..da6a0ea0 100644 --- a/packages/chakra-ui-core/src/CFlex/CFlex.js +++ b/packages/chakra-ui-core/src/CFlex/CFlex.js @@ -38,7 +38,8 @@ const CFlex = { render (h) { return h(this.as, { class: this.className, - attrs: this.computedAttrs + attrs: this.computedAttrs, + on: this.computedListeners }, this.$slots.default) } } diff --git a/packages/chakra-ui-core/src/CFlex/tests/CFlex.test.js b/packages/chakra-ui-core/src/CFlex/tests/CFlex.test.js index e5abcb5b..b5303c63 100644 --- a/packages/chakra-ui-core/src/CFlex/tests/CFlex.test.js +++ b/packages/chakra-ui-core/src/CFlex/tests/CFlex.test.js @@ -1,5 +1,5 @@ import CFlex from '..' -import { render, screen } from '@/tests/test-utils' +import { render, screen, userEvent } from '@/tests/test-utils' const renderComponent = (props) => { const inlineAttrs = (props && props.inlineAttrs) || '' @@ -11,21 +11,56 @@ const renderComponent = (props) => { return render(base) } -it('should render correctly', () => { - const { asFragment } = renderComponent() +describe('CFlex', () => { + it('should render correctly', () => { + const { asFragment } = renderComponent() - expect(asFragment()).toMatchSnapshot() -}) + expect(asFragment()).toMatchSnapshot() + }) + + it('should change styles', () => { + const inlineAttrs = 'align="center" justify="center" direction="column"' + const { asFragment } = renderComponent({ inlineAttrs }) + + expect(asFragment()).toMatchSnapshot() + + const flex = screen.getByTestId('flex') + expect(flex).toHaveStyle('display: flex') + expect(flex).toHaveStyle('align-items: center') + expect(flex).toHaveStyle('justify-content: center') + expect(flex).toHaveStyle('flex-direction: column') + }) + + it('should preserve inherited event listeners', async () => { + const handleClick = jest.fn() + renderComponent({ + inlineAttrs: '@click="handleClick"', + methods: { + handleClick + } + }) -it('should change styles', () => { - const inlineAttrs = 'align="center" justify="center" direction="column"' - const { asFragment } = renderComponent({ inlineAttrs }) + await userEvent.click(screen.getByTestId('flex')) + expect(handleClick).toHaveBeenCalledTimes(1) + }) - expect(asFragment()).toMatchSnapshot() + it('should preserve inherited event listeners with custom `as` component', async () => { + const handleSubmit = jest.fn((event) => { + expect(event.target).toBe(screen.getByTestId('flex-as-form')) + }) + renderComponent({ + template: ` + + +