diff --git a/packages/doenetml-worker/src/components/Paginator.js b/packages/doenetml-worker/src/components/Paginator.js index 863827b66..717d3e55c 100644 --- a/packages/doenetml-worker/src/components/Paginator.js +++ b/packages/doenetml-worker/src/components/Paginator.js @@ -180,6 +180,7 @@ export class Paginator extends BlockComponent { actionId, sourceInformation, skipRendererUpdate, + overrideReadOnly: true, event: { verb: "selected", object: { @@ -345,6 +346,76 @@ export class PaginatorControls extends BlockComponent { }, }; + // disabledDirectly for paginatorControls is not affected by the readOnly flag + // nor the parentDisabled flag + stateVariableDefinitions.disabledDirectly = { + public: true, + shadowingInstructions: { + createComponentOfType: "boolean", + }, + forRenderer: true, + hasEssential: true, + doNotShadowEssential: true, + defaultValue: false, + returnDependencies: () => ({ + disabledPreliminary: { + dependencyType: "stateVariable", + variableName: "disabledPreliminary", + variablesOptional: true, + }, + sourceCompositeDisabled: { + dependencyType: "sourceCompositeStateVariable", + variableName: "disabled", + }, + adapterSourceDisabled: { + dependencyType: "adapterSourceStateVariable", + variableName: "disabled", + }, + }), + definition({ dependencyValues, usedDefault }) { + if (!usedDefault.disabledPreliminary) { + return { + setValue: { + disabledDirectly: + dependencyValues.disabledPreliminary, + }, + }; + } + + let disabledDirectly = false; + let useEssential = true; + + if ( + dependencyValues.sourceCompositeDisabled !== null && + !usedDefault.sourceCompositeDisabled + ) { + disabledDirectly = + disabledDirectly || + dependencyValues.sourceCompositeDisabled; + useEssential = false; + } + if ( + dependencyValues.adapterSourceDisabled !== null && + !usedDefault.adapterSourceDisabled + ) { + disabledDirectly = + disabledDirectly || + dependencyValues.adapterSourceDisabled; + useEssential = false; + } + + if (useEssential) { + return { + useEssentialOrDefaultValue: { + disabledDirectly: true, + }, + }; + } else { + return { setValue: { disabledDirectly } }; + } + }, + }; + return stateVariableDefinitions; } } diff --git a/packages/doenetml/src/Viewer/renderers/paginatorControls.jsx b/packages/doenetml/src/Viewer/renderers/paginatorControls.jsx index 8926545c2..cf897ede6 100644 --- a/packages/doenetml/src/Viewer/renderers/paginatorControls.jsx +++ b/packages/doenetml/src/Viewer/renderers/paginatorControls.jsx @@ -24,7 +24,7 @@ export default React.memo(function PaginatorControls(props) { args: { number: SVs.currentPage - 1 }, }); }} - disabled={SVs.disabled || !(SVs.currentPage > 1)} + disabled={SVs.disabledDirectly || !(SVs.currentPage > 1)} value={SVs.previousLabel} /> @@ -38,7 +38,10 @@ export default React.memo(function PaginatorControls(props) { args: { number: SVs.currentPage + 1 }, }); }} - disabled={SVs.disabled || !(SVs.currentPage < SVs.numPages)} + disabled={ + SVs.disabledDirectly || + !(SVs.currentPage < SVs.numPages) + } value={SVs.nextLabel} /> diff --git a/packages/test-cypress/cypress/e2e/tagSpecific/paginator.cy.js b/packages/test-cypress/cypress/e2e/tagSpecific/paginator.cy.js index 7f15f95d8..e5eba0991 100644 --- a/packages/test-cypress/cypress/e2e/tagSpecific/paginator.cy.js +++ b/packages/test-cypress/cypress/e2e/tagSpecific/paginator.cy.js @@ -2305,8 +2305,7 @@ describe("Paginator Tag Tests", function () { cy.get(cesc2("#/ca")).should("have.text", "0.722"); }); - // Do we restore this feature? - it.skip("Paginator controls ignore read only flag", () => { + it("Paginator controls ignore read only flag", () => { let doenetML = ` a @@ -2324,11 +2323,6 @@ describe("Paginator Tag Tests", function () {

Credit achieved: $_document1.creditAchieved{assignNames="ca"}

`; - cy.get("#testRunner_toggleControls").click(); - cy.get("#testRunner_allowLocalState").click(); - cy.wait(100); - cy.get("#testRunner_toggleControls").click(); - cy.window().then(async (win) => { win.postMessage( { @@ -2356,29 +2350,26 @@ describe("Paginator Tag Tests", function () { cy.get(cesc("#\\/ti2_submit")).should("be.visible"); cy.get(cesc2("#/ca")).should("have.text", "0.5"); - // at least right now, this turns on Read Only - cy.get("h3 > button").click(); - cy.get(":nth-child(5) > label > input").click(); - cy.get("h3 > button").click(); - - cy.get(cesc("#\\/ti2_input")).should("be.disabled"); - cy.get(cesc("#\\/ti2_input")).should("have.value", "2"); - cy.get(cesc("#\\/ti2_submit")).should("be.disabled"); + cy.get("#testRunner_toggleControls").click(); + cy.get("#testRunner_readOnly").click(); + cy.wait(100); + cy.get("#testRunner_toggleControls").click(); - cy.get(cesc2("#/pcontrols_previous")).click(); cy.get(cesc2("#/_title1")).should("have.text", "Problem 1"); - cy.get(cesc2("#/ca")).should("have.text", "0.5"); cy.get(cesc("#\\/ti1_input")).should("be.disabled"); - cy.get(cesc("#\\/ti1_input")).should("have.value", "1"); + cy.get(cesc("#\\/ti1_submit")).should("be.disabled"); cy.get(cesc2("#/pcontrols_next")).click(); cy.get(cesc2("#/_title2")).should("have.text", "Problem 2"); - cy.get(cesc2("#/ca")).should("have.text", "0.5"); cy.get(cesc("#\\/ti2_input")).should("be.disabled"); - cy.get(cesc("#\\/ti2_input")).should("have.value", "2"); cy.get(cesc("#\\/ti2_submit")).should("be.disabled"); + + cy.get(cesc2("#/pcontrols_previous")).click(); + cy.get(cesc2("#/_title1")).should("have.text", "Problem 1"); + cy.get(cesc("#\\/ti1_input")).should("be.disabled"); + cy.get(cesc("#\\/ti1_submit")).should("be.disabled"); }); it("Variants stay consistent with external copies", () => {