From 116e8e7495d14d0f8be49fcba11c7d9ecb0a7985 Mon Sep 17 00:00:00 2001 From: chris <kokosias@yahoo.gr> Date: Wed, 17 May 2023 12:19:05 +0300 Subject: [PATCH] set multiple choice aria-label --- .../components/Switch.js | 6 ++++-- .../components/SwitchComponent.js | 14 +++++++++++++- .../components/YesNoSwitch.js | 3 ++- 3 files changed, 19 insertions(+), 4 deletions(-) diff --git a/wax-prosemirror-services/src/MultipleChoiceQuestionService/components/Switch.js b/wax-prosemirror-services/src/MultipleChoiceQuestionService/components/Switch.js index 1896a2913..e88b3af80 100644 --- a/wax-prosemirror-services/src/MultipleChoiceQuestionService/components/Switch.js +++ b/wax-prosemirror-services/src/MultipleChoiceQuestionService/components/Switch.js @@ -43,7 +43,9 @@ const Label = styled.label` `; const SwitchComponent = props => { - const { className, label, labelPosition, onChange, ...rest } = props; + const { className, label, labelPosition, onChange, text, ...rest } = props; + + const ariaLabel = `Is it correct ${text}`; return ( <Wrapper className={className}> @@ -53,7 +55,7 @@ const SwitchComponent = props => { </Label> )} - <Switch aria-label="Is it correct" onChange={onChange} {...rest} /> + <Switch aria-label={ariaLabel} onChange={onChange} {...rest} /> {label && labelPosition === 'right' && ( <Label labelPosition={labelPosition} onClick={onChange}> diff --git a/wax-prosemirror-services/src/MultipleChoiceQuestionService/components/SwitchComponent.js b/wax-prosemirror-services/src/MultipleChoiceQuestionService/components/SwitchComponent.js index cdf648128..5261c7e9f 100644 --- a/wax-prosemirror-services/src/MultipleChoiceQuestionService/components/SwitchComponent.js +++ b/wax-prosemirror-services/src/MultipleChoiceQuestionService/components/SwitchComponent.js @@ -6,6 +6,7 @@ const CustomSwitch = ({ node, getPos }) => { const context = useContext(WaxContext); const [checked, setChecked] = useState(false); const [checkedAnswerMode, setCheckedAnswerMode] = useState(false); + const { pmViews: { main }, } = context; @@ -45,6 +46,17 @@ const CustomSwitch = ({ node, getPos }) => { }); }; + const getUpdatedNode = () => { + let nodeFound = node; + const allNodes = getNodes(main); + allNodes.forEach(singNode => { + if (singNode.node.attrs.id === node.attrs.id) { + nodeFound = singNode; + } + }); + return nodeFound; + }; + return ( <YesNoSwitch checked={checked} @@ -52,7 +64,7 @@ const CustomSwitch = ({ node, getPos }) => { customProps={customProps} handleChange={handleChange} isEditable={isEditable} - node={node} + node={getUpdatedNode()} /> ); }; diff --git a/wax-prosemirror-services/src/MultipleChoiceQuestionService/components/YesNoSwitch.js b/wax-prosemirror-services/src/MultipleChoiceQuestionService/components/YesNoSwitch.js index 7451482d3..6d847117a 100644 --- a/wax-prosemirror-services/src/MultipleChoiceQuestionService/components/YesNoSwitch.js +++ b/wax-prosemirror-services/src/MultipleChoiceQuestionService/components/YesNoSwitch.js @@ -44,7 +44,7 @@ const StyledIconWrong = styled(Icon)` `; const YesNoSwitch = ({ customProps, - node, + node: { node }, isEditable, handleChange, checked, @@ -83,6 +83,7 @@ const YesNoSwitch = ({ label="Correct?" labelPosition="left" onChange={handleChange} + text={node.textContent} unCheckedChildren="NO" /> ); -- GitLab