From c3cbb2e83e786c6bfd363e6e137ef4265f8eef15 Mon Sep 17 00:00:00 2001 From: Duane Nykamp Date: Mon, 19 Oct 2026 12:55:42 -0500 Subject: [PATCH 1/2] Show the virtual keyboard in assignments Every document's viewer was given addVirtualKeyboard={false}, and the addVirtualKeyboard prop of ActivityViewer was accepted but never used, so an assignment had no Doenet virtual keyboard. On a touch device a math input also keeps the device's own keyboard down, which left readers on an iPad with no keyboard at all. addVirtualKeyboard now reaches each document's viewer, defaulting to true. The viewers share a single keyboard tray on the page. Bump the version to 0.1.0-alpha-19, and bring the version recorded in package-lock.json, which still said alpha-17, up to match. Co-Authored-By: Claude Opus 5.5 --- package-lock.json | 4 +- package.json | 2 +- src/Activity/Activity.tsx | 5 ++ src/Activity/SingleDocActivity.tsx | 3 +- src/Viewer/Viewer.tsx | 3 +- .../ActivityViewer.virtualKeyboard.cy.tsx | 81 +++++++++++++++++++ 6 files changed, 93 insertions(+), 5 deletions(-) create mode 100644 test/cypress/component/ActivityViewer.virtualKeyboard.cy.tsx diff --git a/package-lock.json b/package-lock.json index 4dd9218..a1935aa 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@doenet/assignment-viewer", - "version": "0.1.0-alpha-17", + "version": "0.1.0-alpha-19", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "@doenet/assignment-viewer", - "version": "0.1.0-alpha-17", + "version": "0.1.0-alpha-19", "license": "AGPL-3.0-or-later", "dependencies": { "nanoid": "^5.1.6", diff --git a/package.json b/package.json index 336faa3..3c83dd5 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "name": "@doenet/assignment-viewer", "private": false, "description": "View assignments from questions written in DoenetML", - "version": "0.1.0-alpha-18", + "version": "0.1.0-alpha-19", "license": "AGPL-3.0-or-later", "homepage": "https://github.com/Doenet/assignment-viewer#readme", "type": "module", diff --git a/src/Activity/Activity.tsx b/src/Activity/Activity.tsx index 83405fb..a53f1eb 100644 --- a/src/Activity/Activity.tsx +++ b/src/Activity/Activity.tsx @@ -23,6 +23,11 @@ export type ActivityCommonProps = { doenetmlVersion?: string; fetchExternalDoenetML?: (arg: string) => Promise; darkMode?: "dark" | "light"; + /** + * Whether each document's viewer offers the Doenet virtual keyboard. The + * viewers share a single keyboard tray on the page. + */ + addVirtualKeyboard?: boolean; showAnswerResponseMenu?: boolean; answerResponseCountsByItem?: Record[]; doenetStates: unknown[]; diff --git a/src/Activity/SingleDocActivity.tsx b/src/Activity/SingleDocActivity.tsx index a62d33f..4e017d9 100644 --- a/src/Activity/SingleDocActivity.tsx +++ b/src/Activity/SingleDocActivity.tsx @@ -35,6 +35,7 @@ export const SingleDocActivity = memo(function SingleDocActivity({ doenetmlVersion, fetchExternalDoenetML, darkMode = "light", + addVirtualKeyboard = true, showAnswerResponseMenu = false, answerResponseCounts, state, @@ -136,7 +137,7 @@ export const SingleDocActivity = memo(function SingleDocActivity({ darkMode={darkMode} showAnswerResponseMenu={showAnswerResponseMenu} answerResponseCounts={answerResponseCounts} - addVirtualKeyboard={false} + addVirtualKeyboard={addVirtualKeyboard} initialState={initialDoenetState} initializeCounters={initialCounters} mountPolicy={mountPolicy} diff --git a/src/Viewer/Viewer.tsx b/src/Viewer/Viewer.tsx index 82f564c..c2c4cdd 100644 --- a/src/Viewer/Viewer.tsx +++ b/src/Viewer/Viewer.tsx @@ -45,7 +45,7 @@ export function Viewer({ forceShowCorrectness = false, forceShowSolution = false, forceUnsuppressCheckwork = false, - addVirtualKeyboard: _addVirtualKeyboard = true, + addVirtualKeyboard = true, externalVirtualKeyboardProvided: _externalVirtualKeyboardProvided = false, doenetViewerUrl, doenetImagesUrl, @@ -615,6 +615,7 @@ export function Viewer({ doenetmlVersion={doenetmlVersion} fetchExternalDoenetML={fetchExternalDoenetML} darkMode={darkMode} + addVirtualKeyboard={addVirtualKeyboard} showAnswerResponseMenu={showAnswerResponseMenu} answerResponseCountsByItem={answerResponseCountsByItem} state={activityState} diff --git a/test/cypress/component/ActivityViewer.virtualKeyboard.cy.tsx b/test/cypress/component/ActivityViewer.virtualKeyboard.cy.tsx new file mode 100644 index 0000000..6f46d2f --- /dev/null +++ b/test/cypress/component/ActivityViewer.virtualKeyboard.cy.tsx @@ -0,0 +1,81 @@ +import React from "react"; +import { ActivityViewer } from "../../../src/activity-viewer"; +import type { ActivitySource } from "../../../src/Activity/activityState"; +import type { SingleDocSource } from "../../../src/Activity/singleDocState"; +import { + STANDALONE_URL, + STANDALONE_CSS_URL, + IFRAME_READY_TIMEOUT, +} from "./helpers"; + +// `addVirtualKeyboard` must reach each document's embedded ``, +// whose iframe wrapper draws the virtual keyboard tray in this page. Every +// viewer on a page shares one tray, so an activity of several documents still +// shows a single keyboard. + +function mkDoc(id: string): SingleDocSource { + return { + id, + type: "singleDoc", + isDescription: false, + doenetML: `

`, + version: "0.7.24", + numVariants: 1, + }; +} + +const SOURCE = { + type: "sequence", + id: "seq", + title: "keyboard", + shuffle: false, + items: [mkDoc("doc1"), mkDoc("doc2")], +} as ActivitySource; + +function waitForDocuments() { + cy.get("iframe", { timeout: IFRAME_READY_TIMEOUT }).should( + "have.length", + 2, + ); + cy.get("iframe").each(($iframe) => { + cy.wrap($iframe) + .its("0.contentDocument.body", { timeout: IFRAME_READY_TIMEOUT }) + .find("#mi", { timeout: IFRAME_READY_TIMEOUT }) + .should("exist"); + }); +} + +describe("ActivityViewer — virtual keyboard", () => { + it("offers one virtual keyboard for all its documents by default", () => { + cy.mount( + , + ); + + waitForDocuments(); + cy.get("#virtual-keyboard-tray").should("have.length", 1); + cy.get(".open-keyboard-button").should("have.length", 1); + }); + + it("leaves the keyboard out when addVirtualKeyboard is false", () => { + cy.mount( + , + ); + + waitForDocuments(); + cy.get("#virtual-keyboard-tray").should("not.exist"); + cy.get(".open-keyboard-button").should("not.exist"); + }); +}); From 31d3304d22634eb6d4e5a6c3b0007960bdb3641e Mon Sep 17 00:00:00 2001 From: Duane Nykamp Date: Mon, 19 Oct 2026 13:03:02 -0500 Subject: [PATCH 2/2] Load the keyboard tray's styles in the dev app and document them The keyboard tray takes its styles from @doenet/doenetml-iframe's stylesheet, which the host page has to import. Now that the keyboard is on by default, the dev app showed the tray's keys unstyled at the end of the page, since it never imported that stylesheet. Import it there, and say in the README that a host page needs it. Co-Authored-By: Claude Opus 5.5 --- README.md | 14 ++++++++++++++ dev/main.tsx | 1 + 2 files changed, 15 insertions(+) diff --git a/README.md b/README.md index e6583a4..67b5015 100644 --- a/README.md +++ b/README.md @@ -68,3 +68,17 @@ viewers still mount lazily but stay live once booted. To cut the per-document core cost further, `useSharedCoreWorker` serves all documents' cores from a shared worker pool instead of one dedicated ~100 MB worker per document (default off; see `@doenet/doenetml-iframe`). + +## Virtual keyboard + +Each document's viewer offers the Doenet virtual keyboard for its math +inputs, and all of them share one keyboard tray along the bottom of the +page. The tray's styles come from `@doenet/doenetml-iframe`, so the page +must import them once: + +```tsx +import "@doenet/doenetml-iframe/style.css"; +``` + +Without that stylesheet the tray's keys appear unstyled at the end of the +page. Pass `addVirtualKeyboard={false}` to leave the keyboard out. diff --git a/dev/main.tsx b/dev/main.tsx index 7ba47bf..c5305c6 100644 --- a/dev/main.tsx +++ b/dev/main.tsx @@ -1,5 +1,6 @@ import { StrictMode } from "react"; import { createRoot } from "react-dom/client"; +import "@doenet/doenetml-iframe/style.css"; import "./index.css"; import App from "./App";