Skip to content

Commit 5e097cd

Browse files
authored
fix(18204): remove redundant aria-label in inline mode for AILabel component (#18407)
* fix(18204): remove redundant aria-label in inline mode * test: adds tests
1 parent eee39f8 commit 5e097cd

File tree

3 files changed

+30
-21
lines changed

3 files changed

+30
-21
lines changed

packages/react/src/components/AILabel/__tests__/AILabel-test.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,4 +157,25 @@ describe('AILabelActions', () => {
157157

158158
expect(screen.getByText('View details')).toBeInTheDocument();
159159
});
160+
describe('Labels and kind prop', () => {
161+
it('should use empty label for inline kind', () => {
162+
render(<AILabel kind="inline" aiText="AI" textLabel="Text goes here" />);
163+
expect(screen.getByRole('button')).toHaveAttribute('aria-label', '');
164+
});
165+
166+
it('should set aria-label when kind is default', () => {
167+
render(<AILabel aiText="AI" />);
168+
expect(screen.getByRole('button')).toHaveAttribute(
169+
'aria-label',
170+
'AI Show information'
171+
);
172+
});
173+
174+
it('should let visible text serve as accessible name in inline mode', () => {
175+
render(<AILabel kind="inline" aiText="AI" textLabel="Text goes here" />);
176+
expect(
177+
screen.getByRole('button', { name: 'AI Text goes here' })
178+
).toBeInTheDocument();
179+
});
180+
});
160181
});

packages/react/src/components/AILabel/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ export const AILabel = React.forwardRef<HTMLDivElement, AILabelProps>(
214214
{...rest}>
215215
<ToggletipButton
216216
className={aiLabelButtonClasses}
217-
label={ariaLabelText}>
217+
label={kind === 'inline' ? '' : ariaLabelText}>
218218
<span className={`${prefix}--ai-label__text`}>{aiText}</span>
219219
{kind === 'inline' && (aiTextLabel || textLabel) && (
220220
<span className={`${prefix}--ai-label__additional-text`}>

packages/react/src/components/Tag/Tag-test.js

Lines changed: 8 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -80,13 +80,10 @@ describe('Tag', () => {
8080
type="red"
8181
title="Close tag"
8282
text="Tag content"
83-
decorator={<AILabel />}
83+
decorator={<AILabel aiText="AI" />}
8484
/>
8585
);
86-
87-
expect(
88-
screen.getByRole('button', { name: 'AI Show information' })
89-
).toBeInTheDocument();
86+
expect(screen.getByText('AI')).toBeInTheDocument();
9087
});
9188

9289
it('should respect deprecated slug prop', () => {
@@ -96,13 +93,10 @@ describe('Tag', () => {
9693
type="red"
9794
title="Close tag"
9895
text="Tag content"
99-
slug={<AILabel />}
96+
slug={<AILabel aiText="AI" />}
10097
/>
10198
);
102-
103-
expect(
104-
screen.getByRole('button', { name: 'AI Show information' })
105-
).toBeInTheDocument();
99+
expect(screen.getByText('AI')).toBeInTheDocument();
106100
spy.mockRestore();
107101
});
108102
});
@@ -123,20 +117,14 @@ describe('Tag', () => {
123117
});
124118

125119
it('should respect decorator prop', () => {
126-
render(<Tag type="red" decorator={<AILabel />} />);
127-
128-
expect(
129-
screen.getByRole('button', { name: 'AI Show information' })
130-
).toBeInTheDocument();
120+
render(<Tag type="red" decorator={<AILabel aiText="AI" />} />);
121+
expect(screen.getByText('AI')).toBeInTheDocument();
131122
});
132123

133124
it('should respect deprecated slug prop', () => {
134125
const spy = jest.spyOn(console, 'warn').mockImplementation(() => {});
135-
render(<Tag type="red" slug={<AILabel />} />);
136-
137-
expect(
138-
screen.getByRole('button', { name: 'AI Show information' })
139-
).toBeInTheDocument();
126+
render(<Tag type="red" slug={<AILabel aiText="AI" />} />);
127+
expect(screen.getByText('AI')).toBeInTheDocument();
140128
spy.mockRestore();
141129
});
142130

0 commit comments

Comments
 (0)