Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ProDev Copilot] Enhance accessibility by adding ARIA attributes and keyboard navigation #1085

Merged
merged 3 commits into from
Dec 23, 2024
Merged
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
31 changes: 21 additions & 10 deletions src/common/copilot/assets/scripts/copilot.js
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@
copyButton.classList.add("action-button");
copyButton.classList.add("copy-button");
copyButton.title = copilotStrings.COPY_TO_CLIPBOARD_MESSAGE;
copyButton.setAttribute("aria-label", copilotStrings.COPY_TO_CLIPBOARD_MESSAGE);
copyButton.addEventListener("click", () => {
copyCodeToClipboard(code);
});
Expand All @@ -144,12 +145,12 @@
insertButton.classList.add("action-button");
insertButton.classList.add("insert-button");
insertButton.title = copilotStrings.INSERT_CODE_MESSAGE;
insertButton.setAttribute("aria-label", copilotStrings.INSERT_CODE_MESSAGE);
insertButton.addEventListener("click", () => {
insertCode(code);
});
actionWrapper.appendChild(insertButton);


return actionWrapper;
}

Expand All @@ -160,7 +161,6 @@
return truncatedInitials.join("").toUpperCase();
}


function handleUserMessage(message) {
const messageWrapper = document.createElement("div");
messageWrapper.classList.add("message-wrapper");
Expand Down Expand Up @@ -259,21 +259,21 @@
const listPrompt = copilotStrings.LIST_PROMPT;

suggestedPrompt.innerHTML = `<p class="suggested-title">${copilotStrings.SUGGESTIONS_MESSAGE}</p>
<a href='#' class="suggested-prompt">
<a href='#' class="suggested-prompt" tabindex="0" aria-label="${formPrompt}">
<span class="icon-container">
${starIconSvg}
</span>
${formPrompt}
</a>
<br>
<a href='#' class="suggested-prompt">
<a href='#' class="suggested-prompt" tabindex="0" aria-label="${webApiPrompt}">
<span class="icon-container">
${starIconSvg}
</span>
${webApiPrompt}
</a>
<br>
<a href='#' class="suggested-prompt">
<a href='#' class="suggested-prompt" tabindex="0" aria-label="${listPrompt}">
<span class="icon-container">
${starIconSvg}
</span>
Expand All @@ -287,7 +287,7 @@
const walkthrough = document.createElement("div");
walkthrough.classList.add("walkthrough-div");
walkthrough.innerHTML = `<p class="walkthrough-title">${copilotStrings.GETTING_STARTED_MESSAGE}</p>
<a href="#" class="walkthrough-content">
<a href="#" class="walkthrough-content" tabindex="0" aria-label="${copilotStrings.LEARN_MORE_MESSAGE}">
${bookIconSvg}
<span id="walk-text">${copilotStrings.LEARN_MORE_MESSAGE}</span>
</a>`;
Expand Down Expand Up @@ -317,6 +317,7 @@
const thinking = document.createElement("div");
thinking.classList.add("thinking");
thinking.innerText = thinkingMessage;
thinking.setAttribute("aria-live", "assertive"); // Add aria-live attribute

messageElement.appendChild(thinking);
chatMessages.scrollTop = chatMessages.scrollHeight - chatMessages.clientHeight;
Expand All @@ -341,6 +342,7 @@
messageIndex++;

const apiResponseElement = parseCodeBlocks(apiResponse);
apiResponseElement.setAttribute("aria-live", "assertive"); // Add aria-live attribute to response
messageElement.appendChild(apiResponseElement);

messageWrapper.dataset.id = message.id;
Expand Down Expand Up @@ -375,7 +377,7 @@
notLoggedIn.classList.add("not-loggedIn");
notLoggedIn.innerHTML = `<p id="greeting"></p>
<p>${copilotStrings.LOGIN_MESSAGE}</p>
<button id="loginButton" >${copilotStrings.LOGIN_BUTTON}</button>`;
<button id="loginButton" aria-label="${copilotStrings.LOGIN_BUTTON}">${copilotStrings.LOGIN_BUTTON}</button>`;

messageElement.appendChild(notLoggedIn);

Expand Down Expand Up @@ -403,21 +405,31 @@
vscode.postMessage({ type: "openGitHubCopilotLink" });
});


const suggestedPromptDiv = createSuggestedPromptDiv();
messageElement.appendChild(suggestedPromptDiv);

const suggestedPrompts = document.querySelectorAll(".suggested-prompt");
suggestedPrompts.forEach((suggestedPrompt) => {
suggestedPrompt.addEventListener("click", handleSuggestionsClick);
suggestedPrompt.addEventListener("keydown", (event) => {
if (event.key === "Enter" || event.key === " ") {
event.preventDefault();
handleSuggestionsClick.call(suggestedPrompt);
}
});
});

const walkthroughDiv = createWalkthroughDiv();
messageElement.appendChild(walkthroughDiv);

const walkthroughContent = document.getElementById("walk-text");
walkthroughContent.addEventListener("click", handleWalkthroughClick);

walkthroughContent.addEventListener("keydown", (event) => {
if (event.key === "Enter" || event.key === " ") {
event.preventDefault();
handleWalkthroughClick.call(walkthroughContent);
}
});
}
};
}
Expand All @@ -443,7 +455,6 @@
<p>${copilotStrings.DOCUMENTATION_LINK}<a></p>`;

messageElement.appendChild(notAvailabel);

}

// Handle messages sent from the extension to the webview
Expand Down
Loading