Skip to content

Form field theming set up #2672

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

Merged
merged 26 commits into from
Jun 23, 2025
Merged

Conversation

beaesguerra
Copy link
Member

@beaesguerra beaesguerra commented Jun 17, 2025

Summary:

Prep work for applying TB theming for TextField, TextArea, and LabeledField

  • update spacing tokens to sizing
  • update use of deprecated semantic color tokens
  • use BodyText component instead of Label* components
  • use global focus styles

Also added more stories for visual regression tests. And set up testing snapshot stories for LabeledField and SearchField so that we can have less Chromatic snapshots for each story in each theme.

The next PR will set up the TB styling for these components!

Issue: WB-1864

Test plan:

  • Confirm TextField, TextArea, and LabeledField look as expected in the classic theme (everything should be the same except the focus style is updated)
    • TextArea StateSheet ?path=/story/packages-form-testing-snapshots-textarea--state-sheet-story&globals=theme:default
    • TextField StateSheet http://localhost:6061/?path=/story/packages-form-testing-snapshots-textfield--state-sheet-story&globals=theme:default
    • LabeledField http://localhost:6061/?path=/docs/packages-labeledfield--docs&globals=theme:default
  • Confirm new stories
    • TextArea Combinations ?path=/story/packages-form-testing-snapshots-textarea--combinations&globals=;theme:default
    • TextField Combinations ?path=/story/packages-form-testing-snapshots-textfield--combinations&globals=;theme:default
  • Confirm LabeledField and SearchField testing snapshots stories

Copy link

changeset-bot bot commented Jun 17, 2025

🦋 Changeset detected

Latest commit: 8992b07

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 5 packages
Name Type
@khanacademy/wonder-blocks-labeled-field Patch
@khanacademy/wonder-blocks-form Patch
@khanacademy/wonder-blocks-dropdown Patch
@khanacademy/wonder-blocks-search-field Patch
@khanacademy/wonder-blocks-birthday-picker Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Copy link
Contributor

github-actions bot commented Jun 17, 2025

Size Change: -22 B (-0.02%)

Total Size: 100 kB

Filename Size Change
packages/wonder-blocks-dropdown/dist/es/index.js 16.6 kB +2 B (+0.01%)
packages/wonder-blocks-form/dist/es/index.js 4.92 kB -20 B (-0.4%)
packages/wonder-blocks-labeled-field/dist/es/index.js 2.92 kB -4 B (-0.14%)
ℹ️ View Unchanged
Filename Size
packages/wonder-blocks-accordion/dist/es/index.js 2.99 kB
packages/wonder-blocks-announcer/dist/es/index.js 1.74 kB
packages/wonder-blocks-badge/dist/es/index.js 1.75 kB
packages/wonder-blocks-banner/dist/es/index.js 1.42 kB
packages/wonder-blocks-birthday-picker/dist/es/index.js 1.91 kB
packages/wonder-blocks-breadcrumbs/dist/es/index.js 723 B
packages/wonder-blocks-button/dist/es/index.js 4.12 kB
packages/wonder-blocks-cell/dist/es/index.js 2.06 kB
packages/wonder-blocks-clickable/dist/es/index.js 2.67 kB
packages/wonder-blocks-core/dist/es/index.js 2.48 kB
packages/wonder-blocks-data/dist/es/index.js 5.48 kB
packages/wonder-blocks-grid/dist/es/index.js 1.24 kB
packages/wonder-blocks-icon-button/dist/es/index.js 3.05 kB
packages/wonder-blocks-icon/dist/es/index.js 2.02 kB
packages/wonder-blocks-layout/dist/es/index.js 1.63 kB
packages/wonder-blocks-link/dist/es/index.js 1.64 kB
packages/wonder-blocks-modal/dist/es/index.js 4.99 kB
packages/wonder-blocks-pill/dist/es/index.js 1.31 kB
packages/wonder-blocks-popover/dist/es/index.js 4.32 kB
packages/wonder-blocks-progress-spinner/dist/es/index.js 1.48 kB
packages/wonder-blocks-search-field/dist/es/index.js 1.09 kB
packages/wonder-blocks-styles/dist/es/index.js 467 B
packages/wonder-blocks-switch/dist/es/index.js 1.55 kB
packages/wonder-blocks-tabs/dist/es/index.js 3.67 kB
packages/wonder-blocks-testing-core/dist/es/index.js 3.51 kB
packages/wonder-blocks-testing/dist/es/index.js 985 B
packages/wonder-blocks-theming/dist/es/index.js 577 B
packages/wonder-blocks-timing/dist/es/index.js 1.37 kB
packages/wonder-blocks-tokens/dist/es/index.js 4.84 kB
packages/wonder-blocks-toolbar/dist/es/index.js 900 B
packages/wonder-blocks-tooltip/dist/es/index.js 6.42 kB
packages/wonder-blocks-typography/dist/es/index.js 1.15 kB

compressed-size-action

…e, sizing token usage, and use global focus styles for TextField and TextArea
Copy link
Contributor

github-actions bot commented Jun 17, 2025

A new build was pushed to Chromatic! 🚀

https://5e1bf4b385e3fb0020b7073c-mjdyoddrji.chromatic.com/

Chromatic results:

Metric Total
Captured snapshots 4
Tests with visual changes 11
Total stories 630
Inherited (not captured) snapshots [TurboSnap] 398
Tests on the build 402

export const Combinations: Story = {
render: (args) => {
return (
<AllVariants
Copy link
Member Author

Choose a reason for hiding this comment

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

Creating a new story for testing the component with a value and placeholder in different states. We don't include this in the StateSheet because it's unnecessary to see these things with all the different pseudo states (it's enough to show these cases at rest!)

Comment on lines +50 to +51
name: "Readonly",
props: {readOnly: true},
Copy link
Member Author

Choose a reason for hiding this comment

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

Adding readonly since we have TB designs for the readonly state!

// This minHeight is equivalent to when the textarea has one row
minHeight: `calc(${VERTICAL_SPACING_PX * 2 + 2}px + ${font.lineHeight.medium})`,
minHeight: `calc(${VERTICAL_SPACING} * 2 + ${sizing.size_020} + ${font.lineHeight.medium})`,
...focusStyles.focus,
},
default: {
background: semanticColor.input.default.background,
Copy link
Member Author

Choose a reason for hiding this comment

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

We continue to use the semanticColor.input tokens. In the next PR where I work on adding the TB theme, I'll see if we need to make any changes to the shared input tokens!

@@ -727,6 +727,7 @@ const styles = StyleSheet.create({
borderRadius: border.radius.radius_040,
border: `solid 1px ${theme.combobox.color.default.border}`,
paddingInline: spacing.xSmall_8,
overflow: "hidden",
Copy link
Member Author

Choose a reason for hiding this comment

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

This addresses an issue where the TextField was overlapping the combobox wrapper
image

Copy link
Member

Choose a reason for hiding this comment

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

oh thanks!

@beaesguerra beaesguerra marked this pull request as ready for review June 18, 2025 22:35
@khan-actions-bot
Copy link
Contributor

khan-actions-bot commented Jun 18, 2025

Gerald

Required Reviewers
  • @Khan/wonder-blocks for changes to .changeset/eleven-pianos-chew.md, .changeset/flat-needles-sort.md, .changeset/tiny-bottles-beam.md, __docs__/components/scenarios-layout.tsx, __docs__/wonder-blocks-form/text-area-testing-snapshots.stories.tsx, __docs__/wonder-blocks-form/text-field-testing-snapshots.stories.tsx, __docs__/wonder-blocks-labeled-field/labeled-field-testing-snapshots.stories.tsx, __docs__/wonder-blocks-labeled-field/labeled-field.stories.tsx, __docs__/wonder-blocks-search-field/search-field-testing-snapshots.stories.tsx, packages/wonder-blocks-dropdown/src/components/combobox.tsx, packages/wonder-blocks-form/src/components/text-area.tsx, packages/wonder-blocks-form/src/components/text-field.tsx, packages/wonder-blocks-labeled-field/src/components/labeled-field.tsx

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

@khan-actions-bot khan-actions-bot requested a review from a team June 18, 2025 22:35
Copy link
Contributor

github-actions bot commented Jun 18, 2025

npm Snapshot: Published

🎉 Good news!! We've packaged up the latest commit from this PR (9090a71) and published all packages with changesets to npm.

You can install the packages in frontend by running:

./dev/tools/deploy_wonder_blocks.js --tag="PR2672"

Packages can also be installed manually by running:

pnpm add @khanacademy/wonder-blocks-<package-name>@PR2672

Copy link
Member

@jandrade jandrade left a comment

Choose a reason for hiding this comment

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

Code changes look great! Just want to get your thoughts on Storybook/Chromatic before approving there.

@@ -727,6 +727,7 @@ const styles = StyleSheet.create({
borderRadius: border.radius.radius_040,
border: `solid 1px ${theme.combobox.color.default.border}`,
paddingInline: spacing.xSmall_8,
overflow: "hidden",
Copy link
Member

Choose a reason for hiding this comment

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

oh thanks!

Comment on lines -334 to -343
defaultFocus: {
// TODO(WB-1864): Use focusStyles.focus
":focus-visible": {
borderColor: semanticColor.focus.outer,
outline: `${border.width.thin} solid ${semanticColor.focus.outer}`,
// Negative outline offset so it focus outline is not cropped off if
// an ancestor element has overflow: hidden
outlineOffset: -2,
},
},
Copy link
Member

Choose a reason for hiding this comment

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

praise: Awesome, thanks for the cleanup!

Comment on lines 55 to 60
chromatic: {
modes: {
default: allModes.themeDefault,
thunderblocks: allModes.themeThunderBlocks,
},
},
Copy link
Member

Choose a reason for hiding this comment

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

thought: I also mentioned this in Chromatic. Would it make sense to refactor this to use StateSheet. I'm seeing that we are going to x2 the stories here, and I'm wondering if there's space to optimize for that.

Copy link
Member Author

Choose a reason for hiding this comment

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

I reduced the number of snapshots we had for LabeledField and SearchField by combining and simplifying stories. Let me know what you think!

@beaesguerra beaesguerra requested a review from jandrade June 19, 2025 22:28
Copy link
Member

@jandrade jandrade left a comment

Choose a reason for hiding this comment

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

Looks great! thanks for combining the stories. :shipit:

@beaesguerra beaesguerra merged commit 6b05521 into feature/field-theming Jun 23, 2025
14 checks passed
@beaesguerra beaesguerra deleted the text-input-fields branch June 23, 2025 20:30
Copy link

codecov bot commented Jun 23, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 0.00%. Comparing base (65fecdb) to head (8992b07).
Report is 1 commits behind head on feature/field-theming.

Additional details and impacted files

Impacted file tree graph

@@              Coverage Diff              @@
##   feature/field-theming   #2672   +/-   ##
=============================================
=============================================

Continue to review full report in Codecov by Sentry.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 65fecdb...8992b07. Read the comment docs.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

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