diff --git a/public/translations/en.json b/public/translations/en.json
index 9ee80fc55..aaebded83 100644
--- a/public/translations/en.json
+++ b/public/translations/en.json
@@ -215,11 +215,14 @@
"errors": {
"interrupted": "Execution interrupted"
},
+ "errorMessage": {
+ "title": "Error running your code"
+ },
"aiErrorMessages": {
"loadingText": "Generating hint",
- "buttonText": "Need help? Generate an AI hint",
+ "buttonText": "Generate an AI hint",
"retryButtonText": "Try again",
- "aiGeneratedHint": "AI generated hint",
+ "aiGeneratedHint": "AI-generated hint",
"errorText": "We were not able to generate a hint, try again later.",
"notice": "AI hints can be wrong. Learn more and share feedback",
"turnOff": "Turn off AI hints"
@@ -360,7 +363,7 @@
"charity": "Raspberry Pi Foundation - UK registered charity 1129409",
"settingsMenu": {
"heading": "Settings",
- "aiHint": "AI generated hints",
+ "aiHint": "AI-generated hints",
"aiHintDescription": "When your code has an error, you can generate a hint using AI. Hints do not give you the answer and can be wrong. Learn more about how AI hints work or share feedback.",
"textSize": "Text size",
"theme": "Theme",
diff --git a/src/assets/icons/cancel_FILL.svg b/src/assets/icons/cancel_FILL.svg
index 5ef0d2fec..23f1bdc80 100644
--- a/src/assets/icons/cancel_FILL.svg
+++ b/src/assets/icons/cancel_FILL.svg
@@ -1,3 +1,3 @@
-
+
\ No newline at end of file
diff --git a/src/assets/icons/chevron_down.svg b/src/assets/icons/chevron_down.svg
index 77708f4a0..c4da7a249 100644
--- a/src/assets/icons/chevron_down.svg
+++ b/src/assets/icons/chevron_down.svg
@@ -1,9 +1,9 @@
diff --git a/src/assets/stylesheets/ErrorMessage.scss b/src/assets/stylesheets/ErrorMessage.scss
index 409b7b947..74d5d2959 100644
--- a/src/assets/stylesheets/ErrorMessage.scss
+++ b/src/assets/stylesheets/ErrorMessage.scss
@@ -4,29 +4,96 @@
.error-message {
color: var(--rpf-red-900);
background-color: var(--rpf-red-100);
- border-block: 1px solid var(--editor-color-outline);
- padding: var(--space-1);
+ border-block-start: 1px solid var(--rpf-red-200);
+ display: flex;
+ flex-direction: column;
+ min-block-size: 0;
overflow-y: auto;
+ &__summary {
+ position: sticky;
+ inset-block-start: 0;
+ background-color: var(--rpf-red-100);
+ z-index: 1;
+ display: flex;
+ align-items: center;
+ justify-content: space-between;
+ gap: var(--space-1);
+ padding: var(--space-1);
+ list-style: none;
+ cursor: pointer;
+
+ &::-webkit-details-marker {
+ display: none;
+ }
+
+ &:focus-visible {
+ outline: 3px solid var(--editor-focus-color);
+ outline-offset: -3px;
+ }
+ }
+
+ @supports selector(::details-content) {
+ overflow-y: visible;
+ details {
+ display: flex;
+ flex-direction: column;
+ min-block-size: 0;
+
+ &::details-content {
+ min-block-size: 0;
+ overflow-y: auto;
+ }
+ }
+
+ .error-message__summary {
+ position: static;
+ }
+ }
+
+ details &__summary {
+ border-block-end: 1px solid var(--rpf-red-200);
+ }
+
+ &__title {
+ display: flex;
+ align-items: center;
+ gap: var(--space-1);
+ margin: 0;
+ @include typography.style-1;
+ font-weight: bold;
+
+ svg {
+ flex-shrink: 0;
+ }
+ }
+
+ &__chevron {
+ flex-shrink: 0;
+ fill: var(--rpf-text-primary);
+ transition: transform 0.2s ease-in-out;
+ }
+
+ details[open] &__chevron {
+ transform: rotate(180deg);
+ }
+
+ &__content {
+ padding-block: var(--space-1);
+ padding-inline: var(--space-1-5);
+ }
+
&__error {
padding: 0;
margin: 0;
+ font-family: inherit;
white-space: pre-wrap;
overflow-wrap: break-word;
- font-weight: bold;
+ @include typography.style-1;
}
&__python {
display: flex;
gap: var(--space-1);
- @include typography.style-1;
-
- &--medium {
- @include typography.style-1;
- }
-
- &--large {
- @include typography.style-2;
- }
}
}
diff --git a/src/assets/stylesheets/SettingsPanel.scss b/src/assets/stylesheets/SettingsPanel.scss
index f25d19873..c6e51e2e4 100644
--- a/src/assets/stylesheets/SettingsPanel.scss
+++ b/src/assets/stylesheets/SettingsPanel.scss
@@ -23,6 +23,10 @@
p {
color: var(--rpf-text-secondary);
margin-block: var(--space-0-5) 0;
+
+ a {
+ font-weight: var(--font-weight-bold);
+ }
}
}
}
diff --git a/src/components/Editor/AiErrorMessage/AiErrorMessage.jsx b/src/components/Editor/AiErrorMessage/AiErrorMessage.jsx
index e937fe259..97dbc35ed 100644
--- a/src/components/Editor/AiErrorMessage/AiErrorMessage.jsx
+++ b/src/components/Editor/AiErrorMessage/AiErrorMessage.jsx
@@ -46,6 +46,14 @@ const AiErrorMessage = () => {
};
}, [errorDetails]);
+ // Showing the hint removes the button that had focus, so move focus to the result.
+ const resultRef = useRef(null);
+ const showResult = Boolean(hint || failed);
+
+ useEffect(() => {
+ if (showResult) resultRef.current?.focus();
+ }, [showResult]);
+
const handleButtonClick = async () => {
const code =
projectCode?.find((c) => c.name === "main" && c.extension === "py")
@@ -106,11 +114,11 @@ const AiErrorMessage = () => {
};
return (
-
- {(hint || failed) && (
-
+
+ {showResult && (
+
-
+
{t("output.aiErrorMessages.aiGeneratedHint")}
diff --git a/src/components/Editor/AiErrorMessage/AiErrorMessage.test.jsx b/src/components/Editor/AiErrorMessage/AiErrorMessage.test.jsx
index 1d391698b..1f54f5f8f 100644
--- a/src/components/Editor/AiErrorMessage/AiErrorMessage.test.jsx
+++ b/src/components/Editor/AiErrorMessage/AiErrorMessage.test.jsx
@@ -140,6 +140,30 @@ describe("AiErrorMessage", () => {
).not.toBeInTheDocument();
});
+ test("Moves focus to the hint when it replaces the button", async () => {
+ getAiErrorHint.mockResolvedValue({ data: { fem: "A friendly hint" } });
+ renderAiErrorMessage();
+ hintButton().focus();
+ await clickButtonAndWait();
+
+ expect(document.querySelector(".ai-error-message__hint")).toHaveFocus();
+ });
+
+ test("Moves focus to the error text when the request fails", async () => {
+ getAiErrorHint.mockRejectedValue(new Error("Bad gateway"));
+ renderAiErrorMessage();
+ hintButton().focus();
+ await clickButtonAndWait();
+
+ expect(document.querySelector(".ai-error-message__hint")).toHaveFocus();
+ });
+
+ test("Does not move focus before a hint is requested", () => {
+ renderAiErrorMessage();
+
+ expect(document.body).toHaveFocus();
+ });
+
test("Keeps loading for the minimum time when the response is fast", async () => {
getAiErrorHint.mockResolvedValue({ data: { fem: "A friendly hint" } });
renderAiErrorMessage();
diff --git a/src/components/Editor/ErrorMessage/ErrorMessage.jsx b/src/components/Editor/ErrorMessage/ErrorMessage.jsx
index 419fcc724..dee576386 100644
--- a/src/components/Editor/ErrorMessage/ErrorMessage.jsx
+++ b/src/components/Editor/ErrorMessage/ErrorMessage.jsx
@@ -1,33 +1,52 @@
-import React, { useContext } from "react";
import "../../../assets/stylesheets/ErrorMessage.scss?inline";
import { useSelector } from "react-redux";
import DOMPurify from "dompurify";
-import { SettingsContext } from "../../../utils/settings";
+import { useTranslation } from "react-i18next";
import CancelFillIcon from "../../../assets/icons/cancel_FILL.svg";
+import ChevronDownIcon from "../../../assets/icons/chevron_down.svg";
import FriendlyErrorMessage from "../FriendlyErrorMessage/FriendlyErrorMessage";
import AiErrorMessage from "../AiErrorMessage/AiErrorMessage";
import useAiHintOffered from "../../../hooks/useAiHintOffered";
const ErrorMessage = () => {
const error = useSelector((state) => state.editor.error);
- const settings = useContext(SettingsContext);
+ const { t } = useTranslation();
const aiHintOffered = useAiHintOffered();
- return error ? (
-
-
-
-
+ return (
+ <>
+ {/* Screen readers are already watching it when an error appears.
+ Announces the title, without moving focus away from the Run button. */}
+