Skip to content
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
8 changes: 4 additions & 4 deletions src/lab/search-input/__tests__/search-input.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ test('renders default SearchInput with placeholder', () => {
expect(screen.getByPlaceholderText('Search')).toBeVisible()
})

test('calls onSearch when typing in the input', () => {
test('calls unstable_onSearch when typing in the input', () => {
const handleSearch = vi.fn()
render(<SearchInputStories.Default onSearch={handleSearch} />)
render(<SearchInputStories.Default unstable_onSearch={handleSearch} />)

const input = screen.getByPlaceholderText('Search')
fireEvent.change(input, { target: { value: 'hello' } })
Expand All @@ -31,7 +31,7 @@ test('shows clear button when text is entered', () => {

test('clicking clear button resets input value', () => {
const handleSearch = vi.fn()
render(<SearchInputStories.Default onSearch={handleSearch} />)
render(<SearchInputStories.Default unstable_onSearch={handleSearch} />)

const input = screen.getByPlaceholderText('Search')
fireEvent.change(input, { target: { value: 'test' } })
Expand All @@ -45,7 +45,7 @@ test('clicking clear button resets input value', () => {

test('does not allow typing when disabled', () => {
const handleSearch = vi.fn()
render(<SearchInputStories.IsDisabled onSearch={handleSearch} />)
render(<SearchInputStories.IsDisabled unstable_onSearch={handleSearch} />)

const input = screen.getByPlaceholderText('Search')
expect(input).toBeDisabled()
Expand Down
18 changes: 12 additions & 6 deletions src/lab/search-input/search-input.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,17 @@ export interface SearchInputProps extends InputHTMLAttributes<HTMLInputElement>
* @default "medium"
*/
inputSize?: 'small' | 'medium' | 'large'
/**
* Callback fired whenever the input value changes
* or when the clear button is pressed.
*/
onSearch?: (value: string) => void
/**
* If `true`, the input will be disabled and changes will be ignored.
* @default false
*/
isDisabled?: boolean
/**
* Callback fired whenever the input value changes or when the clear button is pressed.
* Considered unstable because it may be removed in future when the component is standardised
* in `@reapit/elements/core`.
*/
unstable_onSearch?: (value: string) => void
}

/**
Expand All @@ -31,7 +32,12 @@ export interface SearchInputProps extends InputHTMLAttributes<HTMLInputElement>
* - A clear button (visible when the field has a value).
* - Support for custom sizes and disabled state.
*/
export const SearchInput: FC<SearchInputProps> = ({ inputSize = 'medium', onSearch, isDisabled = false, ...rest }) => {
export const SearchInput: FC<SearchInputProps> = ({
inputSize = 'medium',
isDisabled = false,
unstable_onSearch: onSearch,
...rest
}) => {
const [value, setValue] = useState('')

const handleChange = (event: ChangeEvent<HTMLInputElement>) => {
Expand Down