Skip to content

Commit

Permalink
fix: button text alignment, excess button markup & space (#271)
Browse files Browse the repository at this point in the history
* fix(tup-cms): button text alignment (edge cases)

The `<span>` inside <Button> is unnecessary and causes alignment bugs.

This change removes some code meant to fix an alignment issue.*

* I could not see alignment issue. Regardless, the <span> is gone.

* test: button text match
  • Loading branch information
wesleyboar authored Jul 20, 2023
1 parent cdd8845 commit 1e19cc5
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 10 deletions.
7 changes: 3 additions & 4 deletions libs/core-components/src/lib/Button/Button.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,12 @@ const TEST_SIZE = 'medium';

function testClassnamesByType(type, size, getByRole, getByTestId) {
const root = getByRole('button');
const text = getByTestId('text');
const typeClassName = BTN.TYPE_MAP[type];
const sizeClassName = BTN.SIZE_MAP[size];
expect(root.className).toMatch('root');
expect(root.className).toMatch(new RegExp(typeClassName));
expect(root.className).toMatch(new RegExp(sizeClassName));
expect(text.className).toMatch('text');
expect(root.textContent).toMatch(TEST_TEXT);
}

function isPropertyLimitation(type, size) {
Expand All @@ -34,8 +33,8 @@ function isPropertyLimitation(type, size) {

describe('Button', () => {
it('uses given text', () => {
const { getByTestId } = render(<Button>{TEST_TEXT}</Button>);
expect(getByTestId('text').textContent).toEqual(TEST_TEXT);
const { getByRole } = render(<Button>{TEST_TEXT}</Button>);
expect(getByRole('button').textContent).toEqual(TEST_TEXT);
});

describe('icons exist as expected when', () => {
Expand Down
4 changes: 1 addition & 3 deletions libs/core-components/src/lib/Button/Button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -102,9 +102,7 @@ const Button: React.FC<ButtonProps> = ({
) : (
''
)}
<span className="c-button__text" data-testid="text">
{children}
</span>
{children}
{iconNameAfter && (
<Icon
name={iconNameAfter}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,6 @@
justify-content: space-between;
}

.link-button > span {
vertical-align: baseline;
}
.link-button-delete {
font-weight: bold;
}
Expand Down

0 comments on commit 1e19cc5

Please sign in to comment.