Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
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
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Weird that these screenshot file names end with a hyphen, but I don't think it's related to anything in this PR.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed. Maybe we open new issue?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#2329 done!

Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
11 changes: 11 additions & 0 deletions packages/react/src/components/Button/index.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,17 @@ test('should render button as tag', () => {
expect(TagButton).toHaveClass('Tag');
});

test('should render button as small tag', () => {
render(
<Button variant="tag" size="small">
small tag
</Button>
);
const TagButton = screen.getByRole('button', { name: 'small tag' });
expect(TagButton).toHaveClass('Tag');
expect(TagButton).toHaveClass('Tag--small');
});

test('should render button as badge', () => {
render(<Button variant="badge">badge</Button>);
const BadgeButton = screen.getByRole('button', { name: 'badge' });
Expand Down
3 changes: 3 additions & 0 deletions packages/react/src/components/Button/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,15 @@ export interface ButtonProps extends ButtonHTMLAttributes<HTMLButtonElement> {
| 'tag'
| 'badge';
thin?: boolean;
size?: 'default' | 'small';
}
Comment thread
Bracciata marked this conversation as resolved.
Outdated

const Button = forwardRef<HTMLButtonElement, ButtonProps>(
(
{
variant = 'primary',
thin,
size = 'default',
Comment thread
Bracciata marked this conversation as resolved.
Outdated
children,
className,
buttonRef,
Expand All @@ -40,6 +42,7 @@ const Button = forwardRef<HTMLButtonElement, ButtonProps>(
Link: variant === 'link',
Tag: variant === 'tag',
'Button--tag': variant === 'tag',
'Tag--small': variant === 'tag' && size === 'small',
'Button--thin': thin,
'Button--badge': variant === 'badge'
})}
Expand Down
36 changes: 36 additions & 0 deletions packages/react/src/components/Button/screenshots.e2e.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -566,6 +566,42 @@ test('should have screenshot for Button[variant="tag"]', async ({
await expect(component).toHaveScreenshot('dark--button[variant=tag]');
});

test('should have screenshot for Button[variant="tag"][size="small"]', async ({
mount,
page
}) => {
const component = await mount(
<div>
<Button variant="tag" size="small">
Tag
</Button>
<Button variant="tag" size="small">
Hover
</Button>
<Button variant="tag" size="small">
Active
</Button>
<Button variant="tag" size="small">
Focus
</Button>
<Button variant="tag" size="small" disabled>
{' '}
Disabled
</Button>
</div>
);

await component.getByText('Hover').hover();
Comment thread
Bracciata marked this conversation as resolved.
Outdated
setActive(component.getByText('Active'));
await component.getByText('Focus').focus();
Comment on lines +595 to +596
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: there are some other .getByText calls that could be updated to .getByRole.


await expect(component).toHaveScreenshot('button[variant=tag][size=small]');
await setTheme(page, 'dark');
await expect(component).toHaveScreenshot(
'dark--button[variant=tag][size=small]'
);
});

test('should have screenshot for Button[variant="badge"]', async ({
mount,
page
Expand Down
6 changes: 6 additions & 0 deletions packages/react/src/components/TagButton/index.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,12 @@ test('should render an icon in the button', () => {
);
});

test('should support size prop', () => {
renderDefaultTagButton({ size: 'small' });

expect(screen.getByRole('button')).toHaveClass('Tag--small');
});

test('returns no axe violations', async () => {
const { container } = renderDefaultTagButton();

Expand Down
4 changes: 3 additions & 1 deletion packages/react/src/components/TagButton/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,19 @@ interface TagButtonProps extends React.HTMLAttributes<HTMLButtonElement> {
value: ContentNode;
icon: IconType;
onClick: (e: React.MouseEvent<HTMLButtonElement>) => void;
Comment thread
Bracciata marked this conversation as resolved.
size?: 'default' | 'small';
Comment thread
Bracciata marked this conversation as resolved.
Outdated
}

const TagButton = React.forwardRef(
(
{ label, value, icon, className, ...rest }: TagButtonProps,
{ label, value, icon, className, size, ...rest }: TagButtonProps,
ref: Ref<HTMLButtonElement>
) => {
return (
<Button
variant="tag"
className={classNames('TagButton', className)}
size={size}
ref={ref}
{...rest}
>
Expand Down
Loading