Skip to content

Commit 04eb2cd

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

File tree

2 files changed

+21
-21
lines changed

2 files changed

+21
-21
lines changed

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

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -636,7 +636,19 @@ properties[xlinkHref] = new PropertyInfoRecord(
636636
false, // removeEmptyString
637637
);
638638

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

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

Lines changed: 8 additions & 20 deletions
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)