Skip to content
Closed
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
4 changes: 4 additions & 0 deletions packages/mui-joy/src/Button/Button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -486,6 +486,10 @@ Button.propTypes /* remove-proptypes */ = {
PropTypes.oneOf(['outlined', 'plain', 'soft', 'solid']),
PropTypes.string,
]),
/**
* Supports React 19 declarative actions (formAction).
*/
formAction: PropTypes.oneOfType([PropTypes.func, PropTypes.string]),
} as any;

// @ts-ignore internal logic for ToggleButtonGroup
Expand Down
1 change: 1 addition & 0 deletions packages/mui-material/src/Button/Button.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ export interface ButtonOwnProps {
* @default 'text'
*/
variant?: OverridableStringUnion<'text' | 'outlined' | 'contained', ButtonPropsVariantOverrides>;
formAction?: ((formData: FormData) => void) | string;
}

export type ButtonTypeMap<
Expand Down
6 changes: 6 additions & 0 deletions packages/mui-material/src/Button/Button.js
Original file line number Diff line number Diff line change
Expand Up @@ -530,6 +530,7 @@ const Button = React.forwardRef(function Button(inProps, ref) {
startIcon: startIconProp,
type,
variant = 'text',
formAction,
...other
} = props;

Expand Down Expand Up @@ -605,6 +606,7 @@ const Button = React.forwardRef(function Button(inProps, ref) {
id={loading ? loadingId : idProp}
{...other}
classes={classes}
formAction={formAction}
>
{startIcon}
{loadingPosition !== 'end' && loader}
Expand Down Expand Up @@ -743,6 +745,10 @@ Button.propTypes /* remove-proptypes */ = {
PropTypes.oneOf(['contained', 'outlined', 'text']),
PropTypes.string,
]),
/**
* Supports React 19's declarative form actions.
*/
formAction: PropTypes.oneOfType([PropTypes.func, PropTypes.string]),
};

export default Button;
10 changes: 10 additions & 0 deletions packages/mui-material/src/Button/Button.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -853,5 +853,15 @@ describe('<Button />', () => {
);
expect(screen.getByRole('button')).to.have.class(classes.loadingPositionEnd);
});
it('forwards formAction to the DOM button', () => {
const handleAction = jest.fn();
render(<Button formAction={handleAction}>Submit</Button>);

const button = screen.getByRole('button', { name: 'Submit' });
expect(button).toHaveAttribute('formaction');

fireEvent.click(button);
expect(handleAction).toHaveBeenCalledWith(expect.any(FormData));
});
});
});
Loading