Skip to content

Commit

Permalink
feat(snaps): Added support for form property in Snap footer buttons (#…
Browse files Browse the repository at this point in the history
…27158)

<!--
Please submit this PR as a draft initially.
Do not mark it as "Ready for review" until the template has been
completely filled out, and PR status checks have passed at least once.
-->

## **Description**
This PR adds changes required to enable Snaps' footer buttons to submit
and reset forms.

<!--
Write a short description of the changes included in this pull request,
also include relevant motivation and context. Have in mind the following
questions:
1. What is the reason for the change?
2. What is the improvement/solution?
-->

[![Open in GitHub
Codespaces](https://github.com/codespaces/badge.svg)](https://codespaces.new/MetaMask/metamask-extension/pull/27158?quickstart=1)

## **Related issues**

Fixes: MetaMask/snaps#2691

## **Manual testing steps**

1. Go to this page...
2.
3.

## **Screenshots/Recordings**

<!-- If applicable, add screenshots and/or recordings to visualize the
before and after of your change. -->

### **Before**

<!-- [screenshots/recordings] -->

### **After**

<!-- [screenshots/recordings] -->

## **Pre-merge author checklist**

- [ ] I've followed [MetaMask Contributor
Docs](https://github.com/MetaMask/contributor-docs) and [MetaMask
Extension Coding
Standards](https://github.com/MetaMask/metamask-extension/blob/develop/.github/guidelines/CODING_GUIDELINES.md).
- [ ] I've completed the PR template to the best of my ability
- [ ] I’ve included tests if applicable
- [ ] I’ve documented my code using [JSDoc](https://jsdoc.app/) format
if applicable
- [ ] I’ve applied the right labels on the PR (see [labeling
guidelines](https://github.com/MetaMask/metamask-extension/blob/develop/.github/guidelines/LABELING_GUIDELINES.md)).
Not required for external contributors.

## **Pre-merge reviewer checklist**

- [ ] I've manually tested the PR (e.g. pull and build branch, run the
app, test code being changed).
- [ ] I confirm that this PR addresses all acceptance criteria described
in the ticket it closes and includes the necessary testing evidence such
as recordings and or screenshots.
  • Loading branch information
ritave authored and Mrtenz committed Sep 19, 2024
1 parent 8e6ea93 commit 1796697
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 4 deletions.
25 changes: 21 additions & 4 deletions ui/components/app/snaps/snap-footer-button/snap-footer-button.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
import React, { FunctionComponent, MouseEvent as ReactMouseEvent } from 'react';
import { ButtonVariant, UserInputEventType } from '@metamask/snaps-sdk';
import { Button, ButtonSize, IconSize } from '../../../component-library';
import {
ButtonType,
ButtonVariant,
UserInputEventType,
} from '@metamask/snaps-sdk';
import {
Button,
ButtonLinkProps,
ButtonSize,
IconSize,
} from '../../../component-library';
import {
AlignItems,
Display,
Expand All @@ -15,17 +24,23 @@ type SnapFooterButtonProps = {
onCancel?: () => void;
};

export const SnapFooterButton: FunctionComponent<SnapFooterButtonProps> = ({
export const SnapFooterButton: FunctionComponent<
SnapFooterButtonProps & ButtonLinkProps<'button'>
> = ({
onCancel,
name,
children,
isSnapAction = false,
type,
form,
...props
}) => {
const { handleEvent, snapId } = useSnapInterfaceContext();

const handleSnapAction = (event: ReactMouseEvent<HTMLElement>) => {
event.preventDefault();
if (type === ButtonType.Button) {
event.preventDefault();
}

handleEvent({
event: UserInputEventType.ButtonClickEvent,
Expand All @@ -38,6 +53,8 @@ export const SnapFooterButton: FunctionComponent<SnapFooterButtonProps> = ({
return (
<Button
className="snap-footer-button"
type={type}
form={form}
{...props}
size={ButtonSize.Lg}
block
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export const button: UIComponentFactory<ButtonElement> = ({
element: 'SnapUIButton',
props: {
type: element.props.type,
form: element.props.form,
variant: element.props.variant,
name: element.props.name,
disabled: element.props.disabled,
Expand Down

0 comments on commit 1796697

Please sign in to comment.