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(18204): remove redundant aria-label in inline mode for AILabel component #18407

Merged
merged 2 commits into from
Jan 24, 2025
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
21 changes: 21 additions & 0 deletions packages/react/src/components/AILabel/__tests__/AILabel-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -157,4 +157,25 @@ describe('AILabelActions', () => {

expect(screen.getByText('View details')).toBeInTheDocument();
});
describe('Labels and kind prop', () => {
it('should use empty label for inline kind', () => {
render(<AILabel kind="inline" aiText="AI" textLabel="Text goes here" />);
expect(screen.getByRole('button')).toHaveAttribute('aria-label', '');
});

it('should set aria-label when kind is default', () => {
render(<AILabel aiText="AI" />);
expect(screen.getByRole('button')).toHaveAttribute(
'aria-label',
'AI Show information'
);
});

it('should let visible text serve as accessible name in inline mode', () => {
render(<AILabel kind="inline" aiText="AI" textLabel="Text goes here" />);
expect(
screen.getByRole('button', { name: 'AI Text goes here' })
).toBeInTheDocument();
});
});
});
2 changes: 1 addition & 1 deletion packages/react/src/components/AILabel/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ export const AILabel = React.forwardRef<HTMLDivElement, AILabelProps>(
{...rest}>
<ToggletipButton
className={aiLabelButtonClasses}
label={ariaLabelText}>
label={kind === 'inline' ? '' : ariaLabelText}>
<span className={`${prefix}--ai-label__text`}>{aiText}</span>
{kind === 'inline' && (aiTextLabel || textLabel) && (
<span className={`${prefix}--ai-label__additional-text`}>
Expand Down
28 changes: 8 additions & 20 deletions packages/react/src/components/Tag/Tag-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,13 +80,10 @@ describe('Tag', () => {
type="red"
title="Close tag"
text="Tag content"
decorator={<AILabel />}
decorator={<AILabel aiText="AI" />}
/>
);

expect(
screen.getByRole('button', { name: 'AI Show information' })
).toBeInTheDocument();
expect(screen.getByText('AI')).toBeInTheDocument();
});

it('should respect deprecated slug prop', () => {
Expand All @@ -96,13 +93,10 @@ describe('Tag', () => {
type="red"
title="Close tag"
text="Tag content"
slug={<AILabel />}
slug={<AILabel aiText="AI" />}
/>
);

expect(
screen.getByRole('button', { name: 'AI Show information' })
).toBeInTheDocument();
expect(screen.getByText('AI')).toBeInTheDocument();
spy.mockRestore();
});
});
Expand All @@ -123,20 +117,14 @@ describe('Tag', () => {
});

it('should respect decorator prop', () => {
render(<Tag type="red" decorator={<AILabel />} />);

expect(
screen.getByRole('button', { name: 'AI Show information' })
).toBeInTheDocument();
render(<Tag type="red" decorator={<AILabel aiText="AI" />} />);
expect(screen.getByText('AI')).toBeInTheDocument();
});

it('should respect deprecated slug prop', () => {
const spy = jest.spyOn(console, 'warn').mockImplementation(() => {});
render(<Tag type="red" slug={<AILabel />} />);

expect(
screen.getByRole('button', { name: 'AI Show information' })
).toBeInTheDocument();
render(<Tag type="red" slug={<AILabel aiText="AI" />} />);
expect(screen.getByText('AI')).toBeInTheDocument();
spy.mockRestore();
});

Expand Down
Loading