From caebaf32689016418248721fb48b1164b621489d Mon Sep 17 00:00:00 2001 From: Olaf Tomalka Date: Mon, 16 Sep 2024 14:32:53 +0200 Subject: [PATCH] feat(snaps): Added support for form property in Snap footer buttons (#27158) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## **Description** This PR adds changes required to enable Snaps' footer buttons to submit and reset forms. [![Open in GitHub Codespaces](https://github.com/codespaces/badge.svg)](https://codespaces.new/MetaMask/metamask-extension/pull/27158?quickstart=1) ## **Related issues** Fixes: https://github.com/MetaMask/snaps/issues/2691 ## **Manual testing steps** 1. Go to this page... 2. 3. ## **Screenshots/Recordings** ### **Before** ### **After** ## **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. --- .../snap-footer-button/snap-footer-button.tsx | 25 ++++++++++++++++--- .../snap-ui-renderer/components/button.ts | 1 + 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/ui/components/app/snaps/snap-footer-button/snap-footer-button.tsx b/ui/components/app/snaps/snap-footer-button/snap-footer-button.tsx index 04f84b64f23c..8d2a84b8ccff 100644 --- a/ui/components/app/snaps/snap-footer-button/snap-footer-button.tsx +++ b/ui/components/app/snaps/snap-footer-button/snap-footer-button.tsx @@ -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, @@ -15,17 +24,23 @@ type SnapFooterButtonProps = { onCancel?: () => void; }; -export const SnapFooterButton: FunctionComponent = ({ +export const SnapFooterButton: FunctionComponent< + SnapFooterButtonProps & ButtonLinkProps<'button'> +> = ({ onCancel, name, children, isSnapAction = false, + type, + form, ...props }) => { const { handleEvent, snapId } = useSnapInterfaceContext(); const handleSnapAction = (event: ReactMouseEvent) => { - event.preventDefault(); + if (type === ButtonType.Button) { + event.preventDefault(); + } handleEvent({ event: UserInputEventType.ButtonClickEvent, @@ -38,6 +53,8 @@ export const SnapFooterButton: FunctionComponent = ({ return (