8000 USWDS-proposals: Text input web component pre-alpha by amyleadem · Pull Request #17 · uswds/uswds-proposals · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

USWDS-proposals: Text input web component pre-alpha #17

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

Open
wants to merge 8 commits into
base: main
Choose a base branch
from

Conversation

amyleadem
Copy link
Contributor
@amyleadem amyleadem commented Nov 26, 2024

Summary

Design the code structure for the text input web component.

Related issue

Closes uswds/web-components#111

Preview link

Pre-alpha for text input

Tasks

  • Gather code samples from the landscape
  • Identify and document the component’s critical content
    • Document the component content that is critical for end-user understanding. Note: This critical content should always appear on the page, even in non-JS environments.
  • Design and document the structure for the light DOM
  • Design and document the structure for the shadow DOM
  • Design and document the expected component customization methods
    • List and define the proposed component variants
    • List and define props
    • List and define slots
    • List and define CSS Parts
    • List and define CSS Variables
    • List any component content that will need to be translated into other languages

Testing and review

  • Confirm the critical content has been appropriately identified and is included in the light DOM
  • Confirm that the light DOM design matches convention
  • Confirm that the shadow DOM design matches convention
  • Confirm that the existing variants have been accounted for
  • Confirm that the existing settings have been accounted for
  • Confirm the proposed additional variants meet the needs of users and make sense
  • Confirm the proposed additional settings/CSS custom properties meet the needs of users and make sense
  • Confirm the proposed parts are comprehensive and allow users to customize the component

@amyleadem
Copy link
Contributor Author

Next steps

  • Make hint a prop or slot or
    • Consider if hints will have rich text or escaped characters
  • Convert usa-hint to a <p>
  • Add numbers to pre-release template for easier reference
  • Consider converting to a markdown PR
  • Consider adding open questions/proposals section

@amyleadem amyleadem marked this pull request as ready for review December 13, 2024 16:19
@amyleadem amyleadem requested a review from a team as a code owner December 13, 2024 16:19
Copy link
@mejiaj mejiaj left a comment

Choose a reason for hiding this comment

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

@amyleadem I've run prettier on the markdown file (via VS Code prettier plugin) for consistent formatting.

Thanks for putting this together. The thoughts I added aren't blocking, but curious to see what you think. I also left additional comments for improvements.

| -- | Required | Add indicator that field is required | `required` prop |

> [!note]
> Textarea is currently bundled with the text input in USWDS 3. Because its html structure requires the `<textarea>` tag instead of the `<input>` tag, I propose that we create a separate custom element for `<usa-textarea>`.
Copy link

Choose a reason for hiding this comment

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

thought: Makes sense to start out separate.

> Textarea is currently bundled with the text input in USWDS 3. Because its html structure requires the `<textarea>` tag instead of the `<input>` tag, I propose that we create a separate custom element for `<usa-textarea>`.

> [!note]
> We could consider including some custom styles for common text input types, like `tel`, `email`, etc. I imagine we could add an icon prefix for these types when appropriate. However, this might be too opinionated and we can instead let users choose to add a prefix with the `prefix-icon` prop.
Copy link

Choose a reason for hiding this comment

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

thought: Beyond scope, but good to capture the enhancement nonetheless.

| Property | Description | Expected values |
| ------------- | -------------------------------- | --------------- |
| `prefix` | Add content for an input prefix | `string` |
| `prefix-icon` | Add icon for an input prefix | Name of icon |
Copy link

Choose a reason for hiding this comment

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

question: Could this be combined with suffix-icon? Not quite seeing the benefit of having them separate at the start.

If possible, we should take a light approach to the API at the start.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I am not quite understanding how that would work. Can you give me more info about what you are thinking?

I can see that it might make sense to combine prefix and prefix-icon though 🤔

Copy link

Choose a reason for hiding this comment

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

@amyleadem the icon will be the same whether we add it before/after the input. We should follow DRY principles and try to avoid duplicating the prop for the essentially the same icon.

Maybe I'm misunderstanding how the variant will be implemented. I think shoelace has a good example of this.

<!-- Icon prefix -->
<usa-text-input>
  <usa-icon name="mail_outline" slot="prefix"></usa-icon>
  <label for="input-type-text">Text input label</label>
  <input id="input-type-text" name="input-type-text" />
</usa-text-input>

<!-- Text prefix -->
<usa-text-input>
  <span slot="prefix">Email:</span>
  <label for="input-type-text">Text input label</label>
  <input id="input-type-text" name="input-type-text" />
</usa-text-input>

Comment on lines 121 to 124
| Part name | Element |
| --------- | --------- |
| `input` | `<input>` |
| `label` | `<label>` |
Copy link

Choose a reason for hiding this comment

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

issue: The input and label are light DOM elements. It doesn't seem necessary to have them as part, unless I'm misunderstanding this section.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I might be misunderstanding, but I thought we needed to make the part available in the shadow DOM in order to give users access to style it.

Copy link
@mejiaj mejiaj Feb 18, 2025

Choose a reason for hiding this comment

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

MDN link in comment says it's for styling elements in a shadow tree.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Removed the listed parts in f3270ab

Comment on lines 150 to 153
- Should textarea be its own custom element (ie, `<usa-textarea>`)?
- Should hint text be a prop or a slot?
- Is there ever a need to change the location of hint text? (maybe after the input?)
- Are input mask, character count, etc distinct custom elements? How do these components interact with this?
Copy link

Choose a reason for hiding this comment

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

polish: Numbering the questions could help clarity when addressing them.

Suggested change
- Should textarea be its own custom element (ie, `<usa-textarea>`)?
- Should hint text be a prop or a slot?
- Is there ever a need to change the location of hint text? (maybe after the input?)
- Are input mask, character count, etc distinct custom elements? How do these components interact with this?
1. Should textarea be its own custom element (ie, `<usa-textarea>`)?
2. Should hint text be a prop or a slot?
3. Is there ever a need to change the location of hint text? (maybe after the input?)
4. Are input mask, character count, etc distinct custom elements? How do these components interact with this?
  1. It makes sense. Ideally we'd extend text input, but the API seems too different. For example, we might not want textarea with icon prefix/suffixes.
  2. Probably easier for now to have hint be a prop.
  3. If it's a prop, we can control this. If we're talking multiple hints, this should be named something else or we should make hint a light DOM element.
  4. Yes, they have different API's. We'd need to extend or have distinct implementations if LOE is moderate+.

Co-authored-by: James Mejia <james.mejia@gsa.gov>
@amyleadem amyleadem requested a review from mejiaj February 14, 2025 18:13
@amyleadem
Copy link
Contributor Author

@mejiaj I addressed your comments to the best of my ability. This is ready for your re-review. Let me know if you want to talk through anything.

Copy link
@mejiaj mejiaj left a comment

Choose a reason for hiding this comment

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

@amyleadem thanks for updating. This looks good. I've added two additional clarifying comments.

We should be careful of adding too many props from the start. Especially if they're potentially duplicative.

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-Proposals - Pre-alpha: Text input
2 participants
0