Skip to content
Snippets Groups Projects
Commit f12c9684 authored by chris's avatar chris
Browse files

multiple drop down readonly

parent 58e97d4d
No related branches found
No related tags found
1 merge request!411add readonly state to multiple choice ones
/* eslint-disable no-underscore-dangle */ /* eslint-disable no-underscore-dangle */
import React, { useContext, useMemo, useEffect, useState } from 'react'; import React, { useContext, useEffect, useMemo, useState } from 'react';
import styled from 'styled-components'; import styled from 'styled-components';
import { find } from 'lodash';
import { ReactDropDownStyles } from 'wax-prosemirror-components'; import { ReactDropDownStyles } from 'wax-prosemirror-components';
import { WaxContext } from 'wax-prosemirror-core'; import { WaxContext } from 'wax-prosemirror-core';
import { DocumentHelpers } from 'wax-prosemirror-utilities'; import { DocumentHelpers } from 'wax-prosemirror-utilities';
...@@ -51,6 +50,14 @@ const DropComponent = ({ getPos, node, options }) => { ...@@ -51,6 +50,14 @@ const DropComponent = ({ getPos, node, options }) => {
} = context; } = context;
const customProps = main.props.customValues; const customProps = main.props.customValues;
const { testMode } = customProps;
useEffect(() => {
const currentOption = node.attrs.options.filter(option => {
return option.value === node.attrs.correct;
});
if (!testMode && currentOption[0]) setSelectedOption(currentOption[0]);
}, []);
const onChange = option => { const onChange = option => {
const allNodes = getNodes(main); const allNodes = getNodes(main);
...@@ -66,12 +73,11 @@ const DropComponent = ({ getPos, node, options }) => { ...@@ -66,12 +73,11 @@ const DropComponent = ({ getPos, node, options }) => {
main.dispatch(tr); main.dispatch(tr);
}; };
useEffect(() => {}, []);
const MultipleDropDown = useMemo( const MultipleDropDown = useMemo(
() => ( () => (
<Wrapper key={uuidv4()}> <Wrapper key={uuidv4()}>
<DropdownStyled <DropdownStyled
disabled={!testMode}
key={uuidv4()} key={uuidv4()}
onChange={option => onChange(option)} onChange={option => onChange(option)}
options={options} options={options}
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment