{"version":3,"file":"useSearchResultsKeyboardNavigation.mjs","names":[],"sources":["../../../../../src/components/Search/hooks/useSearchResultsKeyboardNavigation.ts"],"sourcesContent":["import type { RefObject } from 'react';\n\nimport {\n  createRowActionKeyHandlers,\n  useListboxKeyboardNavigation,\n} from '../../../a11y/hooks/useListboxKeyboardNavigation';\n\n// Channel and message results render a `ChannelListItem`, so they have a row container and action\n// buttons. User results do not, so the horizontal keys do nothing there.\nconst OPTION_SELECTOR = '[role=\"option\"]';\nconst ROW_SELECTOR = '.str-chat__channel-list-item-container';\nconst ACTION_BUTTON_SELECTOR = '.str-chat__channel-list-item__action-buttons button';\n\n/**\n * Keyboard navigation for the search results. ArrowUp, ArrowDown, Home and End rove the result\n * options from anywhere in the container, so they also work from the filter buttons before the\n * options and from a result's action button. ArrowRight and ArrowLeft move between a result and its\n * action button.\n *\n * @param containerRef - Container of the result options.\n * @returns An object with the `onKeyDown` handler to attach to the container.\n */\nexport const useSearchResultsKeyboardNavigation = (\n  containerRef: RefObject<HTMLElement | null>,\n) => {\n  const { onKeyDown } = useListboxKeyboardNavigation(containerRef, {\n    enterScope: 'container',\n    keyHandlers: createRowActionKeyHandlers({\n      actionSelector: ACTION_BUTTON_SELECTOR,\n      rowSelector: ROW_SELECTOR,\n    }),\n    resolveActiveOption: (active) =>\n      active.closest(ROW_SELECTOR)?.querySelector<HTMLElement>(OPTION_SELECTOR) ?? null,\n  });\n\n  return { onKeyDown };\n};\n"],"mappings":";;AASA,IAAM,kBAAkB;AACxB,IAAM,eAAe;AACrB,IAAM,yBAAyB;;;;;;;;;;AAW/B,IAAa,sCACX,iBACG;CACH,MAAM,EAAE,cAAc,6BAA6B,cAAc;EAC/D,YAAY;EACZ,aAAa,2BAA2B;GACtC,gBAAgB;GAChB,aAAa;EACf,CAAC;EACD,sBAAsB,WACpB,OAAO,QAAQ,YAAY,CAAC,EAAE,cAA2B,eAAe,KAAK;CACjF,CAAC;CAED,OAAO,EAAE,UAAU;AACrB"}