Skip to content
This repository has been archived by the owner on Mar 4, 2024. It is now read-only.

Commit

Permalink
Prevent form submission for WidgetTooltip
Browse files Browse the repository at this point in the history
  • Loading branch information
valentinogagliardi committed May 3, 2023
1 parent 6643a24 commit bd2daa8
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 1 deletion.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres
to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [5.3.1] 2023-05-03

## Fixed

- prevent form submission when `WidgetTooltip` is used inside a form

## [5.3.0] 2023-04-26

## Added
Expand Down
27 changes: 27 additions & 0 deletions cypress/component/WidgetTooltip.cy.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import React from 'react'
import { TooltipProvider } from '@radix-ui/react-tooltip'

import { WidgetTooltip } from '../../src'

describe('<WidgetTooltip/>', () => {
it('should not submit the parent form', () => {
const stubbedHandleSubmit = cy.stub().as('stubbedHandleSubmit')

cy.mount(
<form
onSubmit={ev => {
ev.preventDefault()
stubbedHandleSubmit()
}}
>
<TooltipProvider>
<WidgetTooltip helpText='the help text' triggerAriaLabel='get help' />
</TooltipProvider>
</form>
)

cy.findByLabelText('get help').click()

cy.get('@stubbedHandleSubmit').should('not.have.been.called')
})
})
2 changes: 1 addition & 1 deletion src/common/WidgetTooltip.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const WidgetTooltip = ({ helpText, triggerAriaLabel }: Props) => {
triggerProps={{
asChild: true,
child: () => (
<Trigger aria-label={triggerAriaLabel}>
<Trigger aria-label={triggerAriaLabel} type='button'>
<StyledQuestionMarkCircledIcon
focusable={false}
aria-hidden={true}
Expand Down

0 comments on commit bd2daa8

Please sign in to comment.