Skip to content

Commit e55501b

Browse files
authored
Merge pull request #92 from rcpch/mbarton/form-submit-gradient-labels-button
Make sure the gradient labels button doesn't auto-submit a parent form
2 parents 632e32b + 07a9f5f commit e55501b

File tree

2 files changed

+34
-1
lines changed

2 files changed

+34
-1
lines changed

src/CentileChart/CentileChart.test.tsx

+32
Original file line numberDiff line numberDiff line change
@@ -1175,4 +1175,36 @@ describe("Tests relating to negative settings on the zoom button", () => {
11751175
render(<CentileChart {...props} />);
11761176
expect(screen.queryByTestId('resetzoom-button')).not.toBeInTheDocument();
11771177
})
1178+
})
1179+
1180+
describe("Tests relating to the gradient labels button", () => {
1181+
let props: CentileChartProps;
1182+
const midparentalHeight: MidParentalHeightObject = {}
1183+
1184+
beforeEach(() => {
1185+
props = {
1186+
chartsVersion: "7.0.0",
1187+
reference: "uk-who",
1188+
title: "Term Girl",
1189+
subtitle: "Now over 4 years with advanced bone age",
1190+
measurementMethod: "height",
1191+
sex: 'female',
1192+
childMeasurements: termGirlWithSingleHeightMeasurementAndBoneAgeAndEvent,
1193+
midParentalHeightData: midparentalHeight,
1194+
enableZoom: true,
1195+
styles: monochromeStyles,
1196+
enableExport: false,
1197+
exportChartCallback: ()=>null,
1198+
clinicianFocus: false
1199+
};
1200+
});
1201+
1202+
it("should not trigger form submission when gradient labels clicked", () => {
1203+
const onSubmit = jest.fn();
1204+
render(<form onSubmit={onSubmit}>
1205+
<CentileChart {...props} />
1206+
</form>);
1207+
fireEvent.click(screen.getByTestId('gradient-labels-button'));
1208+
expect(onSubmit).not.toHaveBeenCalled();
1209+
});
11781210
})

src/SubComponents/StyledGradientLabelsButton.tsx

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import styled from 'styled-components';
2+
import { CommonButton } from './CommonButton';
23

3-
export const StyledGradientLabelsButton = styled.button<{
4+
export const StyledGradientLabelsButton = styled(CommonButton)<{
45
$color?: string,
56
size?: number
67
}>`

0 commit comments

Comments
 (0)