Skip to content

USWDS - Text Input: Include width variant styles in usa-input package#5935

Closed
aduth wants to merge 2 commits into
uswds:developfrom
aduth:aduth-input-width
Closed

USWDS - Text Input: Include width variant styles in usa-input package#5935
aduth wants to merge 2 commits into
uswds:developfrom
aduth:aduth-input-width

Conversation

@aduth

@aduth aduth commented May 21, 2024

Copy link
Copy Markdown
Contributor

Summary

Add missing styles for Text Input component when using optimized installation. Width variants for the Text Input component were previously not included when using the usa-input Sass package.

Breaking change

This would only theoretically be a breaking change if someone was importing usa-form and not usa-input, yet expected to be able to use usa-input--[width] classes. This seems exceedingly unlikely, since if someone is using usa-input--[width] classes, presumably they're also using usa-input classes.

Related issue

Fixes #5312

Problem statement

As a developer, I expect that if I include the package listed on a component's documentation (e.g. Text Input), all of the usage options documented for that component are available, so that I'm not confused by styles not existing despite being documented, or be forced to include more packages than I'd otherwise need for my optimized installation.

Solution

Moves usa-input--[width] styles from usa-form to usa-input package.

@aduth

aduth commented May 30, 2024

Copy link
Copy Markdown
Contributor Author

As a developer, I expect that if I include the package listed on a component's documentation (e.g. Text Input), all of the usage options documented for that component are available, so that I'm not confused by styles not existing despite being documented, or be forced to include more packages than I'd otherwise need for my optimized installation.

As a real-world use-case, we don't include usa-form styles in our project, because we find that they're too opinionated (specifically the unconfigurable max-width styling), but we had a need for width-constrained inputs and use usa-input styles. We were surprised and confused that the styles weren't being applied as expected, and it took a non-insignificant amount of debugging to figure out what was going on. Eventually we decided to implement ad-hoc styles for a width-constrained input, which isn't ideal.

Writing out this use-case also has me thinking that there's room to improve usa-form to either make it less opinionated or at least more configurable, so that we would feel more comfortable using those styles.

@amyleadem amyleadem added Needs: Discussion Need to discuss best approach to this issue and removed Needs: Discussion Need to discuss best approach to this issue labels Oct 22, 2024
@amyleadem amyleadem self-requested a review November 19, 2024 14:48

@amyleadem amyleadem left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks for this submission, @aduth. This is generally looking good, but I noticed one issue where these width classes no longer work when used inside a .usa-form parent. I've added details in the comment below.

I checked the following items:

  • Confirm that the approach to move .usa-input--[width] classes to the usa-input package makes sense
  • Confirm the usa-input--[width] classes work as expected on usa-input and usa-textarea elements when the usa-form package is not present
  • Confirm that this change to usa-input--[width] classes does not negatively impact other components when usa-form package is not present
    • Note: I tested adding usa-input—[width] classes to the form input components in develop. Below I have listed the components that did successfully receive the usa-input--[width] classes in develop and confirmed that they still work in this branch when the usa-form package is absent:
      • Character count
      • Input mask
      • Input prefix/suffix
      • Input
      • Textarea
  • Confirm no regressions when using .usa-input--[width] classes on .usa-input and .usa-textarea elements placed inside a.usa-form parent
    • See details in the comment below
  • Confirm that the sizes for the usa-input--[width] classes match the sizes in usa-form.scss

Please let me know if you have any questions.

Comment on lines +27 to +56

.usa-input--2xs {
max-width: 5ex;
}

.usa-input--xs {
max-width: 9ex;
}

.usa-input--sm,
.usa-input--small {
max-width: 13ex;
}

.usa-input--md,
.usa-input--medium {
max-width: 20ex;
}

.usa-input--lg {
max-width: 30ex;
}

.usa-input--xl {
max-width: 40ex;
}

.usa-input--2xl {
max-width: 50ex;
}

@amyleadem amyleadem Nov 21, 2024

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

issue: I noticed that these rules are not specific enough to work when added to an element inside of usa-form. Here is an example of markup that does not successfully accept the width classes:

<div class="usa-form">
	<label class="usa-label" for="input-type-text">Text input label</label>  
	<input class="usa-input usa-input--sm" id="input-type-text" name="input-type-text" type="text">  
	<label class="usa-label" for="input-type-textarea">Text area label</label>  
	<textarea class="usa-textarea usa-input--sm" id="input-type-textarea" name="input-type-textarea"></textarea>
</div>

This is because there is a more specific max-width rule for .usa-input that overrides it.

image

@aduth

aduth commented Nov 22, 2024

Copy link
Copy Markdown
Contributor Author

That's a good catch @amyleadem ! I'll plan to patch that up.

@aduth

aduth commented Nov 22, 2024

Copy link
Copy Markdown
Contributor Author

Maybe it's a matter of keeping the current styling (reverting the changes to _usa-form.scss), even if it's duplicated. Or maybe we could extract this to a mixin/placeholder for input widths and use it in both places to avoid the duplication. Or a :not qualifier on the styles you linked to avoid applying max-width: none to classes with specified widths.

@amyleadem

Copy link
Copy Markdown
Contributor

Closing this PR in favor of #6232.

Thanks for your work on this @aduth. If you have a moment, we'd appreciate it if you could take a look at PR #6232 to make sure the solution will still work for you.

@amyleadem amyleadem closed this Dec 4, 2024
@aduth aduth deleted the aduth-input-width branch December 5, 2024 13:45
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.

USWDS - Feature: Move usa-input--[width] classes to the usa-input module

2 participants