Skip to content

Commit

Permalink
chore(Autocomplete): enable dynamic aria-label value (#2962)
Browse files Browse the repository at this point in the history
* chore(Autocomplete): enable dynamic  value

* chore: add changelog
  • Loading branch information
cf-remylenoir authored Jan 9, 2025
1 parent f0b031c commit 3c9a565
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/lazy-bees-clap.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@contentful/f36-autocomplete": patch
---

Enable dynamic `aria-label` value
17 changes: 16 additions & 1 deletion packages/components/autocomplete/src/Autocomplete.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,13 @@ export interface AutocompleteProps<ItemType>
* Manually control when the button to clear the input value is shown
*/
showClearButton?: boolean;
/**
* Additional aria attributes
*/
aria?: {
showListIconLabel?: string;
clearSelectionIconLabel?: string;
};
}

function _Autocomplete<ItemType>(
Expand Down Expand Up @@ -227,6 +234,10 @@ function _Autocomplete<ItemType>(
testId = 'cf-autocomplete',
popoverTestId = 'cf-autocomplete-container',
showClearButton: showClearButtonProp,
aria = {
clearSelectionIconLabel: 'Clear',
showListIconLabel: 'Show list',
},
} = props;

type GroupType = GenericGroupType<ItemType>;
Expand Down Expand Up @@ -410,7 +421,11 @@ function _Autocomplete<ItemType>(
<IconButton
{...toggleProps}
ref={mergeRefs(toggleProps.ref, toggleRef)}
aria-label={showClearButton ? 'Clear' : 'Show list'}
aria-label={
showClearButton
? aria.clearSelectionIconLabel
: aria.showListIconLabel
}
className={styles.toggleButton}
variant="transparent"
icon={showClearButton ? <CloseIcon variant="muted" /> : icon}
Expand Down

0 comments on commit 3c9a565

Please sign in to comment.