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
28 changes: 28 additions & 0 deletions spec/Components/CioAutocomplete/CioAutocomplete.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -225,4 +225,32 @@ describe('CioAutocomplete Client-Side Rendering', () => {
});
});
});

describe('Search button behavior', () => {
it('Focuses the input when search button is clicked with empty input', () => {
render(<CioAutocomplete apiKey={DEMO_API_KEY} onSubmit={() => {}} />);

const searchInput = screen.getByRole('combobox') as HTMLInputElement;
const searchButton = screen.getByTestId('cio-submit-btn');

expect(searchInput).not.toHaveFocus();

fireEvent.click(searchButton);

expect(searchInput).toHaveFocus();
});

it('Submits the form when search button is clicked with non-empty input', () => {
const mockOnSubmit = jest.fn();
render(<CioAutocomplete apiKey={DEMO_API_KEY} onSubmit={mockOnSubmit} />);

const searchInput = screen.getByRole('combobox');
const searchButton = screen.getByTestId('cio-submit-btn');

fireEvent.change(searchInput, { target: { value: 'test query' } });
fireEvent.click(searchButton);

expect(mockOnSubmit).toHaveBeenCalled();
});
});
});
9 changes: 8 additions & 1 deletion src/components/Autocomplete/SearchInput/SearchInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,15 @@ function DefaultRenderInput({ getFormProps, getInputProps, getLabelProps, setQue
<button
className='cio-submit-btn'
data-testid='cio-submit-btn'
disabled={!inputProps.value}
data-cnstrc-search-submit-btn
onClick={(e) => {
if (!inputProps.value) {
e.preventDefault();
if (inputProps.id) {
document.getElementById(inputProps.id)?.focus();
}
Comment on lines +49 to +51
Copy link

Copilot AI Oct 17, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using document.getElementById is unnecessary here since you already have access to the input element through React. Consider using a ref to access the input element directly, which is more idiomatic in React and avoids direct DOM manipulation.

Copilot uses AI. Check for mistakes.
}
}}
type='submit'
aria-label='Submit Search'>
<div className='cio-icon'>
Expand Down
3 changes: 0 additions & 3 deletions src/styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,6 @@
cursor: pointer;
}

.cio-autocomplete button:disabled {
cursor: not-allowed;
}

.cio-autocomplete .cio-submit-btn {
right: -21px;
Expand Down
Loading