diff --git a/packages/@react-spectrum/button/test/Button.test.js b/packages/@react-spectrum/button/test/Button.test.js index 7d732f9707c..8357fe302f0 100644 --- a/packages/@react-spectrum/button/test/Button.test.js +++ b/packages/@react-spectrum/button/test/Button.test.js @@ -363,5 +363,19 @@ describe('Button', function () { expect(button).not.toHaveAttribute('href'); }); + it('associates button with form with form id', () => { + let {getByRole} = render( + +
+ An Input +
+ +
+ ); + + let button = getByRole('button'); + expect(button).toHaveAttribute('form', 'testForm'); + }); + // 'implicit submission' can't be tested https://github.com/testing-library/react-testing-library/issues/487 }); diff --git a/packages/@react-types/button/src/index.d.ts b/packages/@react-types/button/src/index.d.ts index 4c7ee4ffa5a..7d35bd6e128 100644 --- a/packages/@react-types/button/src/index.d.ts +++ b/packages/@react-types/button/src/index.d.ts @@ -95,7 +95,13 @@ export interface SpectrumButtonProps extends A * Whether the button should be displayed with a quiet style. * @deprecated */ - isQuiet?: boolean + isQuiet?: boolean, + /** + * The `
` element to associate the button with. + * The value of this attribute must be the id of a `` in the same document. + * See [form attribute](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/button#form). + */ + form?: string } export interface SpectrumActionButtonProps extends AriaBaseButtonProps, Omit, StyleProps {