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

fix: Combobox adds aria-invalid when in an error state #27651

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
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
@@ -0,0 +1,7 @@
{
"type": "patch",
"comment": "fix: Combobox adds aria-invalid when in an error state",
"packageName": "@fluentui/react",
"email": "[email protected]",
"dependentChangeType": "patch"
}
9 changes: 9 additions & 0 deletions packages/react/src/components/ComboBox/ComboBox.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,15 @@ describe('ComboBox', () => {
expect(combobox.getAttribute('aria-disabled')).toEqual('true');
});

it('Sets aria-invalid when an error message is passed in.', () => {
const { getByRole, rerender } = render(<ComboBox errorMessage="error" options={DEFAULT_OPTIONS} />);
const combobox = getByRole('combobox');
expect(combobox.getAttribute('aria-invalid')).toEqual('true');

rerender(<ComboBox errorMessage={undefined} options={DEFAULT_OPTIONS} />);
expect(combobox.getAttribute('aria-invalid')).toBeNull();
});

it('Renders no selected item in default case', () => {
const { getByRole } = render(<ComboBox options={DEFAULT_OPTIONS} />);
expect(getByRole('combobox').getAttribute('value')).toEqual('');
Expand Down
1 change: 1 addition & 0 deletions packages/react/src/components/ComboBox/ComboBox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -659,6 +659,7 @@ class ComboBoxInternal extends React.Component<IComboBoxInternalProps, IComboBox
aria-describedby={
errorMessage !== undefined ? mergeAriaAttributeValues(ariaDescribedBy, errorMessageId) : ariaDescribedBy
}
aria-invalid={errorMessage !== undefined ? 'true' : undefined}
aria-activedescendant={ariaActiveDescendantValue}
aria-required={required}
aria-disabled={disabled}
Expand Down