Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(Label):Added button type V6 #10807

Merged
merged 2 commits into from
Jul 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/react-core/src/components/Label/Label.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,7 @@ export const Label: React.FunctionComponent<LabelProps> = ({
className
)}
onClick={isOverflowLabel || isAddLabel ? onLabelClick : undefined}
{...(LabelComponent === 'button' && { type: 'button' })}
>
{!isEditableActive && labelComponentChild}
{!isEditableActive && onClose && closeButton}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down Expand Up @@ -110,6 +111,12 @@ describe('Label', () => {
expect(asFragment()).toMatchSnapshot();
});

test('renders with variant overflow and type is set to button ', () => {
const { asFragment } = render(<Label variant="overflow">Something</Label>);
expect(screen.getByRole('button')).toHaveAttribute('type', 'button');
expect(asFragment()).toMatchSnapshot();
});

test('a button is not rendered when onClick is not passed', () => {
render(<Label>Click me</Label>);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -599,3 +599,22 @@ exports[`Label renders with outline variant 1`] = `
</span>
</DocumentFragment>
`;

exports[`Label renders with variant overflow and type is set to button 1`] = `
<DocumentFragment>
<button
class="pf-v6-c-label pf-m-overflow"
type="button"
>
<span
class="pf-v6-c-label__content"
>
<span
class="pf-v6-c-label__text"
>
Something
</span>
</span>
</button>
</DocumentFragment>
`;
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ exports[`LabelGroup label group compact 1`] = `
>
<button
class="pf-v6-c-label pf-m-overflow pf-m-compact"
type="button"
>
<span
class="pf-v6-c-label__content"
Expand Down
Loading