Skip to content

Feat: Form attribute of button with type submit #7892

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 13 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions packages/@react-spectrum/button/test/Button.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -363,5 +363,19 @@ describe('Button', function () {
expect(button).not.toHaveAttribute('href');
});

it('associates button with form with form id', () => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks like the test is failing, can you see why the form attribute isn't making it onto the button? it's likely being filtered out somewhere

let {getByRole} = render(
<Provider theme={defaultTheme}>
<Form id="testForm">
<Checkbox>An Input</Checkbox>
</Form>
<Button form="testForm">Submit</Button>
</Provider>
);

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
});
8 changes: 7 additions & 1 deletion packages/@react-types/button/src/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,13 @@ export interface SpectrumButtonProps<T extends ElementType = 'button'> extends A
* Whether the button should be displayed with a quiet style.
* @deprecated
*/
isQuiet?: boolean
isQuiet?: boolean,
/**
* The `<form>` element to associate the button with.
* The value of this attribute must be the id of a `<form>` 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<ButtonProps, 'onClick'>, StyleProps {
Expand Down