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(Button): do not shrink button when there is only one icon #1580

Closed
Closed
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
4 changes: 4 additions & 0 deletions src/components/Button/Button.scss
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,10 @@ $block: '.#{variables.$ns}button';
&_side_end {
order: 1;
}

&:only-child {
margin: 0;
}
}

&:has(#{$block}__icon:only-child) {
Expand Down
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.
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.
12 changes: 11 additions & 1 deletion src/components/Button/__tests__/Button.visual.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@ import React from 'react';

import {test} from '~playwright/core';

import {ButtonStories, CustomIconSizeButton} from './helpersPlaywright';
import {
ButtonStories,
CustomIconSizeButton,
SingleIconButtonInShrinkedContainer,
} from './helpersPlaywright';

test.describe('Button', () => {
test('render story: <Default>', async ({mount, expectScreenshot}) => {
Expand Down Expand Up @@ -76,4 +80,10 @@ test.describe('Button', () => {

await expectScreenshot();
});

test('single Icon in shrinked container', async ({mount, expectScreenshot}) => {
await mount(<SingleIconButtonInShrinkedContainer />);

await expectScreenshot();
});
});
17 changes: 17 additions & 0 deletions src/components/Button/__tests__/helpersPlaywright.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
.button-view-showcase-container {
width: 200px;

.showcase__content {
flex-direction: column;
}

&__shrinked-container {
display: flex;
width: 20px;
border: 1px solid var(--g-color-line-generic);

&_max {
width: 100%;
}
}
}
22 changes: 21 additions & 1 deletion src/components/Button/__tests__/helpersPlaywright.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
import React from 'react';

import {ChevronDown, Globe} from '@gravity-ui/icons';
import {ChevronDown, Globe, Xmark} from '@gravity-ui/icons';
import {composeStories} from '@storybook/react';

import {Button} from '..';
import {Showcase} from '../../../demo/Showcase';
import {Icon} from '../../Icon';
import {cn} from '../../utils/cn';
import * as DefaultButtonStories from '../__stories__/Button.stories';

import './helpersPlaywright.scss';

const b = cn('button-view-showcase-container');

export const ButtonStories = composeStories(DefaultButtonStories);

export const CustomIconSizeButton = () => (
Expand Down Expand Up @@ -39,3 +44,18 @@ export const CustomIconSizeButton = () => (
</Button>
</Showcase>
);

export const SingleIconButtonInShrinkedContainer = () => (
<Showcase className={b()}>
<div className={b('shrinked-container')}>
<Button size="xl">
<Icon size={24} data={Xmark} />
</Button>
</div>
<div className={b('shrinked-container', {max: true})}>
<Button size="xl" width="max">
<Icon size={24} data={Xmark} />
</Button>
</div>
</Showcase>
);
Loading