diff --git a/CHANGELOG.md b/CHANGELOG.md index 3c631d366e..a34b450b19 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,11 +7,15 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased - React] -- Nothing yet! +### Fixes + +- Only add `type=button` to real buttons ([#709](https://github.com/tailwindlabs/headlessui/pull/709)) ## [Unreleased - Vue] -- Nothing yet! +### Fixes + +- Only add `type=button` to real buttons ([#709](https://github.com/tailwindlabs/headlessui/pull/709)) ## [@headlessui/react@v1.4.0] - 2021-07-29 diff --git a/packages/@headlessui-react/src/components/disclosure/disclosure.test.tsx b/packages/@headlessui-react/src/components/disclosure/disclosure.test.tsx index a6528a2d6d..6c72cff4e1 100644 --- a/packages/@headlessui-react/src/components/disclosure/disclosure.test.tsx +++ b/packages/@headlessui-react/src/components/disclosure/disclosure.test.tsx @@ -20,7 +20,7 @@ jest.mock('../../hooks/use-id') afterAll(() => jest.restoreAllMocks()) function nextFrame() { - return new Promise(resolve => { + return new Promise(resolve => { requestAnimationFrame(() => { requestAnimationFrame(() => { resolve() @@ -296,6 +296,66 @@ describe('Rendering', () => { assertDisclosurePanel({ state: DisclosureState.Visible }) }) ) + + describe('`type` attribute', () => { + it('should set the `type` to "button" by default', async () => { + render( + + Trigger + + ) + + expect(getDisclosureButton()).toHaveAttribute('type', 'button') + }) + + it('should not set the `type` to "button" if it already contains a `type`', async () => { + render( + + Trigger + + ) + + expect(getDisclosureButton()).toHaveAttribute('type', 'submit') + }) + + it('should set the `type` to "button" when using the `as` prop which resolves to a "button"', async () => { + let CustomButton = React.forwardRef((props, ref) => ( +