Skip to content

Commit

Permalink
fix(Label):Added button type V6 (#10807)
Browse files Browse the repository at this point in the history
* fix(Label):Added button type

* revert changes
  • Loading branch information
tlabaj authored Jul 29, 2024
1 parent dc76e64 commit 3881b58
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 0 deletions.
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

0 comments on commit 3881b58

Please sign in to comment.