Skip to content

Commit

Permalink
feat(react-tags): make non-dismissible tag not focusable (#28350)
Browse files Browse the repository at this point in the history
* make default tag not focusable

* UT

* simplify test
  • Loading branch information
YuanboXue-Amber committed Jun 29, 2023
1 parent 53e6485 commit 104c81e
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { Tag } from './Tag';
import { isConformant } from '../../testing/isConformant';
import { TagProps } from './Tag.types';
import { render } from '@testing-library/react';
import { tagClassNames } from './useTagStyles.styles';

const requiredProps: TagProps = {
dismissible: true,
Expand All @@ -20,8 +19,13 @@ describe('Tag', () => {
requiredProps,
});

it('should render root as a button', () => {
const { getByRole } = render(<Tag>Tag</Tag>);
expect(getByRole('button').className.includes(tagClassNames.root)).toBe(true);
it('should render root as a span', () => {
const { getByTestId } = render(<Tag data-testid="testid">Tag</Tag>);
expect(getByTestId('testid').tagName).toBe('SPAN');
});

it('should render root as a button for dismissible tag', () => {
const { queryByRole } = render(<Tag dismissible>Tag</Tag>);
expect(queryByRole('button')).not.toBe(null);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ export const useTag_unstable = (props: TagProps, ref: React.Ref<HTMLElement>): T
size,

components: {
root: 'button',
root: dismissible ? 'button' : 'span',
media: 'span',
icon: 'span',
primaryText: 'span',
Expand Down

0 comments on commit 104c81e

Please sign in to comment.