[accessibility-2819223]:Bug 2819223: [Keyboard navigation - Cosmos DB Query Copilot - Copilot]: The suggestions of 'Copilot search' edit field are not accessible with keyboard. (#1893)
Co-authored-by: Satyapriya Bai <v-satybai@microsoft.com>
This commit is contained in:
parent
805a4ae168
commit
6f35fb5526
|
@ -18,7 +18,7 @@ import {
|
||||||
Text,
|
Text,
|
||||||
TextField,
|
TextField,
|
||||||
} from "@fluentui/react";
|
} from "@fluentui/react";
|
||||||
import { HttpStatusCodes } from "Common/Constants";
|
import { HttpStatusCodes, NormalizedEventKey } from "Common/Constants";
|
||||||
import { handleError } from "Common/ErrorHandlingUtils";
|
import { handleError } from "Common/ErrorHandlingUtils";
|
||||||
import QueryError, { QueryErrorSeverity } from "Common/QueryError";
|
import QueryError, { QueryErrorSeverity } from "Common/QueryError";
|
||||||
import { createUri } from "Common/UrlUtility";
|
import { createUri } from "Common/UrlUtility";
|
||||||
|
@ -35,7 +35,7 @@ import { SamplePrompts, SamplePromptsProps } from "Explorer/QueryCopilot/Shared/
|
||||||
import { Action } from "Shared/Telemetry/TelemetryConstants";
|
import { Action } from "Shared/Telemetry/TelemetryConstants";
|
||||||
import { userContext } from "UserContext";
|
import { userContext } from "UserContext";
|
||||||
import { useQueryCopilot } from "hooks/useQueryCopilot";
|
import { useQueryCopilot } from "hooks/useQueryCopilot";
|
||||||
import React, { useRef, useState } from "react";
|
import React, { useMemo, useRef, useState } from "react";
|
||||||
import HintIcon from "../../../images/Hint.svg";
|
import HintIcon from "../../../images/Hint.svg";
|
||||||
import RecentIcon from "../../../images/Recent.svg";
|
import RecentIcon from "../../../images/Recent.svg";
|
||||||
import errorIcon from "../../../images/close-black.svg";
|
import errorIcon from "../../../images/close-black.svg";
|
||||||
|
@ -71,6 +71,8 @@ export const QueryCopilotPromptbar: React.FC<QueryCopilotPromptProps> = ({
|
||||||
}: QueryCopilotPromptProps): JSX.Element => {
|
}: QueryCopilotPromptProps): JSX.Element => {
|
||||||
const [copilotTeachingBubbleVisible, setCopilotTeachingBubbleVisible] = useState<boolean>(false);
|
const [copilotTeachingBubbleVisible, setCopilotTeachingBubbleVisible] = useState<boolean>(false);
|
||||||
const inputEdited = useRef(false);
|
const inputEdited = useRef(false);
|
||||||
|
const itemRefs = useRef([]);
|
||||||
|
const searchInputRef = useRef(null);
|
||||||
const {
|
const {
|
||||||
openFeedbackModal,
|
openFeedbackModal,
|
||||||
hideFeedbackModalForLikedQueries,
|
hideFeedbackModalForLikedQueries,
|
||||||
|
@ -109,7 +111,7 @@ export const QueryCopilotPromptbar: React.FC<QueryCopilotPromptProps> = ({
|
||||||
setErrors,
|
setErrors,
|
||||||
errors,
|
errors,
|
||||||
} = useCopilotStore();
|
} = useCopilotStore();
|
||||||
|
const [focusedIndex, setFocusedIndex] = useState(-1);
|
||||||
const sampleProps: SamplePromptsProps = {
|
const sampleProps: SamplePromptsProps = {
|
||||||
isSamplePromptsOpen: isSamplePromptsOpen,
|
isSamplePromptsOpen: isSamplePromptsOpen,
|
||||||
setIsSamplePromptsOpen: setIsSamplePromptsOpen,
|
setIsSamplePromptsOpen: setIsSamplePromptsOpen,
|
||||||
|
@ -142,6 +144,7 @@ export const QueryCopilotPromptbar: React.FC<QueryCopilotPromptProps> = ({
|
||||||
: getSuggestedPrompts();
|
: getSuggestedPrompts();
|
||||||
const [filteredHistories, setFilteredHistories] = useState<string[]>(histories);
|
const [filteredHistories, setFilteredHistories] = useState<string[]>(histories);
|
||||||
const [filteredSuggestedPrompts, setFilteredSuggestedPrompts] = useState<SuggestedPrompt[]>(suggestedPrompts);
|
const [filteredSuggestedPrompts, setFilteredSuggestedPrompts] = useState<SuggestedPrompt[]>(suggestedPrompts);
|
||||||
|
const { UpArrow, DownArrow, Enter } = NormalizedEventKey;
|
||||||
|
|
||||||
const handleUserPromptChange = (event: React.ChangeEvent<HTMLInputElement>) => {
|
const handleUserPromptChange = (event: React.ChangeEvent<HTMLInputElement>) => {
|
||||||
inputEdited.current = true;
|
inputEdited.current = true;
|
||||||
|
@ -307,7 +310,38 @@ export const QueryCopilotPromptbar: React.FC<QueryCopilotPromptProps> = ({
|
||||||
return "Content is updated";
|
return "Content is updated";
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
const openSamplePrompts = () => {
|
||||||
|
inputEdited.current = true;
|
||||||
|
setShowSamplePrompts(true);
|
||||||
|
};
|
||||||
|
const totalSuggestions = useMemo(
|
||||||
|
() => [...filteredSuggestedPrompts, ...filteredHistories],
|
||||||
|
[filteredSuggestedPrompts, filteredHistories],
|
||||||
|
);
|
||||||
|
|
||||||
|
const handleKeyDownForInput = (event: React.KeyboardEvent<HTMLInputElement>) => {
|
||||||
|
if (event.key === DownArrow) {
|
||||||
|
setFocusedIndex(0);
|
||||||
|
itemRefs.current[0]?.current?.focus();
|
||||||
|
} else if (event.key === Enter && userPrompt) {
|
||||||
|
inputEdited.current = true;
|
||||||
|
startGenerateQueryProcess();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleKeyDownForItem = (event: React.KeyboardEvent<HTMLInputElement>) => {
|
||||||
|
if (event.key === UpArrow && focusedIndex > 0) {
|
||||||
|
itemRefs.current[focusedIndex - 1].current?.focus();
|
||||||
|
setFocusedIndex((prevIndex) => prevIndex - 1);
|
||||||
|
} else if (event.key === DownArrow && focusedIndex < totalSuggestions.length - 1) {
|
||||||
|
itemRefs.current[focusedIndex + 1].current?.focus();
|
||||||
|
setFocusedIndex((prevIndex) => prevIndex + 1);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
React.useEffect(() => {
|
||||||
|
itemRefs.current = totalSuggestions.map(() => React.createRef());
|
||||||
|
}, [totalSuggestions]);
|
||||||
React.useEffect(() => {
|
React.useEffect(() => {
|
||||||
useTabs.getState().setIsQueryErrorThrown(false);
|
useTabs.getState().setIsQueryErrorThrown(false);
|
||||||
}, []);
|
}, []);
|
||||||
|
@ -337,23 +371,14 @@ export const QueryCopilotPromptbar: React.FC<QueryCopilotPromptProps> = ({
|
||||||
id="naturalLanguageInput"
|
id="naturalLanguageInput"
|
||||||
value={userPrompt}
|
value={userPrompt}
|
||||||
onChange={handleUserPromptChange}
|
onChange={handleUserPromptChange}
|
||||||
onClick={() => {
|
onClick={openSamplePrompts}
|
||||||
inputEdited.current = true;
|
onFocus={() => setShowSamplePrompts(true)}
|
||||||
setShowSamplePrompts(true);
|
elementRef={searchInputRef}
|
||||||
}}
|
onKeyDown={handleKeyDownForInput}
|
||||||
onKeyDown={(e) => {
|
|
||||||
if (e.key === "Enter" && userPrompt) {
|
|
||||||
inputEdited.current = true;
|
|
||||||
startGenerateQueryProcess();
|
|
||||||
}
|
|
||||||
}}
|
|
||||||
style={{ lineHeight: 30 }}
|
style={{ lineHeight: 30 }}
|
||||||
styles={{
|
styles={{
|
||||||
root: { width: "100%" },
|
root: { width: "100%" },
|
||||||
suffix: {
|
suffix: { background: "none", padding: 0 },
|
||||||
background: "none",
|
|
||||||
padding: 0,
|
|
||||||
},
|
|
||||||
fieldGroup: {
|
fieldGroup: {
|
||||||
borderRadius: 4,
|
borderRadius: 4,
|
||||||
borderColor: "#D1D1D1",
|
borderColor: "#D1D1D1",
|
||||||
|
@ -366,7 +391,8 @@ export const QueryCopilotPromptbar: React.FC<QueryCopilotPromptProps> = ({
|
||||||
},
|
},
|
||||||
}}
|
}}
|
||||||
disabled={isGeneratingQuery}
|
disabled={isGeneratingQuery}
|
||||||
autoComplete="off"
|
autoComplete="list"
|
||||||
|
aria-expanded={showSamplePrompts}
|
||||||
placeholder="Ask a question in natural language and we’ll generate the query for you."
|
placeholder="Ask a question in natural language and we’ll generate the query for you."
|
||||||
aria-labelledby="copilot-textfield-label"
|
aria-labelledby="copilot-textfield-label"
|
||||||
onRenderSuffix={() => {
|
onRenderSuffix={() => {
|
||||||
|
@ -438,6 +464,8 @@ export const QueryCopilotPromptbar: React.FC<QueryCopilotPromptProps> = ({
|
||||||
setShowSamplePrompts(false);
|
setShowSamplePrompts(false);
|
||||||
inputEdited.current = true;
|
inputEdited.current = true;
|
||||||
}}
|
}}
|
||||||
|
elementRef={itemRefs.current[i]}
|
||||||
|
onKeyDown={handleKeyDownForItem}
|
||||||
onRenderIcon={() => <Image src={RecentIcon} styles={{ root: { overflow: "unset" } }} />}
|
onRenderIcon={() => <Image src={RecentIcon} styles={{ root: { overflow: "unset" } }} />}
|
||||||
styles={promptStyles}
|
styles={promptStyles}
|
||||||
>
|
>
|
||||||
|
@ -460,14 +488,16 @@ export const QueryCopilotPromptbar: React.FC<QueryCopilotPromptProps> = ({
|
||||||
>
|
>
|
||||||
Suggested Prompts
|
Suggested Prompts
|
||||||
</Text>
|
</Text>
|
||||||
{filteredSuggestedPrompts.map((prompt) => (
|
{filteredSuggestedPrompts.map((prompt, index) => (
|
||||||
<DefaultButton
|
<DefaultButton
|
||||||
key={prompt.id}
|
key={prompt.id}
|
||||||
|
elementRef={itemRefs.current[filteredHistories.length + index]}
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
setUserPrompt(prompt.text);
|
setUserPrompt(prompt.text);
|
||||||
setShowSamplePrompts(false);
|
setShowSamplePrompts(false);
|
||||||
inputEdited.current = true;
|
inputEdited.current = true;
|
||||||
}}
|
}}
|
||||||
|
onKeyDown={handleKeyDownForItem}
|
||||||
onRenderIcon={() => <Image src={HintIcon} />}
|
onRenderIcon={() => <Image src={HintIcon} />}
|
||||||
styles={promptStyles}
|
styles={promptStyles}
|
||||||
>
|
>
|
||||||
|
|
Loading…
Reference in New Issue