Skip to content

Conversation

@mark-fitzgerald
Copy link
Contributor

@mark-fitzgerald mark-fitzgerald commented Dec 3, 2025

Summary:

When TeX is displayed in a mobile viewport, it is reduced in size so that it can be seen in its entirety. It is made "zoomable" so that a user can click the math and have it display at its normal size, and scroll to see the offscreen content. The math is initially reduced in size by calculating the available width and comparing it to the actual width of the math element.

When zoomable math is displayed within the Explanation widget, it is hidden along with the rest of the explanation content. Part of the hiding involves reducing the size of the explanation container to a width of zero. When an HTML element has a width of zero, it causes the height to be extremely tall in order to accommodate all the content within. When the zoomable math reduction is calculated in this situation, it uses this invalid height information. This PR resolve this by using more reliable height information (elements not affected by the zero-width container). It only does this adjusted calculation when one of the ancestor containers has aria-hidden="true" added (indicating that the element is hidden from view).

Issue: LEMS-3608

Test plan:

Bugfix:

  1. Open an exercise with math content within an Explanation widget (i.e. this ZND example)
  2. Reduce the viewport in some manner (either by shrinking the window to a mobile size, or emulating it in the developer window)
    • Be sure to reload the page so that the app knows that it "is mobile"
  3. Expand the widget (yes, you can click it - it won't explode)
  4. Notice that the left-side border is only as tall as the math content (not super tall)
    • The extra space between math lines is due to how mobile styling affects the math - it is not a regression

Regression test:

  1. Open an exercise with math content that is NOT in the Explanation widget (i.e. this ZND example)
  2. Make sure that the math is on its own line (no other text with it)
    • You may need to check within the editor
    • You may need to view this in the Preview tab if you end up needing to adjust the content
  3. Note that the math is reduced to fit within the window
  4. Click the math to enlarge it to full size
  5. Note that scrolling will show the full math

…ion-widget] docs(changeset): [Explanation] Bugix - Math within the widget has additional space added below it when in mobile viewport
@github-actions
Copy link
Contributor

github-actions bot commented Dec 3, 2025

🗄️ Schema Change: No Changes ✅

@github-actions
Copy link
Contributor

github-actions bot commented Dec 3, 2025

Size Change: +92 B (+0.02%)

Total Size: 499 kB

Filename Size Change
packages/perseus/dist/es/index.js 202 kB +92 B (+0.05%)
ℹ️ View Unchanged
Filename Size
packages/kas/dist/es/index.js 20.8 kB
packages/keypad-context/dist/es/index.js 1 kB
packages/kmath/dist/es/index.js 5.98 kB
packages/math-input/dist/es/index.js 99.2 kB
packages/math-input/dist/es/strings.js 1.61 kB
packages/perseus-core/dist/es/index.item-splitting.js 13.1 kB
packages/perseus-core/dist/es/index.js 22.6 kB
packages/perseus-editor/dist/es/index.js 98.2 kB
packages/perseus-linter/dist/es/index.js 8.64 kB
packages/perseus-score/dist/es/index.js 9.2 kB
packages/perseus-utils/dist/es/index.js 403 B
packages/perseus/dist/es/strings.js 7.73 kB
packages/pure-markdown/dist/es/index.js 1.39 kB
packages/simple-markdown/dist/es/index.js 6.72 kB

compressed-size-action

@github-actions
Copy link
Contributor

github-actions bot commented Dec 3, 2025

🛠️ Item Splitting: No Changes ✅

@github-actions
Copy link
Contributor

github-actions bot commented Dec 3, 2025

npm Snapshot: Published

Good news!! We've packaged up the latest commit from this PR (ec0f963) and published it to npm. You
can install it using the tag PR3084.

Example:

pnpm add @khanacademy/perseus@PR3084

If you are working in Khan Academy's frontend, you can run the below command.

./dev/tools/bump_perseus_version.ts -t PR3084

If you are working in Khan Academy's webapp, you can run the below command.

./dev/tools/bump_perseus_version.js -t PR3084

…ion-widget] Add logic to exclude invalid measurements when parent height is zero.

Add debugging statements to aid in verifying calculations.
…ion-widget] Use ancestor to determine if width is zero - parent node can still have width when hidden.
…ion-widget] Set initial state to "expanded" to test logic.
…ion-widget] Reset initial state of explanation widget.

Remove debugging messages.
…ion-widget] Add a height check on the children of the math container to ensure that we are getting the best representation of the math height.
@mark-fitzgerald mark-fitzgerald changed the title [Explanation] Bugix - Math within the widget has additional space added below it when in mobile viewport [Explanation] Bugfix - Math within the widget has additional space added below it when in mobile viewport Dec 4, 2025
…ion-widget] Add a default value for the text default height.
@mark-fitzgerald mark-fitzgerald requested a review from a team December 4, 2025 23:17
@mark-fitzgerald mark-fitzgerald marked this pull request as ready for review December 4, 2025 23:17
Copy link
Contributor

@ivyolamit ivyolamit left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mark-fitzgerald implementation looks logical to me, thanks for making this change 🎉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants