Skip to content
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
14 changes: 14 additions & 0 deletions packages/ui/src/components/form/controls/Select/Select.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,18 @@ describe('Select', () => {

expect(onChange).toHaveBeenCalledWith('2')
})

it('calls onNativeChange with the select change event', async () => {
const user = userEvent.setup()
const onNativeChange = vi.fn()

const { getByRole } = render(
<Select options={options} onNativeChange={onNativeChange} aria-label="Native select" />,
)

await user.selectOptions(getByRole('combobox', { name: 'Native select' }), '2')

expect(onNativeChange).toHaveBeenCalledTimes(1)
expect(onNativeChange.mock.calls[0][0].target).toHaveValue('2')
})
})
3 changes: 3 additions & 0 deletions packages/ui/src/components/form/controls/Select/Select.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ export interface SelectProps
defaultValue?: string
size?: ComponentSize
onChange?: (value: string) => void
onNativeChange?: (event: ChangeEvent<HTMLSelectElement>) => void
slotClassNames?: SlotClassNames
}

Expand All @@ -39,6 +40,7 @@ export const Select = forwardRef<HTMLSelectElement, SelectProps>(function Select
size = 'md',
id,
onChange,
onNativeChange,
disabled,
slotClassNames,
...props
Expand All @@ -57,6 +59,7 @@ export const Select = forwardRef<HTMLSelectElement, SelectProps>(function Select

const handleChange = (event: ChangeEvent<HTMLSelectElement>) => {
setInnerValue(event.target.value)
onNativeChange?.(event)
}

return (
Expand Down
Loading