Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Numeric Input] - Show "Format Options" Tooltip as List #1861

Merged
merged 13 commits into from
Dec 3, 2024

Conversation

mark-fitzgerald
Copy link
Contributor

@mark-fitzgerald mark-fitzgerald commented Nov 14, 2024

Summary:

Upon receiving focus, the Numeric Input field will show a tooltip indicating the format of the answer that it is expecting (assuming the input was configured with suggested formats). When multiple formats are indicated, they should be displayed as a list. Currently, the formats are indeed HTML list elements, but they don't display as list items (all formatting has been removed). This change fixes the visual formatting to display the items as a list, but only if there are two or more items. In the case of just one format example, the HTML list element is removed, and the content is displayed as regular text. Also, the first line in the tooltip is more of an introductory text than a format option, and therefore should not be included in the HTML list markup.

Issue: LEMS-2457

Test plan:

NOTE: Only the HTML modifications can be testing locally (aka Storybook). The visual modifications must be verified in a ZND (or locally in Webapp containerized) because the styling that interferes with the list styling does not exist in Storybook.

Storybook:

  1. Launch Storybook
  2. Navigate to Perseus Editor => Editor => Demo
  3. Add a Numeric Input widget
  4. Configure the widget to have just one format option
    Storybook - 1 Format Option
  5. Move focus to the input field in the preview area
    • The tooltip should NOT be a list
      Storybook - 1 Format Tooltip
  6. Configure the widget to have more than one format option
    Storybook - 3 Format Option
  7. Move focus to the input field in the preview area
    • The tooltip should be a list, with the first line of text NOT in the list
      Storybook - 3 Format Tooltip

Webapp (locally or in a ZND):

  1. Log into the app with a valid account for use in editing exercises
  2. Navigate to a Numeric Input example
    • Test Everything > Unit 2 > Lesson 2: Numeric input (ZND)
  3. Edit the exercise
  4. Configure the widget to have just one format option
    Storybook - 1 Format Option
  5. Move focus to the input field in the preview area (make sure the "Desktop" preview is selected)
    • The tooltip should NOT be a list
      Webapp - 1 Format Tooltip
  6. Configure the widget to have more than one format option
    Storybook - 3 Format Option
  7. Move focus to the input field in the preview area
    • The tooltip should be a list, with the first line of text NOT in the list
      Webapp - 3 Format Tooltip

@mark-fitzgerald mark-fitzgerald self-assigned this Nov 14, 2024
Copy link
Contributor

github-actions bot commented Nov 14, 2024

npm Snapshot: Published

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

Example:

yarn add @khanacademy/perseus@PR1861

If you are working in Khan Academy's webapp, you can run:

./dev/tools/bump_perseus_version.sh -t PR1861

Copy link
Contributor

github-actions bot commented Nov 14, 2024

Size Change: +137 B (+0.01%)

Total Size: 1.29 MB

Filename Size Change
packages/perseus/dist/es/index.js 423 kB +137 B (+0.03%)
ℹ️ View Unchanged
Filename Size
packages/kas/dist/es/index.js 39 kB
packages/keypad-context/dist/es/index.js 760 B
packages/kmath/dist/es/index.js 4.27 kB
packages/math-input/dist/es/index.js 77.9 kB
packages/math-input/dist/es/strings.js 1.79 kB
packages/perseus-core/dist/es/index.js 1.48 kB
packages/perseus-editor/dist/es/index.js 697 kB
packages/perseus-linter/dist/es/index.js 22.2 kB
packages/perseus/dist/es/strings.js 3.7 kB
packages/pure-markdown/dist/es/index.js 3.66 kB
packages/simple-markdown/dist/es/index.js 12.5 kB

compressed-size-action

@mark-fitzgerald mark-fitzgerald marked this pull request as ready for review November 18, 2024 22:47
@khan-actions-bot khan-actions-bot requested a review from a team November 18, 2024 22:47
@khan-actions-bot
Copy link
Contributor

khan-actions-bot commented Nov 18, 2024

Gerald

Required Reviewers
  • @Khan/perseus for changes to .changeset/many-keys-smash.md, packages/perseus/src/components/input-with-examples.tsx, packages/perseus/src/styles/perseus-renderer.less, packages/perseus/src/__tests__/__snapshots__/server-item-renderer.test.tsx.snap, packages/perseus/src/widgets/numeric-input/numeric-input.test.ts, packages/perseus/src/multi-items/__tests__/__snapshots__/multi-renderer.test.tsx.snap, packages/perseus/src/widgets/graded-group-set/__snapshots__/graded-group-set-jipt.test.ts.snap, packages/perseus/src/widgets/graded-group-set/__snapshots__/graded-group-set.test.ts.snap, packages/perseus/src/widgets/group/__snapshots__/group.test.tsx.snap, packages/perseus/src/widgets/numeric-input/__snapshots__/numeric-input.test.ts.snap

Don't want to be involved in this pull request? Comment #removeme and we won't notify you of further changes.


// Assert
expect(renderer).toHaveBeenAnsweredIncorrectly();
});
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This isn't new. I just re-organized the tests to group them better. If the first test was "accept correct answer", I would think the next test would be "reject an incorrect answer". This also enabled me to group the snapshot tests together.

@@ -541,24 +541,20 @@
}
}

// TODO(joel) - remove?
.perseus-tooltip {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This style wasn't really used, other than to be a base later on in .perseus-formats-tooltip. So, I just moved this styling to where it is used.

padding: 5px 10px;
width: 240px;
}

// CSS is evil; let's overwrite some styles. T_T
Copy link
Contributor Author

Choose a reason for hiding this comment

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

No! CSS is not evil. Misunderstood, maybe. But definitely not evil.

margin: -20px 0 -16px 0;
> li {
list-style-type: none;
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

There's no evidence that this was ever needed. A list should (almost) always look like a list.

Copy link
Collaborator

@jeremywiebe jeremywiebe left a comment

Choose a reason for hiding this comment

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

Nice!

.map((example, index) => {
// If the first example is bold, then it is most likely a heading/leading text.
// So, it shouldn't be part of the list.
return index === 0 && example.startsWith("**")
Copy link
Collaborator

Choose a reason for hiding this comment

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

It looks like both remaining usages of <InputWithExamples /> provides an examples list where the first item is indeed a bold heading (here and here).

Perhaps we can simplify this once input-number is truly gone because at that point we'll know exactly what is always passed in.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That's the plan. We have follow-up tickets to refactor aspects of Numeric Input. Seeing as how InputWithExamples isn't used anywhere else, we are considering bringing this component into Numeric Input and simplifying the two code bases.

Copy link
Contributor

@SonicScrewdriver SonicScrewdriver left a comment

Choose a reason for hiding this comment

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

Seems straightforward - Thanks for all the cleanup work with the CSS!

Copy link
Member

@catandthemachines catandthemachines left a comment

Choose a reason for hiding this comment

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

Looks pretty good. Just curious about the data-perseus attribute.

</div>
<div
class="paragraph"
data-perseus-paragraph-index="1"
Copy link
Member

Choose a reason for hiding this comment

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

What is this data-perseus-paragraph-index attribute? Is it like our version of tabIndex?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Question has been posted to the team.

@mark-fitzgerald mark-fitzgerald merged commit 763a4ba into main Dec 3, 2024
9 checks passed
@mark-fitzgerald mark-fitzgerald deleted the LEMS-2457-show-format-options-as-list branch December 3, 2024 21:03
mark-fitzgerald pushed a commit that referenced this pull request Dec 5, 2024
This PR was opened by the [Changesets release](https://github.com/changesets/action) GitHub action. When you're ready to do a release, you can merge this and the packages will be published to npm automatically. If you're not ready to do a release yet, that's fine, whenever you add more changesets to main, this PR will be updated.

# Releases
## @khanacademy/[email protected]

### Minor Changes

-   [#1901](#1901) [`051c50cf7`](051c50c) Thanks [@Myranae](https://github.com/Myranae)! - Introduces a validation function for the number line widget (extracted from the scoring function).


-   [#1936](#1936) [`d05272661`](d052726) Thanks [@jeremywiebe](https://github.com/jeremywiebe)! - Changes the PerseusWidgetsMap to be extensible so that widgets can be registered outside of Perseus and still have full type safety.


-   [#1832](#1832) [`e3062b3c8`](e3062b3) Thanks [@mark-fitzgerald](https://github.com/mark-fitzgerald)! - [Numeric Input] - Update the UI to match Expression widget

### Patch Changes

-   [#1937](#1937) [`3cdabf1a3`](3cdabf1) Thanks [@jeremywiebe](https://github.com/jeremywiebe)! - TypeScript fixes


-   [#1948](#1948) [`e21a3a39b`](e21a3a3) Thanks [@jeremywiebe](https://github.com/jeremywiebe)! - Refactor internally used object mapping utilities to use ES6 exports


-   [#1938](#1938) [`5e8d8468b`](5e8d846) Thanks [@jeremywiebe](https://github.com/jeremywiebe)! - Type fixes


-   [#1942](#1942) [`1d2b4e7bf`](1d2b4e7) Thanks [@SonicScrewdriver](https://github.com/SonicScrewdriver)! - Ensure that zoomed-in images retain alt text


-   [#1861](#1861) [`763a4ba38`](763a4ba) Thanks [@mark-fitzgerald](https://github.com/mark-fitzgerald)! - [Numeric Input] - Show format options as a list


-   [#1947](#1947) [`b8926e38a`](b8926e3) Thanks [@jeremywiebe](https://github.com/jeremywiebe)! - Minor refactoring of ServerItemRenderer's componentDidUpdate to reduce duplication


-   [#1946](#1946) [`f35512786`](f355127) Thanks [@jeremywiebe](https://github.com/jeremywiebe)! - Refactor scoring for `group` widget to follow the same pattern as all other widgets


-   [#1891](#1891) [`ef819ea95`](ef819ea) Thanks [@mark-fitzgerald](https://github.com/mark-fitzgerald)! - [Numeric Input] - Associate format options tooltip content with input field for assistive technologies


-   [#1945](#1945) [`e69ca3146`](e69ca31) Thanks [@nishasy](https://github.com/nishasy)! - Add global styles to reflect prod styling


-   [#1923](#1923) [`be8c06c75`](be8c06c) Thanks [@benchristel](https://github.com/benchristel)! - Internal: convert backgroundImage dimensions to numbers during parsing.


-   [#1934](#1934) [`129adebef`](129adeb) Thanks [@jeremywiebe](https://github.com/jeremywiebe)! - Improve comments on some Perseus types


-   [#1924](#1924) [`2d89ef87d`](2d89ef8) Thanks [@benchristel](https://github.com/benchristel)! - Internal: add and pass regression tests for PerseusItem parser's handling of legacy data

## @khanacademy/[email protected]

### Patch Changes

-   [#1938](#1938) [`5e8d8468b`](5e8d846) Thanks [@jeremywiebe](https://github.com/jeremywiebe)! - Type fixes


-   [#1937](#1937) [`3cdabf1a3`](3cdabf1) Thanks [@jeremywiebe](https://github.com/jeremywiebe)! - Ensure links opening to style guide (Google Docs) set `rel="noreferrer"`


-   [#1946](#1946) [`f35512786`](f355127) Thanks [@jeremywiebe](https://github.com/jeremywiebe)! - Remove debugging call in GraphSettings component

-   Updated dependencies \[[`3cdabf1a3`](3cdabf1), [`e21a3a39b`](e21a3a3), [`5e8d8468b`](5e8d846), [`1d2b4e7bf`](1d2b4e7), [`763a4ba38`](763a4ba), [`b8926e38a`](b8926e3), [`f35512786`](f355127), [`ef819ea95`](ef819ea), [`e69ca3146`](e69ca31), [`be8c06c75`](be8c06c), [`051c50cf7`](051c50c), [`129adebef`](129adeb), [`d05272661`](d052726), [`2d89ef87d`](2d89ef8), [`e3062b3c8`](e3062b3)]:
    -   @khanacademy/[email protected]

Author: khan-actions-bot

Reviewers: mark-fitzgerald

Required Reviewers:

Approved By: mark-fitzgerald

Checks: ⏭️  Publish npm snapshot, ✅ Check builds for changes in size (ubuntu-latest, 20.x), ✅ Lint, Typecheck, Format, and Test (ubuntu-latest, 20.x), ✅ Cypress (ubuntu-latest, 20.x), ✅ Check for .changeset entries for all changed files (ubuntu-latest, 20.x), ✅ gerald

Pull Request URL: #1944
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants