Skip to content

feat(textfield, textarea): migrate to spectrum 2 #2856

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

Conversation

rise-erpelding
Copy link
Collaborator

@rise-erpelding rise-erpelding commented Jun 21, 2024

Description (updated as of 2/25/25!)

CSS-767
CSS-768

This work migrates the Textfield and Textarea components to Spectrum 2 - these components share many tokens. Earlier iterations of this PR did incorporate changes to both components, but they've since been split into two separate (but tightly coupled) components which necessitated cards for each component's migration. Thus, this work includes migration work for Textfield and for Textarea.

Migration Work

  • [NEW 2/25] min-width for textfield is now using the multiplier token as a multiplier (multiplier times component height), resulting in min-width having a unit value (rather than a unitless value).
  • [NEW 2/25] focus hover borders for default and invalid textfield inputs match the spec
  • Medium sizing is now the default
  • The textfield component was checked against the tokens design spec and any discrepancies were adjusted
  • Textarea tokens also updated to match spec
    • Note that there are some tokens that currently have different values than what is seen in Figma, this is (for the moment) intentional - see notes in Figma
  • New tokens added to match design spec
  • Quiet variant removed

Fixes

  • [NEW 2/25] Fixes disabled readonly text color where it was not displaying as disabled color
  • [NEW 2/25] Character count uses --spectrum-textfield-font-<prop> custom properties instead of its own custom properties
  • [NEW 2/25] ::after focus indicator styles removed
  • Makes text field keyboard focusable where it was not before
  • Improves the disabled state in WHCM to look different from default state
  • Reorders and reorganizes custom properties

Storybook Updates

  • [NEW 2/25] Adds a variety of new tests and removes redundant test cases where possible
  • [NEW 2/25] Updates existing tests to use more realistic example copy (in line with this guidance) and text that matches guidelines
  • [NEW 2/25] Adds new control for hovered state, and adds description to required control
  • [NEW 2/25] Adds Placeholder story to highlight that we shouldn't use the placeholder
  • [NEW 2/25] Adds Required stories to textfield and textarea, supporting the ability (at least in docs) to set required attribute with asterisk or with "(required)" hint text in label
  • [NEW 2/25] Uses S2 icons and sets checkmark size in template (also set in CSS)
  • Removes the quiet variant from Storybook docs and tests

How and where has this been tested?

Please tag yourself on the tests you've marked complete to confirm the tests have been run by someone other than the author.

Validation steps (updated as of February 25, 2025)

Check the Storybook deployment preview for textfield or check the branch out locally:

@jawinn

  • Quiet variant should be removed, no references to it in tests, documentation, or CSS
  • Component matches design spec for textfield
  • Component matches design spec for textarea
  • CJK styles are applied and appear to match tokens spec
  • Storybook documentation is up to date
  • Storybook tests appear to be accurate and provide good coverage of the component and its states and variants
  • Test headings match what's being tested
  • Storybook component controls work and allow all variants and states
  • Windows High Contrast Mode looks as expected especially compared to colors on main
  • Fixes and new CSS changes are fixed:
    • Disabled readonly text color is always disabled color
    • Min-width textfield matches design spec/results in a reasonable number with a unit
    • Focus hover borders for default and invalid textfield inputs match the spec (and hopefully are concise--would feedback if anyone has any), I did set the focus-hover mods in development since the spec'd color differences are really subtle

Regression testing

Validate:

  1. The documentation pages for at least two other components are still loading, including:
  • The pages render correctly, are accessible, and are responsive.

Screenshots

Before S2 migration:
image

After S2 migration (updated 7/22/24):
image

To-do list

  • I have read the contribution guidelines.
  • I have updated relevant storybook stories and templates.
  • I have tested these changes in Windows High Contrast mode.
  • If my change impacts other components, I have tested to make sure they don't break.
  • If my change impacts documentation, I have updated the documentation accordingly.
  • Updated S2 Icons have been added
  • Design review/approval
  • Code review/approval
  • ✨ This pull request is ready to merge. ✨

@rise-erpelding rise-erpelding added the wip This is a work in progress, don't judge. label Jun 21, 2024
Copy link

changeset-bot bot commented Jun 21, 2024

🦋 Changeset detected

Latest commit: dcc9e1a

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

This PR includes changesets to release 1 package
Name Type
@spectrum-css/textfield Major

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

@rise-erpelding rise-erpelding added skip_vrt Add to a PR to skip running VRT (but still pass the action) S2 Spectrum 2 labels Jun 21, 2024
Copy link
Contributor

github-actions bot commented Jun 21, 2024

🚀 Deployed on https://pr-2856--spectrum-css.netlify.app

Copy link
Contributor

github-actions bot commented Jun 21, 2024

File metrics

Summary

Total size: 1.37 MB*

Package Size Minified Gzipped
textfield 31.83 KB 30.42 KB 3.60 KB

textfield

Filename Head Minified Gzipped Compared to base
index.css 31.83 KB 30.42 KB 3.60 KB 🟢 ⬇ 0.64 KB
metadata.json 17.01 KB - - 🔴 ⬆ 0.06 KB
* Size is the sum of all main files for packages in the library.
* An ASCII character in UTF-8 is 8 bits or 1 byte.

@rise-erpelding rise-erpelding force-pushed the rise-erpelding/css-767-textfield-s2-migration branch 2 times, most recently from 6b9897f to a275b4b Compare June 24, 2024 21:29
@rise-erpelding rise-erpelding force-pushed the rise-erpelding/css-767-textfield-s2-migration branch from a275b4b to 74ee789 Compare July 1, 2024 23:05
@rise-erpelding rise-erpelding force-pushed the rise-erpelding/css-767-textfield-s2-migration branch 3 times, most recently from 6787366 to 0ae0bcb Compare July 5, 2024 18:15
@rise-erpelding rise-erpelding force-pushed the rise-erpelding/css-767-textfield-s2-migration branch 4 times, most recently from ef18f8a to 644cb46 Compare July 8, 2024 15:40
@rise-erpelding rise-erpelding force-pushed the rise-erpelding/css-767-textfield-s2-migration branch 2 times, most recently from a19f685 to 69230b0 Compare July 9, 2024 20:19
@@ -410,7 +410,8 @@ governing permissions and limitations under the License.
}

/* keyboard focus */
.is-keyboardFocused & {
.is-keyboardFocused &,
&:focus-visible {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The way textfield was before, it didn't have that nice focus outline when you keyboard focus, and that didn't seem quite right.


.is-disabled &,
.is-disabled:hover & {
color: var(--highcontrast-textfield-text-color-disabled, var(--mod-textfield-text-color-disabled, var(--spectrum-textfield-text-color-disabled)));
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Ensures we get a disabled color for placeholder text if both disabled and read-only are on

@rise-erpelding rise-erpelding added ready-for-review and removed wip This is a work in progress, don't judge. labels Jul 9, 2024
@rise-erpelding rise-erpelding marked this pull request as ready for review July 9, 2024 20:27
Copy link
Collaborator

@marissahuysentruyt marissahuysentruyt left a comment

Choose a reason for hiding this comment

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

Phew, that was a big one!! I found some places where you're pointing to the correct token, but it seems like the value might be off (which you already mentioned). Maybe once another round of tokens gets released, some of those will take care of themselves.

I did find a weird custom property that I would want to see if you were getting too. Some --system prefixed properties are overriding the correct --spectrum properties, but I don't know where those are coming from.

Other than that, I found a couple of small things! Excellent work!

@rise-erpelding rise-erpelding force-pushed the rise-erpelding/css-767-textfield-s2-migration branch from ca87f08 to 5d0c8e0 Compare March 28, 2025 11:34
Comment on lines 619 to 629
&,
.spectrum-Textfield-input::placeholder {
--highcontrast-textfield-text-color-valid: CanvasText;
--highcontrast-textfield-text-color-invalid: CanvasText;
--highcontrast-textfield-text-color-default: CanvasText;
--highcontrast-textfield-text-color-hover: CanvasText;
--highcontrast-textfield-text-color-focus: CanvasText;
--highcontrast-textfield-text-color-focus-hover: CanvasText;
--highcontrast-textfield-text-color-keyboard-focus: CanvasText;
--highcontrast-textfield-text-color-disabled: GrayText;
--highcontrast-textfield-text-color-readonly: CanvasText;
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Consolidating because placeholder and input value styles should be the same

@@ -345,11 +345,15 @@
grid-row: 2;
grid-column: 1 / span 2;

/* prevents unexpected color changes for border in high contrast mode */
forced-color-adjust: none;
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Forces the input to use the styles from CSS and not the default, so that we won't get that border flash. But since WHCM is now relying on the styles set for the input, we have to set the highcontrast background color or it turns white in WHCM.

@@ -76,6 +86,8 @@
--spectrum-textfield-text-color-readonly: var(--spectrum-neutral-content-color-default);

/* Disabled Colors */
--spectrum-textfield-background-color-disabled: var(--highcontrast-textfield-background-color-disabled, var(--mod-textfield-background-color-disabled, var(--spectrum-gray-25)));
--spectrum-textfield-border-color-disabled: var(--highcontrast-textfield-border-color-disabled, var(--mod-textfield-border-color-disabled, var(--spectrum-disabled-border-color)));
Copy link
Collaborator

Choose a reason for hiding this comment

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

So this disabled border color set according to the specs, but I think the read-only styles are overriding it somewhere. When I toggle the disabled control, the entire textfield disappears.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Screen.Recording.2025-03-28.at.10.16.43.AM.mov

Comment on lines 461 to 462
.spectrum-Textfield.is-invalid:hover:not(.is-disabled) &,
.spectrum-Textfield.is-invalid &:hover:not(.is-disabled) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Now that we have the is-hover class, do we need to add that selector here at all? Invalid + Disabled + hover looks right on the Chromatic tests, but then if I actually hover over it with a cursor, I get the border color to change.

Or maybe it just needed to change a bit: .spectrum-Textfield.is-invalid:not(.is-disabled)&:hover? I might not be in the selector...

Copy link
Collaborator

Choose a reason for hiding this comment

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

Screen.Recording.2025-03-31.at.2.42.28.PM.mov

Copy link
Collaborator

Choose a reason for hiding this comment

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

@rise-erpelding I noticed a similar thing with the invalid+disabled+otherStates. When I toggled random controls, I happened to notice the first one, and then dug some more (with the controls and the keyboard). I'm decently confident that your CSS is right, and that this is just a side effect of/issue with storybook controls, so feel free to disregard! I'm going to approve anyways, since I can't actually recreate them outside of the storybook controls 🤞

Invalid+Disabled+Focus (I think this might just be a storybook only thing- I can't actually click or tab to this)
Screenshot 2025-04-01 at 2 23 29 PM

Invalid+Disabled+KeyboardFocus (same here- I think this is just storybook-only, where the controls create something that doesn't actually trigger/happen with a mouse/keyboard)
Screenshot 2025-04-01 at 2 16 25 PM

Invalid+Disabled or Readonly+FocusHover or KeyboardFocus (same with these)
Screenshot 2025-04-01 at 2 12 07 PM
Screenshot 2025-04-01 at 2 20 30 PM

- Fixes a regression caused when generic selectors like `.is-invalid`
were scoped to `.spectrum-Textfield`.
- Throws in an additional removal of a readonly & disabled :hover
selector that appeared to be unnecessary.
@rise-erpelding rise-erpelding force-pushed the rise-erpelding/css-767-textfield-s2-migration branch from 13969cf to dcc9e1a Compare April 1, 2025 14:30
Copy link
Collaborator

@marissahuysentruyt marissahuysentruyt left a comment

Choose a reason for hiding this comment

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

thumbs-up-good-job

Thanks for sticking with this one! Let's get it merged!

@rise-erpelding rise-erpelding merged commit 19ca328 into spectrum-two Apr 1, 2025
12 checks passed
@rise-erpelding rise-erpelding deleted the rise-erpelding/css-767-textfield-s2-migration branch April 1, 2025 20:29
@github-actions github-actions bot mentioned this pull request Apr 1, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ready-for-review S2 Spectrum 2 skip_vrt Add to a PR to skip running VRT (but still pass the action)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants