Skip to content

Commit 9d14615

Browse files
Merge pull request #2096 from pie-framework/feat/PD-2452
feat(math-inline): Adjust tooltip positioning with PopperProps for enhanced accessibility, Ensure logical DOM placement and improve screen reader support PD-2452
2 parents 945172e + e212c3d commit 9d14615

2 files changed

Lines changed: 12 additions & 1 deletion

File tree

packages/math-inline/src/__tests__/main.test.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { shallowChild } from '@pie-lib/pie-toolbox/test-utils';
66
import { Feedback } from '@pie-lib/pie-toolbox/render-ui';
77
import { CorrectAnswerToggle } from '@pie-lib/pie-toolbox/correct-answer-toggle';
88
import SimpleQuestionBlock from '../simple-question-block';
9+
import { mount } from 'enzyme';
910

1011
const Mathquill = require('@pie-framework/mathquill');
1112

@@ -97,6 +98,7 @@ describe('Math-Inline Main', () => {
9798
},
9899
},
99100
showCorrect: false,
101+
tooltipContainerRef: expect.any(Object),
100102
});
101103

102104
expect(Mathquill.getInterface().registerEmbed).toHaveBeenCalled();
@@ -211,6 +213,7 @@ describe('Math-Inline Main', () => {
211213
},
212214
},
213215
showCorrect: false,
216+
tooltipContainerRef: expect.any(Object),
214217
});
215218
});
216219

@@ -237,6 +240,7 @@ describe('Math-Inline Main', () => {
237240
},
238241
},
239242
showCorrect: false,
243+
tooltipContainerRef: expect.any(Object),
240244
});
241245
});
242246

@@ -262,6 +266,7 @@ describe('Math-Inline Main', () => {
262266
},
263267
},
264268
showCorrect: false,
269+
tooltipContainerRef: expect.any(Object),
265270
});
266271

267272
const newProps = { ...defaultProps };
@@ -289,6 +294,7 @@ describe('Math-Inline Main', () => {
289294
},
290295
},
291296
showCorrect: false,
297+
tooltipContainerRef: expect.any(Object),
292298
});
293299
});
294300
});

packages/math-inline/src/main.jsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ export class Main extends React.Component {
111111
session: { ...props.session, answers },
112112
activeAnswerBlock: '',
113113
showCorrect: this.props.model.config.alwaysShowCorrect || false,
114+
tooltipContainerRef: React.createRef(),
114115
};
115116
}
116117

@@ -525,7 +526,7 @@ export class Main extends React.Component {
525526

526527
render() {
527528
const { model, classes } = this.props;
528-
const { activeAnswerBlock, showCorrect, session } = this.state;
529+
const { activeAnswerBlock, showCorrect, session, tooltipContainerRef } = this.state;
529530
const {
530531
config,
531532
correctness,
@@ -622,6 +623,7 @@ export class Main extends React.Component {
622623

623624
{responseType === ResponseTypes.advanced && (
624625
<div
626+
ref={tooltipContainerRef}
625627
className={cx(classes.expression, {
626628
[classes.incorrect]: !emptyResponse && !correct && !showCorrect,
627629
[classes.correct]: !emptyResponse && (correct || showCorrect),
@@ -639,6 +641,9 @@ export class Main extends React.Component {
639641
tooltip: classes.keypadTooltip,
640642
popper: classes.keypadTooltipPopper,
641643
}}
644+
PopperProps={{
645+
container: tooltipContainerRef?.current || undefined,
646+
}}
642647
title={Object.keys(session.answers).map(
643648
(answerId) =>
644649
(answerId === activeAnswerBlock && !(showCorrect || disabled) && (

0 commit comments

Comments
 (0)