Skip to content

Commit

Permalink
fix(combobox): rendering aria-label (#17678)
Browse files Browse the repository at this point in the history
* fix(combobox): rendering aria-label

* test(combobox): update tests with aria-label and titleText
  • Loading branch information
ariellalgilmore authored Oct 10, 2024
1 parent eac683f commit 993fb9c
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
15 changes: 15 additions & 0 deletions packages/react/src/components/ComboBox/ComboBox-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,21 @@ describe('ComboBox', () => {
});
});

it('should display titleText', () => {
render(<ComboBox {...mockProps} titleText="Combobox title" />);

expect(screen.getByText('Combobox title')).toBeInTheDocument();
});

it('should confirm custom aria-label is on the input', () => {
render(<ComboBox {...mockProps} aria-label="custom aria-label" />);

expect(screen.getByRole('combobox')).toHaveAttribute(
'aria-label',
'custom aria-label'
);
});

it('should select the correct item from the filtered list after text input on click', async () => {
const user = userEvent.setup();

Expand Down
4 changes: 3 additions & 1 deletion packages/react/src/components/ComboBox/ComboBox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -851,7 +851,6 @@ const ComboBox = forwardRef(
const menuProps = useMemo(
() =>
getMenuProps({
'aria-label': deprecatedAriaLabel || ariaLabel,
ref: autoAlign ? refs.setFloating : null,
}),
[
Expand Down Expand Up @@ -905,6 +904,9 @@ const ComboBox = forwardRef(
aria-haspopup="listbox"
title={textInput?.current?.value}
{...getInputProps({
'aria-label': titleText
? undefined
: deprecatedAriaLabel || ariaLabel,
'aria-controls': isOpen ? undefined : menuProps.id,
placeholder,
value: inputValue,
Expand Down

0 comments on commit 993fb9c

Please sign in to comment.