Commit 1dde9fa5 authored by Lyza Danger Gardner's avatar Lyza Danger Gardner Committed by Lyza Gardner

Do not set initial empty search query

The way that the search interface is currently implemented,
clicking on the "search" icon in the top bar actually
submits the search form (with an empty query).

Ignoring empty queries if a query has not yet been set
alleviates "searching" for nothing.

This also prevents expanded threads from being re-collapsed
when clicking on the search icon.
parent cdce4af9
......@@ -29,7 +29,11 @@ export default function SearchInput({ alwaysExpanded, query, onSearch }) {
const onSubmit = e => {
e.preventDefault();
if (input.current.value || prevQuery) {
// Don't set an initial empty query, but allow a later empty query to
// clear `prevQuery`
onSearch(input.current.value);
}
};
// When the active query changes outside of this component, update the input
......
......@@ -61,6 +61,25 @@ describe('SearchInput', () => {
assert.calledWith(onSearch, 'new-query');
});
it('does not set an initial empty query when form is submitted', () => {
// If the first query entered is empty, it will be ignored
const onSearch = sinon.stub();
const wrapper = createSearchInput({ onSearch });
typeQuery(wrapper, '');
wrapper.find('form').simulate('submit');
assert.notCalled(onSearch);
});
it('sets subsequent empty queries if entered', () => {
// If there has already been at least one query set, subsequent
// empty queries will be honored
const onSearch = sinon.stub();
const wrapper = createSearchInput({ query: 'foo', onSearch });
typeQuery(wrapper, '');
wrapper.find('form').simulate('submit');
assert.calledWith(onSearch, '');
});
it('renders loading indicator when app is in a "loading" state', () => {
fakeStore.isLoading.returns(true);
const wrapper = createSearchInput();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment