Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ Repository administrators{% ifversion ghec %}, organization owners, and enterpri
| JetBrains IDEs | {% octicon "check" aria-label="Supported" %} | {% octicon "check" aria-label="Supported" %} |
| Vim/Neovim | {% octicon "check" aria-label="Supported" %} | Not applicable |
| Xcode | {% octicon "check" aria-label="Supported" %} | Not applicable |
| Eclipse | {% octicon "check" aria-label="Supported" %} | {% octicon "x" aria-label="Not supported" %} |
| Azure Data Studio | {% octicon "x" aria-label="Not supported" %} | Not applicable |
| The {% data variables.product.github %} website | Not applicable | {% octicon "check" aria-label="Supported" %} |
| {% data variables.product.prodname_mobile %} | Not applicable | {% octicon "check" aria-label="Supported" %} |
Expand Down
37 changes: 30 additions & 7 deletions src/search/components/input/AskAIResults.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ export function AskAIResults({
const [message, setMessage] = useState('')
const [initialLoading, setInitialLoading] = useState(true)
const [responseLoading, setResponseLoading] = useState(false)
const [announcement, setAnnouncement] = useState<string>('')
const disclaimerRef = useRef<HTMLDivElement>(null)
// We cache up to 1000 queries, and expire them after 30 days
const { getItem, setItem } = useAISearchLocalStorageCache<{
Expand All @@ -83,6 +84,7 @@ export function AskAIResults({
status: 400,
})
setMessage(cannedResponse)
setAnnouncement(cannedResponse)
setReferences([])
setItem(
query,
Expand All @@ -105,6 +107,7 @@ export function AskAIResults({
}
let isCancelled = false
setMessage('')
setAnnouncement('')
setReferences([])
setAICouldNotAnswer(false)
setInitialLoading(true)
Expand All @@ -118,13 +121,18 @@ export function AskAIResults({
setAICouldNotAnswer(cachedData.aiCouldNotAnswer || false)
setInitialLoading(false)
setResponseLoading(false)

sendAISearchResultEvent({
sources: cachedData.sources,
message: cachedData.message,
eventGroupId: askAIEventGroupId.current,
couldNotAnswer: cachedData.aiCouldNotAnswer,
status: cachedData.aiCouldNotAnswer ? 400 : 200,
})

setTimeout(() => {
setAnnouncement(cachedData.message)
}, 1500)
return
}

Expand Down Expand Up @@ -203,6 +211,9 @@ export function AskAIResults({
setMessage(messageBuffer)
}
}
if (!isCancelled) {
setAnnouncement('Copilot Response Loading...')
}
}
}
}
Expand Down Expand Up @@ -246,18 +257,12 @@ export function AskAIResults({

return (
<div className={styles.container}>
{/* Hidden status message for screen readers */}
<span role="status" aria-live="polite" className={styles.displayForScreenReader}>
{initialLoading || responseLoading
? t('search.ai.loading_status_message')
: t('search.ai.done_loading_status_message')}
</span>
{initialLoading ? (
<div className={styles.loadingContainer} role="status">
<Spinner />
</div>
) : (
<article aria-busy={responseLoading} aria-live="polite">
<article aria-busy={responseLoading} aria-live="assertive">
{!aiCouldNotAnswer && message !== '' ? (
<span ref={disclaimerRef} className={styles.disclaimerText}>
{t('search.ai.disclaimer')}
Expand Down Expand Up @@ -358,6 +363,8 @@ export function AskAIResults({
paddingLeft: '0px',
}}
key={`reference-${index}`}
id={`search-option-reference-${index + referencesIndexOffset}`}
role="option"
tabIndex={-1}
onSelect={() => {
referenceOnSelect(source.url)
Expand All @@ -374,6 +381,22 @@ export function AskAIResults({
</ActionList>
</>
) : null}
<div
aria-live="assertive"
style={{
position: 'absolute',
width: '1px',
height: '1px',
padding: '0',
margin: '-1px',
overflow: 'hidden',
clip: 'rect(0, 0, 0, 0)',
whiteSpace: 'nowrap',
border: '0',
}}
>
{announcement}
</div>
</div>
)
}
Expand Down
41 changes: 30 additions & 11 deletions src/search/components/input/SearchOverlay.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ import { EventType } from '@/events/types'
import { ASK_AI_EVENT_GROUP, SEARCH_OVERLAY_EVENT_GROUP } from '@/events/components/event-groups'
import type { AIReference } from '../types'
import type { AutocompleteSearchHit, GeneralSearchHit } from '@/search/types'
import { focusTrap } from '@primer/behaviors'

type Props = {
searchOverlayOpen: boolean
Expand Down Expand Up @@ -88,6 +89,14 @@ export function SearchOverlay({

// Group all events between open / close of the overlay together
const searchEventGroupId = useRef<string>('')
const overlayRef = useRef<HTMLDivElement>(null)

useEffect(() => {
if (searchOverlayOpen && overlayRef.current) {
focusTrap(overlayRef.current, inputRef.current || undefined)
}
}, [searchOverlayOpen])

useEffect(() => {
searchEventGroupId.current = uuidv4()
}, [searchOverlayOpen])
Expand Down Expand Up @@ -486,6 +495,7 @@ export function SearchOverlay({
<>
<ActionList
aria-label={t('search.overlay.suggestions_list_aria_label')}
id="search-suggestions-list"
showDividers
className={styles.suggestionsList}
ref={suggestionsListHeightRef}
Expand Down Expand Up @@ -601,6 +611,7 @@ export function SearchOverlay({
role="dialog"
aria-modal="true"
aria-labelledby={overlayHeadingId}
ref={overlayRef}
>
<Header className={styles.header}>
<TextInput
Expand All @@ -609,9 +620,17 @@ export function SearchOverlay({
ref={inputRef}
value={urlSearchInputQuery}
onChange={handleSearchQueryChange}
onKeyDown={handleKeyDown}
leadingVisual={<SearchIcon />}
aria-labelledby={overlayHeadingId}
role="combobox"
aria-controls="search-suggestions-list"
aria-expanded={combinedOptions.length > 0}
aria-activedescendant={
selectedIndex >= 0
? `search-option-${combinedOptions[selectedIndex].group}-${selectedIndex}`
: undefined
}
onKeyDown={handleKeyDown}
placeholder={t('search.input.placeholder_no_icon')}
trailingAction={
<Stack
Expand Down Expand Up @@ -793,6 +812,8 @@ function renderSearchGroups(
items.push(
<ActionList.Item
key={`general-${index}`}
id={`search-option-general-${index}`}
role="option"
className={styles.noResultsFound}
tabIndex={-1}
aria-label={t('search.overlay.no_results_found')}
Expand All @@ -808,6 +829,9 @@ function renderSearchGroups(
items.push(
<ActionList.Item
key={`general-${index}`}
id={`search-option-general-${index}`}
role="option"
aria-describedby="search-suggestions-list"
onSelect={() =>
option.isViewAllResults ? performGeneralSearch() : generalSearchResultOnSelect(option)
}
Expand Down Expand Up @@ -843,11 +867,7 @@ function renderSearchGroups(

groups.push(
<ActionList.Group key="general" data-testid="general-autocomplete-suggestions">
<ActionList.GroupHeading
as="h3"
tabIndex={-1}
aria-label={t('search.overlay.general_suggestions_list_aria_label')}
>
<ActionList.GroupHeading as="h3" tabIndex={-1} id="search-suggestions-list">
{t('search.overlay.general_suggestions_list_heading')}
</ActionList.GroupHeading>
{items}
Expand All @@ -872,11 +892,7 @@ function renderSearchGroups(
if (aiOptionsWithUserInput.length && !isInAskAIState) {
groups.push(
<ActionList.Group key="ai-suggestions" data-testid="ai-autocomplete-suggestions">
<ActionList.GroupHeading
as="h3"
tabIndex={-1}
aria-label={t('search.overlay.ai_suggestions_list_aria_label')}
>
<ActionList.GroupHeading as="h3" id="copilot-suggestions" tabIndex={-1}>
<CopilotIcon className="mr-1" />
{t('search.overlay.ai_autocomplete_list_heading')}
</ActionList.GroupHeading>
Expand All @@ -887,6 +903,9 @@ function renderSearchGroups(
const item = (
<ActionList.Item
key={`ai-${indexWithOffset}`}
id={`search-option-ai-${indexWithOffset}`}
role="option"
aria-describedby="copilot-suggestions"
onSelect={() => aiAutocompleteOnSelect(option)}
active={isActive}
tabIndex={-1}
Expand Down
Loading