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

refactor(ComboBox): ariaLabel to aria-label #13273

Merged
merged 4 commits into from
Mar 3, 2023
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
Original file line number Diff line number Diff line change
Expand Up @@ -970,7 +970,7 @@ Map {
"ComboBox" => Object {
"$$typeof": Symbol(react.forward_ref),
"defaultProps": Object {
"ariaLabel": "Choose an item",
"aria-label": "Choose an item",
"direction": "bottom",
"disabled": false,
"itemToElement": null,
Expand All @@ -979,9 +979,10 @@ Map {
"type": "default",
},
"propTypes": Object {
"ariaLabel": Object {
"aria-label": Object {
"type": "string",
},
"ariaLabel": [Function],
"className": Object {
"type": "string",
},
Expand Down
5 changes: 5 additions & 0 deletions packages/react/src/components/ComboBox/ComboBox.stories.js
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,11 @@ export const Playground = (args) => (
);

Playground.argTypes = {
['aria-label']: {
table: {
disable: true,
},
},
ariaLabel: {
table: {
disable: true,
Expand Down
30 changes: 26 additions & 4 deletions packages/react/src/components/ComboBox/ComboBox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,13 @@ export interface ComboBoxProps
ExcludedAttributes
> {
/**
* Specify a label to be read by screen readers on the container node
* 'aria-label' of the ListBox component.
*/
['aria-label']?: string;

/**
* @deprecated please use `aria-label` instead.
* 'aria-label' of the ListBox component.
*/
ariaLabel?: string;
Expand Down Expand Up @@ -250,7 +257,8 @@ export interface ComboBoxProps

const ComboBox = React.forwardRef((props: ComboBoxProps, ref) => {
const {
ariaLabel,
['aria-label']: ariaLabel,
ariaLabel: deprecatedAriaLabel,
className: containerClassName,
direction,
disabled,
Expand Down Expand Up @@ -568,7 +576,10 @@ const ComboBox = React.forwardRef((props: ComboBoxProps, ref) => {
translateWithId={translateWithId}
/>
</div>
<ListBox.Menu {...getMenuProps({ 'aria-label': ariaLabel })}>
<ListBox.Menu
{...getMenuProps({
'aria-label': deprecatedAriaLabel || ariaLabel,
})}>
{isOpen
? filterItems(items, itemToString, inputValue).map(
(item, index) => {
Expand Down Expand Up @@ -634,9 +645,20 @@ const ComboBox = React.forwardRef((props: ComboBoxProps, ref) => {
ComboBox.displayName = 'ComboBox';
ComboBox.propTypes = {
/**
* 'aria-label' of the ListBox component.
* Specify a label to be read by screen readers on the container node
*/
['aria-label']: PropTypes.string,

/**
* Deprecated, please use `aria-label` instead.
* Specify a label to be read by screen readers on the container note.
* 'aria-label' of the ListBox component.
*/
ariaLabel: PropTypes.string,
ariaLabel: deprecate(
PropTypes.string,
'This prop syntax has been deprecated. Please use the new `aria-label`.'
),

/**
* An optional className to add to the container node
Expand Down Expand Up @@ -813,7 +835,7 @@ ComboBox.defaultProps = {
itemToElement: null,
shouldFilterItem: defaultShouldFilterItem,
type: 'default',
ariaLabel: 'Choose an item',
['aria-label']: 'Choose an item',
direction: 'bottom',
};

Expand Down