Skip to content
Merged
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
9 changes: 8 additions & 1 deletion packages/mui-material/src/ButtonBase/ButtonBase.js
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,10 @@ const ButtonBase = React.forwardRef(function ButtonBase(inProps, ref) {

Choose a reason for hiding this comment

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

Yaa... It Was Good 👍🏻

const buttonProps = {};
if (ComponentProp === 'button') {
buttonProps.type = type === undefined ? 'button' : type;

Choose a reason for hiding this comment

The 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;
Copy link
Contributor Author

Choose a reason for hiding this comment

The 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").

Copy link
Member

@siriwatknp siriwatknp Nov 7, 2025

Choose a reason for hiding this comment

The 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

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) {
Expand Down Expand Up @@ -395,6 +398,10 @@ ButtonBase.propTypes /* remove-proptypes */ = {
* if needed.
*/
focusVisibleClassName: PropTypes.string,
/**
* @ignore
*/
formAction: PropTypes.oneOfType([PropTypes.func, PropTypes.string]),
/**
* @ignore
*/
Expand Down
22 changes: 22 additions & 0 deletions packages/mui-material/src/ButtonBase/ButtonBase.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1294,4 +1294,26 @@ describe('<ButtonBase />', () => {
expect(ref.current).not.to.equal(null);
});
});

describe('form attributes', () => {
it('should not set default type when formAction is present', async function test() {
if (window.navigator.userAgent.includes('jsdom')) {
this.skip();
}

const formActionSpy = spy();
const { user } = render(
<form>
<ButtonBase formAction={formActionSpy}>Submit</ButtonBase>
</form>,
);
const button = screen.getByRole('button');

// Should not have type="button" when formAction is present
expect(button).not.to.have.attribute('type', 'button');
expect(button).to.have.attribute('formaction');
await user.click(button);
expect(formActionSpy.callCount).to.equal(1);
});
});
});
Loading