-
-
Notifications
You must be signed in to change notification settings - Fork 32.7k
[Button] Fix running formAction when passed #47185
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -257,7 +257,10 @@ const ButtonBase = React.forwardRef(function ButtonBase(inProps, ref) { | |
|
|
||
| const buttonProps = {}; | ||
| if (ComponentProp === 'button') { | ||
| buttonProps.type = type === undefined ? 'button' : type; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The error itself isn't fully visible, but the context suggests that buttonProps.type is being assigned a value, and the assignment is likely causing a type error or a runtime issue. |
||
| const hasFormAttributes = !!other.formAction; | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ButtonBase was defaulting to type="button" when no type prop was provided, which prevented form submission and broke formAction functionality. The fix checks for form-related attributes and skips the default type to allow the browser's natural submit behavior (type="submit").
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
I think this is worth added as a comment in the code because ButtonBase is a child of the Button |
||
| // ButtonBase was defaulting to type="button" when no type prop was provided, which prevented form submission and broke formAction functionality. | ||
| // The fix checks for form-related attributes and skips the default type to allow the browser's natural submit behavior (type="submit"). | ||
| buttonProps.type = type === undefined && !hasFormAttributes ? 'button' : type; | ||
| buttonProps.disabled = disabled; | ||
| } else { | ||
| if (!other.href && !other.to) { | ||
|
|
@@ -395,6 +398,10 @@ ButtonBase.propTypes /* remove-proptypes */ = { | |
| * if needed. | ||
| */ | ||
| focusVisibleClassName: PropTypes.string, | ||
| /** | ||
| * @ignore | ||
| */ | ||
| formAction: PropTypes.oneOfType([PropTypes.func, PropTypes.string]), | ||
| /** | ||
| * @ignore | ||
| */ | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yaa... It Was Good 👍🏻