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

Commit bd2daa8

Browse files
Prevent form submission for WidgetTooltip
1 parent 6643a24 commit bd2daa8

File tree

3 files changed

+34
-1
lines changed

3 files changed

+34
-1
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres
66
to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
77

8+
## [5.3.1] 2023-05-03
9+
10+
## Fixed
11+
12+
- prevent form submission when `WidgetTooltip` is used inside a form
13+
814
## [5.3.0] 2023-04-26
915

1016
## Added
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import React from 'react'
2+
import { TooltipProvider } from '@radix-ui/react-tooltip'
3+
4+
import { WidgetTooltip } from '../../src'
5+
6+
describe('<WidgetTooltip/>', () => {
7+
it('should not submit the parent form', () => {
8+
const stubbedHandleSubmit = cy.stub().as('stubbedHandleSubmit')
9+
10+
cy.mount(
11+
<form
12+
onSubmit={ev => {
13+
ev.preventDefault()
14+
stubbedHandleSubmit()
15+
}}
16+
>
17+
<TooltipProvider>
18+
<WidgetTooltip helpText='the help text' triggerAriaLabel='get help' />
19+
</TooltipProvider>
20+
</form>
21+
)
22+
23+
cy.findByLabelText('get help').click()
24+
25+
cy.get('@stubbedHandleSubmit').should('not.have.been.called')
26+
})
27+
})

src/common/WidgetTooltip.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ const WidgetTooltip = ({ helpText, triggerAriaLabel }: Props) => {
1717
triggerProps={{
1818
asChild: true,
1919
child: () => (
20-
<Trigger aria-label={triggerAriaLabel}>
20+
<Trigger aria-label={triggerAriaLabel} type='button'>
2121
<StyledQuestionMarkCircledIcon
2222
focusable={false}
2323
aria-hidden={true}

0 commit comments

Comments
 (0)