Skip to content

Commit

Permalink
feat: add max results to search (#1466)
Browse files Browse the repository at this point in the history
  • Loading branch information
alisonjoseph authored Apr 17, 2024
1 parent 95a7a99 commit 6b36135
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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);
Expand All @@ -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');
Expand Down Expand Up @@ -197,7 +198,7 @@ const GlobalSearchInput = () => {
<Close size={20} description="Clear search" />
</button>
</div>
<Menu onKeyDown={onKeyDown} results={results} />
<Menu onKeyDown={onKeyDown} results={trimmedResults} />
</div>
</MenuContext.Provider>
);
Expand Down
4 changes: 2 additions & 2 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down

0 comments on commit 6b36135

Please sign in to comment.