Skip to content

Commit c3be129

Browse files
committed
Allow empty string to be passed to formAction
1 parent ef8bdbe commit c3be129

File tree

2 files changed

+20
-21
lines changed

2 files changed

+20
-21
lines changed

packages/react-dom-bindings/src/shared/DOMProperty.js

+12-1
Original file line numberDiff line numberDiff line change
@@ -636,7 +636,18 @@ properties[xlinkHref] = new PropertyInfoRecord(
636636
false, // removeEmptyString
637637
);
638638

639-
['src', 'href', 'action', 'formAction'].forEach(attributeName => {
639+
// $FlowFixMe[invalid-constructor] Flow no longer supports calling new on functions
640+
properties['formAction'] = new PropertyInfoRecord(
641+
'formAction',
642+
STRING,
643+
false, // mustUseProperty
644+
'formaction', // attributeName
645+
null, // attributeNamespace
646+
true, // sanitizeURL
647+
false, // removeEmptyString
648+
);
649+
650+
['src', 'href', 'action'].forEach(attributeName => {
640651
// $FlowFixMe[invalid-constructor] Flow no longer supports calling new on functions
641652
properties[attributeName] = new PropertyInfoRecord(
642653
attributeName,

packages/react-dom/src/__tests__/ReactDOMComponent-test.js

+8-20
Original file line numberDiff line numberDiff line change
@@ -533,29 +533,17 @@ describe('ReactDOMComponent', () => {
533533
expect(node.hasAttribute('action')).toBe(false);
534534
});
535535

536-
it('should not add an empty formAction attribute', () => {
536+
it('allows empty string of a formAction to override the default of a parent', () => {
537537
const container = document.createElement('div');
538-
expect(() =>
539-
ReactDOM.render(<button formAction="" />, container),
540-
).toErrorDev(
541-
'An empty string ("") was passed to the formAction attribute. ' +
542-
'To fix this, either do not render the element at all ' +
543-
'or pass null to formAction instead of an empty string.',
538+
ReactDOM.render(
539+
<form action="hello">
540+
<button formAction="" />,
541+
</form>,
542+
container,
544543
);
545544
const node = container.firstChild;
546-
expect(node.hasAttribute('formAction')).toBe(false);
547-
548-
ReactDOM.render(<button formAction="abc" />, container);
549-
expect(node.hasAttribute('formAction')).toBe(true);
550-
551-
expect(() =>
552-
ReactDOM.render(<button formAction="" />, container),
553-
).toErrorDev(
554-
'An empty string ("") was passed to the formAction attribute. ' +
555-
'To fix this, either do not render the element at all ' +
556-
'or pass null to formAction instead of an empty string.',
557-
);
558-
expect(node.hasAttribute('formAction')).toBe(false);
545+
expect(node.hasAttribute('formaction')).toBe(true);
546+
expect(node.getAttribute('formaction')).toBe('');
559547
});
560548

561549
it('should not filter attributes for custom elements', () => {

0 commit comments

Comments
 (0)