-
Notifications
You must be signed in to change notification settings - Fork 616
Text Input enhancements #1661
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
Text Input enhancements #1661
Conversation
🦋 Changeset detectedLatest commit: 34a05fa The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
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 |
size-limit report 📦
|
src/TextInput.tsx
Outdated
// deprecate icon prop | ||
icon?: React.ComponentType<{className?: string}> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think using a JSDoc comment here will give us some nice in-editor warnings for free.
// deprecate icon prop | |
icon?: React.ComponentType<{className?: string}> | |
/** @deprecated Use `leadingIcon` prop instead */ | |
icon?: React.ComponentType<{className?: string}> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice will do that!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What do you think of having a composable API for leading and trailing visuals similar to action list? Maybe something like this:
<InputGroup>
<InputGroup.LeadingVisual><SearchIcon /></InputGroup.LeadingVisual>
<TextInput placeholder="Search" />
</InputGroup>
This is similar to Chakra UI's API: https://chakra-ui.com/docs/form/input#add-elements-inside-input
cc @siddharthkp
Yep! Definitely looks like the composite component is our way forward seeing all the other component implementations too. My only qualm is that it gets verbose when composed at higher levels. If its a pattern we'll follow then our users should probably get used to it. |
5985748
to
971850d
Compare
What's the benefit of using that API here?
I agree with @pksjce here, the additional verbosity doesn't seem to give us any benefits here. I don't think composite/compound components should not be our go-to API choice. They are useful when we're composing application components within primer components with. In TextInput, we tightly control "how" the Icon renders (size, color, spacing, etc) so |
src/TextInput.tsx
Outdated
icon?: React.ComponentType<{className?: string}> | ||
leadingIcon?: React.ComponentType<{className?: string}> | ||
trailingIcon?: React.ComponentType<{className?: string}> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same feedback as the leading icon, but I think it's even more likely we'll use this space for things besides icons. Here's an example from Codespaces settings where we're using this space to show a "minutes" unit:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will update to trailingVisual property for the first comment.
Yes, I see in this
from https://github.com/github/primer/issues/156
I was wondering if your work in https://github.com/primer/react/pull/1611/files would cover TextInput with actions. I'm still reviewing your PR to find that out.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, my work in #1611 doesn't touch anything inside the inputs. It just handles the layout and passing the correct attributes for screenreader accessibility (e.g.: matching the label's for
attribute to the input's id
attribute)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmmm then I think we should discuss this in a separate PR. It's common to have trailingVisual
and trailingAction
in our components. Possibly we can think of adding trailingAction
onto the TextInput?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm happy with addressing this in a separate PR. Agreed - trailingAction
should be on the TextInput
src/TextInput.tsx
Outdated
contrast={contrast} | ||
disabled={disabled} | ||
hasIcon={!!IconComponent} | ||
hasIcon={!!IconComponent || !!(LeadingIconComponent || TrailingIconComponent)} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Non-blocking nitpick: I prefer Boolean(isTruthy)
over !!isTruthy
just because I find it more readable.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed this check. It was not required after all
@@ -25,45 +43,50 @@ type StyledWrapperProps = { | |||
hasIcon?: boolean | |||
block?: boolean | |||
contrast?: boolean | |||
validationStatus?: 'error' | 'warning' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Heads up: I defined this as a type in utils/types in one of my PRs: https://github.com/primer/react/pull/1611/files#diff-410797b1c4259d74820358a792a62f83cfc7a1c0a0eb26226c89e4621b88d42cR1
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I didn't include 'warning'
because I couldn't figure out where we use it, but I'm fine with keeping it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does that mean I have to handle success
case in TextInput
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Isn't it unnecessary for me to use that type then since it has success
in it too.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Correct :)
src/_TextInputWrapper.tsx
Outdated
background-repeat: no-repeat; // Repeat and position set for form states (success, error, etc) | ||
background-position: right 8px center; // For form validation. This keeps images 8px from right and centered vertically. | ||
border: 1px solid ${get('colors.border.default')}; | ||
border-radius: ${get('radii.2')}; | ||
outline: none; | ||
box-shadow: ${get('shadows.primer.shadow.inset')}; | ||
cursor: text; | ||
padding: 6px 12px; | ||
display: grid; | ||
grid-template-areas: 'leadingIcon input trailingIcon'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Adding
grid-template-columns: auto 1fr auto;
justify-items: end;
seems to help. WDYT?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks like the text input is getting sized with auto
when it's the first child. We might need to change the grid-template-columns
based on what children are there.
leadingVisual
+ input + trailingVisual
grid-template-columns: auto 1fr auto;
leadingVisual
+ input
grid-template-columns: auto 1fr;
input + trailingVisual
grid-template-columns: 1fr auto;
input
grid-template-columns: 1fr;
or
grid-template-columns: unset;
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was hoping grid would have some fancy way of handling this without having to specify different column templates for each case, but I couldn't figure it out :(
Maybe another reviewer will know?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Or maybe we could just use flexbox instead of grid? Is there something we need from grid that can't be done with flexbox?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah I'm not particularly attached to the grid way. Do you want to pair on this for a bit tomorrow?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sounds great! I love a CSS pairing sesh :)
971850d
to
a3b0824
Compare
src/_TextInputWrapper.tsx
Outdated
background-repeat: no-repeat; // Repeat and position set for form states (success, error, etc) | ||
background-position: right 8px center; // For form validation. This keeps images 8px from right and centered vertically. | ||
border: 1px solid ${get('colors.border.default')}; | ||
border-radius: ${get('radii.2')}; | ||
outline: none; | ||
box-shadow: ${get('shadows.primer.shadow.inset')}; | ||
cursor: text; | ||
padding: 6px 12px; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, because this padding is being set in the wrapper, and not in the <input>
itself, the surroundings of the input element aren't interactive.
Screen.Recording.2021-12-06.at.15.27.53.mov
We should make sure the <input>
area covers as much room as possible (saving for leading and trailing elements) within the wrapper.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is great feedback! Had not considered the area covered by the input
. Fixing this right away.
Edit - Looking more deeply into this, the wrapper is the same as the one used in TextInputWithTokens
. The height on that component is a minimum of 34px
and the padding is the same as this component. Do you have similar feedback on that component as well? Or should i work on having independent logic and not reuse whats been done there?
https://primer.style/react/storybook?path=/story/forms-text-input-with-tokens--default
cc - @mperrotti
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The height on that component is a minimum of 34px and the padding is the same as this component.
We should probably fix it in there too. We should make sure the form components match sizes with buttons at a 32px height for the default size variant. c/c @mperrotti
🙇
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@vdepizzol - I'm going to take care of this in a follow-up PR. It's not a trivial amount of work to add to these changes.
Edit: this was actually much simpler than I was expecting, so I added the changes in this PR.
cc @pksjce
40bfb3e
to
bfead25
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Everything is looking good! After @pksjce and I pair on the layout of the leading/trailing visuals and the input, this should be ready to merge.
c59e741
to
51c7fbf
Compare
e882130
to
187d441
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add a changeset, and then it's good to go!
d1a7b0e
to
c959444
Compare
9ca2335
to
b179fad
Compare
2. Change grid logic 3. Update stories and docs
a1906bb
to
b6f2f6c
Compare
* Enhance text input component * Add tests * Fix up review comments * 1. Add leading and trailing visual 2. Change grid logic 3. Update stories and docs * Fix up documentation * Update documentation and css layout * fixes text input height and padding * fixes spacing with leading and trailing visuals * Lint issues * Create clever-shrimps-search.md Co-authored-by: Mike Perrotti <mperrotti@github.com>
Describe your changes here.
Closes # https://github.com/github/primer/issues/501
Screenshots
Some additions
Error condition

Warning condition

Trailing Icon

Merge checklist
Take a look at the What we look for in reviews section of the contributing guidelines for more information on how we review PRs.