Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,10 @@ function extractEvents(
(nativeEvent: any).submitter;
let submitterAction;
if (submitter) {
submitterAction = (getFiberCurrentPropsFromNode(submitter): any).formAction;
const submitterProps = getFiberCurrentPropsFromNode(submitter);
submitterAction = submitterProps
? (submitterProps: any).formAction
: submitter.getAttribute('formAction');
if (submitterAction != null) {
// The submitter overrides the form action.
action = submitterAction;
Expand Down
36 changes: 36 additions & 0 deletions packages/react-dom/src/__tests__/ReactDOMForm-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -414,4 +414,40 @@ describe('ReactDOMForm', () => {
expect(nav).toBe('Navigate to: http://example.com/submit');
expect(actionCalled).toBe(false);
});

// @gate enableFormActions || !__DEV__
it('allows a non-react html formaction to be invoked', async () => {
let actionCalled = false;

function action(formData) {
actionCalled = true;
}

const root = ReactDOMClient.createRoot(container);
await act(async () => {
root.render(
<form
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

If the form is not a React element is already handled by the event system itself.

action={action}
dangerouslySetInnerHTML={{
__html: `
<input
type="submit"
formAction="http://example.com/submit"
/>
`,
}}
/>,
);
});

const node = container.getElementsByTagName('input')[0];
let nav;
try {
submit(node);
} catch (x) {
nav = x.message;
}
expect(nav).toBe('Navigate to: http://example.com/submit');
expect(actionCalled).toBe(false);
});
});