From 6b361356cfc9952501943c65282eca226a686545 Mon Sep 17 00:00:00 2001 From: Alison Joseph Date: Wed, 17 Apr 2024 12:22:50 -0500 Subject: [PATCH] feat: add max results to search (#1466) --- .../src/components/GlobalSearch/GlobalSearch.js | 11 ++++++----- yarn.lock | 4 ++-- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/packages/gatsby-theme-carbon/src/components/GlobalSearch/GlobalSearch.js b/packages/gatsby-theme-carbon/src/components/GlobalSearch/GlobalSearch.js index e49a4c5bb..db70361f2 100644 --- a/packages/gatsby-theme-carbon/src/components/GlobalSearch/GlobalSearch.js +++ b/packages/gatsby-theme-carbon/src/components/GlobalSearch/GlobalSearch.js @@ -33,9 +33,8 @@ import { import Menu, { MenuContext } from './Menu'; -const MAX_RESULT_LIST_SIZE = 8; +const MAX_RESULT_LIST_SIZE = 12; -// TODO pass magnifying ref for escape/close? keep focus within outline for input, const GlobalSearchInput = () => { const data = useStaticQuery(graphql` query { @@ -46,8 +45,8 @@ const GlobalSearchInput = () => { } `); - const index = data.localSearchPages.index; - const store = data.localSearchPages.store; + const { index } = data.localSearchPages; + const { store } = data.localSearchPages; const optionsRef = useRef([]); const [focusedItem, setFocusedItem] = useState(0); @@ -60,6 +59,8 @@ const GlobalSearchInput = () => { const { toggleNavState, searchIsOpen, isManagingFocus, setIsManagingFocus } = useContext(NavContext); + const trimmedResults = results.slice(0, MAX_RESULT_LIST_SIZE); + const clearAndClose = useCallback(() => { setQuery(''); toggleNavState('searchIsOpen', 'close'); @@ -197,7 +198,7 @@ const GlobalSearchInput = () => { - + ); diff --git a/yarn.lock b/yarn.lock index 1fc3675a1..fdad3abe1 100644 --- a/yarn.lock +++ b/yarn.lock @@ -10109,7 +10109,7 @@ __metadata: dependencies: "@carbon/icons-react": "npm:^11.37.0" gatsby: "npm:^5.13.3" - gatsby-theme-carbon: "npm:^4.0.0-next.8" + gatsby-theme-carbon: "npm:^4.0.0-next.9" react: "npm:^18.2.0" react-dom: "npm:^18.2.0" languageName: unknown @@ -11409,7 +11409,7 @@ __metadata: languageName: unknown linkType: soft -"gatsby-theme-carbon@npm:^4.0.0-next.8, gatsby-theme-carbon@workspace:packages/gatsby-theme-carbon": +"gatsby-theme-carbon@npm:^4.0.0-next.9, gatsby-theme-carbon@workspace:packages/gatsby-theme-carbon": version: 0.0.0-use.local resolution: "gatsby-theme-carbon@workspace:packages/gatsby-theme-carbon" dependencies: