Skip to content

Commit 45c1708

Browse files
[CMSDS-3582] Deprecate ariaClearLabel prop for Autocomplete (#3812)
* Add deprecation warning for Type docs and console in dev mode * Add unit tests to verify deprecation warning * Updates the web component docs as well * Updates storybook docs snapshots
1 parent d83f14b commit 45c1708

File tree

5 files changed

+54
-5
lines changed

5 files changed

+54
-5
lines changed

packages/design-system/src/components/Autocomplete/Autocomplete.test.tsx

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -347,6 +347,36 @@ describe('Autocomplete', () => {
347347
});
348348

349349
describe('default props', () => {
350+
describe('ariaClearLabel deprecation', () => {
351+
const originalEnv = process.env.NODE_ENV;
352+
let consoleWarnSpy: jest.SpyInstance;
353+
354+
beforeEach(() => {
355+
process.env.NODE_ENV = 'development';
356+
consoleWarnSpy = jest.spyOn(console, 'warn').mockImplementation(() => {});
357+
});
358+
359+
afterEach(() => {
360+
process.env.NODE_ENV = originalEnv;
361+
consoleWarnSpy.mockRestore();
362+
});
363+
364+
it('logs a deprecation warning when ariaClearLabel is used in dev mode', () => {
365+
renderAutocomplete({ ariaClearLabel: 'Old label' });
366+
367+
expect(consoleWarnSpy).toHaveBeenCalledWith(
368+
expect.stringContaining("[Deprecated]: The 'ariaClearLabel' prop is deprecated")
369+
);
370+
});
371+
372+
it('does not log a warning in production mode', () => {
373+
process.env.NODE_ENV = 'production';
374+
renderAutocomplete({ ariaClearLabel: 'Old label' });
375+
376+
expect(consoleWarnSpy).not.toHaveBeenCalled();
377+
});
378+
});
379+
350380
it('defaults ariaClearLabel', () => {
351381
renderAutocomplete();
352382
const button = screen.getByRole('button');

packages/design-system/src/components/Autocomplete/Autocomplete.tsx

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,12 @@ export type AutocompleteItems = Array<AutocompleteItem | AutocompleteItemGroup>;
6060

6161
export interface AutocompleteProps {
6262
/**
63-
* Screen reader-specific label for the Clear search `<button>`. Intended to provide a longer, more descriptive explanation of the button's behavior.
63+
* @deprecated Use the `clearInputText` prop (which sets the visible Clear search button text) instead.
64+
*
65+
* Providing an `aria-label` on the Clear Search `<button>` can override its visible text label,
66+
* which may confuse users who rely on both visual and screen reader feedback when the two differ.
67+
* This prop was originally intended to provide a more descriptive label for screen reader users
68+
* but is no longer recommended.
6469
*/
6570
ariaClearLabel?: string;
6671
/**
@@ -199,6 +204,13 @@ export const Autocomplete = (props: AutocompleteProps) => {
199204
...autocompleteProps
200205
} = props;
201206

207+
if (process.env.NODE_ENV !== 'production' && ariaClearLabel) {
208+
console.warn(
209+
"[Deprecated]: The 'ariaClearLabel' prop is deprecated and will be removed in a future release. " +
210+
"Use the 'clearInputText' prop instead to set the visible Clear search button text."
211+
);
212+
}
213+
202214
const hasValidStandaloneItems = items?.some((item) => !('items' in item));
203215
const hasValidGroupedItems = items?.some((item) => 'items' in item && item.items?.length > 0);
204216

packages/design-system/src/components/web-components/ds-autocomplete/ds-autocomplete.stories.tsx

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,12 @@ const meta: Meta = {
3939
},
4040
argTypes: {
4141
'aria-clear-label': {
42-
description:
43-
"Screen reader-specific label for the Clear search `<button>`. Intended to provide a longer, more descriptive explanation of the button's behavior.",
42+
description: `
43+
**Deprecated:** Use the \`clearInputText\` prop instead to set the visible Clear search button text.
44+
45+
Providing an \`aria-label\` on the Clear Search button can override its visible text label,
46+
which may confuse users who rely on both visual and screen reader feedback when the two differ.
47+
`,
4448
control: 'text',
4549
},
4650
'aria-complete-label': {

tests/browser/snapshots/storybook-docs/Docs-Components-Autocomplete-Docs-prop-table-matches-snapshot-1.txt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,12 @@
88
[
99
"Deprecated: This is no longer used"
1010
],
11+
[
12+
"Deprecated: Use the `clearInputText` prop (which sets the visible Clear search button text) instead. Providing an `aria-label` on the Clear Search `<button>` can override its visible text label, which may confuse users who rely on both visual and screen reader feedback when the two differ. This prop was originally intended to provide a more descriptive label for screen reader users but is no longer recommended."
13+
],
1114
[
1215
"ariaClearLabel",
13-
"Screen reader-specific label for the Clear search <button>. Intended to provide a longer, more descriptive explanation of the button's behavior.\nstring",
16+
"string\nDeprecated: Use the `clearInputText` prop (which sets the visible Clear search button text) instead. Providing an `aria-label` on the Clear Search `<button>` can override its visible text label, which may confuse users who rely on both visual and screen reader feedback when the two differ. This prop was originally intended to provide a more descriptive label for screen reader users but is no longer recommended.",
1417
"Clear search to try again"
1518
],
1619
[

tests/browser/snapshots/storybook-docs/Docs-Web-Components-ds-autocomplete-Docs-prop-table-matches-snapshot-1.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[
22
[
33
"aria-clear-label",
4-
"Screen reader-specific label for the Clear search <button>. Intended to provide a longer, more descriptive explanation of the button's behavior.",
4+
"Deprecated: Use the clearInputText prop instead to set the visible Clear search button text.\n\nProviding an aria-label on the Clear Search button can override its visible text label, which may confuse users who rely on both visual and screen reader feedback when the two differ.",
55
"string"
66
],
77
[

0 commit comments

Comments
 (0)