{
expect(component).toBeDisabled()
})
- it('can be invalid', () => {
- render(
)
+ describe('Invalid state', () => {
+ it('is not invalid by default', () => {
+ render(
)
- const component = screen.getByRole('combobox')
+ const component = screen.getByRole('combobox')
+
+ expect(component).not.toBeInvalid()
+ })
+
+ it('can have an invalid state', () => {
+ render(
)
+
+ const component = screen.getByRole('combobox')
- expect(component).toHaveClass('ams-select--invalid')
+ expect(component).toHaveAttribute('aria-invalid')
+ expect(component).toBeInvalid()
+ })
+
+ it('omits non-essential invalid attributes when not invalid', () => {
+ render(
)
+
+ const component = screen.getByRole('combobox')
+
+ expect(component).not.toHaveAttribute('aria-invalid')
+ })
})
it('is not required by default', () => {
diff --git a/packages/react/src/Select/Select.tsx b/packages/react/src/Select/Select.tsx
index 22ee1a02d1..e5247666dd 100644
--- a/packages/react/src/Select/Select.tsx
+++ b/packages/react/src/Select/Select.tsx
@@ -12,16 +12,11 @@ import { SelectOptionGroup } from './SelectOptionGroup'
export type SelectProps = {
/** Whether the value fails a validation rule. */
invalid?: boolean
-} & PropsWithChildren
>
+} & PropsWithChildren, 'aria-invalid'>>
const SelectRoot = forwardRef(
({ children, className, invalid, ...restProps }: SelectProps, ref: ForwardedRef) => (
-