diff --git a/api/hub/src/resolvers/query.ts b/api/hub/src/resolvers/query.ts index af9b2a65fd..360bbc9e3a 100644 --- a/api/hub/src/resolvers/query.ts +++ b/api/hub/src/resolvers/query.ts @@ -163,7 +163,7 @@ const query = { return Object.assign({}, returned, { results: posts }); }, globalSearch: async (_source, { keyword }, { dataSources }) => { - const results = await dataSources.postsAPI.globalSearch(keyword); + const results = await dataSources.postsAPI.globalSearch(keyword?.trim()); results.tags = await (async () => { const res = []; for (const rec of results.tags) { diff --git a/ui/design/src/components/TopBar/mobile-search-bar.tsx b/ui/design/src/components/TopBar/mobile-search-bar.tsx index c6275aaaef..919b5be8b9 100644 --- a/ui/design/src/components/TopBar/mobile-search-bar.tsx +++ b/ui/design/src/components/TopBar/mobile-search-bar.tsx @@ -16,8 +16,10 @@ const MobileSearchBar: React.FC = props => { const [showSearch, setShowSearch] = React.useState(true); const handleSearch = (ev: React.KeyboardEvent) => { + const trimmedValue = inputValue.trim(); + if (!trimmedValue) return; if (ev.key === 'Enter') { - onSearch(inputValue); + onSearch(trimmedValue); } }; diff --git a/ui/widgets/top-bar/src/components/topbar-component.tsx b/ui/widgets/top-bar/src/components/topbar-component.tsx index ad74299f65..4e7066e169 100644 --- a/ui/widgets/top-bar/src/components/topbar-component.tsx +++ b/ui/widgets/top-bar/src/components/topbar-component.tsx @@ -167,7 +167,9 @@ const TopbarComponent = (props: RootComponentProps) => { }; const handleSearch = (inputValue: string) => { - const encodedSearchKey = encodeURIComponent(inputValue); + const trimmedValue = inputValue.trim(); + if (!trimmedValue) return; + const encodedSearchKey = encodeURIComponent(trimmedValue); if (searchAreaItem) { handleNavigation(`${searchAreaItem.route}/${encodedSearchKey}`); }