From 2c847371a0e03d87ffc2ade8a4fafdd8b61d5b4e Mon Sep 17 00:00:00 2001 From: Titani Date: Thu, 25 Jul 2024 10:44:07 -0400 Subject: [PATCH 1/2] fix(Label):Added button type --- packages/react-core/src/components/Label/Label.tsx | 1 + .../src/components/Label/__tests__/Label.test.tsx | 7 +++++++ .../Label/__tests__/__snapshots__/LabelGroup.test.tsx.snap | 1 + 3 files changed, 9 insertions(+) diff --git a/packages/react-core/src/components/Label/Label.tsx b/packages/react-core/src/components/Label/Label.tsx index e56e85b2458..6558f9d494b 100644 --- a/packages/react-core/src/components/Label/Label.tsx +++ b/packages/react-core/src/components/Label/Label.tsx @@ -357,6 +357,7 @@ export const Label: React.FunctionComponent = ({ className )} onClick={isOverflowLabel || isAddLabel ? onLabelClick : undefined} + {...(LabelComponent === 'button' && { type: 'button' })} > {!isEditableActive && labelComponentChild} {!isEditableActive && onClose && closeButton} diff --git a/packages/react-core/src/components/Label/__tests__/Label.test.tsx b/packages/react-core/src/components/Label/__tests__/Label.test.tsx index cbff1fef898..6d9b78ac844 100644 --- a/packages/react-core/src/components/Label/__tests__/Label.test.tsx +++ b/packages/react-core/src/components/Label/__tests__/Label.test.tsx @@ -2,6 +2,7 @@ import React from 'react'; import { render, screen } from '@testing-library/react'; import userEvent from '@testing-library/user-event'; +import '@testing-library/jest-dom'; import { Label } from '../Label'; @@ -110,6 +111,12 @@ describe('Label', () => { expect(asFragment()).toMatchSnapshot(); }); + test('renders with isOverflow and type is set to button ', () => { + const { asFragment } = render(); + expect(screen.getByRole('button')).toHaveAttribute('type', 'button'); + expect(asFragment()).toMatchSnapshot(); + }); + test('a button is not rendered when onClick is not passed', () => { render(); diff --git a/packages/react-core/src/components/Label/__tests__/__snapshots__/LabelGroup.test.tsx.snap b/packages/react-core/src/components/Label/__tests__/__snapshots__/LabelGroup.test.tsx.snap index c072e723a4a..2dd15e93af6 100644 --- a/packages/react-core/src/components/Label/__tests__/__snapshots__/LabelGroup.test.tsx.snap +++ b/packages/react-core/src/components/Label/__tests__/__snapshots__/LabelGroup.test.tsx.snap @@ -69,6 +69,7 @@ exports[`LabelGroup label group compact 1`] = ` > + +`;