diff --git a/src/components/InputProblem.tsx b/src/components/InputProblem.tsx index 77dc7cf2..90e3c30c 100644 --- a/src/components/InputProblem.tsx +++ b/src/components/InputProblem.tsx @@ -187,12 +187,14 @@ export const InputProblem = ({ { comparator.toLowerCase() === 'math' ? ( +
): void => { clearFeedback(); void setFieldValue('response', e.target.value) }} className={buildClassName(userResponseCorrect, inputDisabled || isSubmitting, errors.response)} /> +
) : ( { const mathfieldRef = useRef(null) + const mathKeyboardRef = useRef(null) + useEffect(() => { const mathFieldCurrent = mathfieldRef.current - if ((mathFieldCurrent === null)) { + const maybeMathKeyboard = mathKeyboardRef.current + + if ((mathFieldCurrent === null) || (maybeMathKeyboard === null)) { return } + mathFieldCurrent.mathVirtualKeyboardPolicy = 'manual' mathFieldCurrent.minFontScale = 0.7 mathFieldCurrent.addEventListener('focusin', (ev) => { + window.mathVirtualKeyboard.container = maybeMathKeyboard + const r = mathFieldCurrent.getBoundingClientRect() + maybeMathKeyboard.style.display = 'block' + const w = maybeMathKeyboard.offsetWidth + maybeMathKeyboard.style.top = `${r.bottom + 16}px` + maybeMathKeyboard.style.left = `${r.left + r.width / 2 - w / 2}px` + maybeMathKeyboard.style.height = '300px' + maybeMathKeyboard.style.width = '100%' window.mathVirtualKeyboard.show() }) - mathFieldCurrent.addEventListener('focusout', (ev) => { - window.mathVirtualKeyboard.hide() - }) + const handleFocusOut = (ev: FocusEvent): void => { + if (ev.relatedTarget === null) { + maybeMathKeyboard.style.display = 'none' + window.mathVirtualKeyboard.hide() + } + } + + mathFieldCurrent.addEventListener('focusout', handleFocusOut) }, []) useEffect(() => { @@ -65,6 +83,7 @@ export const Mathfield = ({ className, disabled, onInput }: MathfieldProps): JSX onInput={onInput} tabIndex={disabled ? '-1' : '0'} /> +
) } diff --git a/src/styles/content.scss b/src/styles/content.scss index de880ba4..2bc6289c 100644 --- a/src/styles/content.scss +++ b/src/styles/content.scss @@ -428,3 +428,8 @@ $arrow-svg: url("data:image/svg+xml,%3Csvg width='16' height='9' viewBox='0 0 16 font-weight: 700; font-size: 1.25rem; } + +.os-mathfield-container { + flex-direction: column; + width: 100%; +}