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): remove button as default role #2876

Merged
merged 4 commits into from
May 13, 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
2 changes: 1 addition & 1 deletion packages/gamut/src/ButtonBase/ButtonBase.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ export const ButtonBase = forwardRef<
ref={ref as MutableRefObject<HTMLButtonElement>}
as="button"
type={type}
role={role ?? 'button'}
role={role}
disabled={!!disabled}
>
{children}
Expand Down
56 changes: 56 additions & 0 deletions packages/gamut/src/ButtonBase/__tests__/ButtonBase.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import { setupRtl } from '@codecademy/gamut-tests';

import { ButtonBase } from '../ButtonBase';

const buttonText = 'Submit';

const renderView = setupRtl(ButtonBase, {
children: buttonText,
});

describe('ButtonBase', () => {
it('renders itself and children', () => {
const { view } = renderView();

view.getByText(buttonText);
view.getByRole('button');
});

it('renders an anchor tag if the href prop is used', () => {
const { view } = renderView({ href: 'https://www.codecademy.com' });

view.getByText(buttonText);
view.getByRole('link');
});

it('renders an anchor tag if a blank href prop is used', () => {
const { view } = renderView({ href: '' });

view.getByText(buttonText);
view.getByRole('link');
});

it('renders a button with the correct role', () => {
const { view } = renderView({ role: 'menuitem' });

view.getByText(buttonText);
view.getByRole('menuitem');
});

describe('when the button is disabled', () => {
it('does not render the href attribute and renders a button', () => {
const { view } = renderView({ disabled: true });

const el = view.getByText(buttonText);
view.getByRole('button');
expect(el.getAttribute('href')).toBeNull();
});

it('renders the disabled attribute on button tags', () => {
const { view } = renderView({ disabled: true });

const el = view.getByText(buttonText);
expect(el.getAttribute('disabled')).toBe('');
});
});
});
54 changes: 0 additions & 54 deletions packages/gamut/src/ButtonBase/__tests__/ButtonOutline.test.tsx

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ import { ButtonScale } from './examples';
args={{
children: 'Click Me',
disabled: false,
href: '',
size: 'normal',
}}
parameters={{
Expand Down
Loading