Uh oh!
There was an error while loading. Please reload this page.
Add trailingAction to TextInput - #1947
Conversation
Co-authored-by: Pavithra Kodmad <pksjce@github.com>
… into mp/text-input-loading-state
🦋 Changeset detectedLatest commit: e73b569 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 |
mperrotti
commented
Mar 10, 2022
#1920 should merge before this |
| // TODO: figure out how to type a themed CSS function (e.g.: css`color: blue;`) | ||
| // eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
| const renderFocusStyles = (hasActions: boolean, isInputFocused: boolean, focusStyles: any) => { |
There was a problem hiding this comment.
Help wanted: what's a good way to write the correct type for the result of a themed CSS function? For example: (e.g.: css`color: blue;`)
| <TextInput | ||
| trailingAction={ | ||
| <TextInput.Action | ||
| onClick={() => { | ||
| alert('clear input') | ||
| }} | ||
| icon={XIcon} | ||
| iconLabel="Clear input" | ||
| sx={{color: 'fg.subtle'}} | ||
| /> | ||
| } | ||
| /> |
There was a problem hiding this comment.
I'm not super confident about this but what do you think about an API like this:
| <TextInput | |
| trailingAction={ | |
| <TextInput.Action | |
| onClick={() => { | |
| alert('clear input') | |
| }} | |
| icon={XIcon} | |
| iconLabel="Clear input" | |
| sx={{color: 'fg.subtle'}} | |
| /> | |
| } | |
| /> | |
| <TextInput> | |
| <TextInput.TrailingAction | |
| onClick={() => { | |
| alert('clear input') | |
| }} | |
| icon={XIcon} | |
| iconLabel="Clear input" | |
| sx={{color: 'fg.subtle'}} | |
| /> | |
| </TextInput> |
cc @siddharthkp
There was a problem hiding this comment.
Oh yeah! Me and @mperrotti went through a bunch of options and this was one of them!
What I like:
- It makes TextInput feel like a compound component and then putting children inside could makes sense
What I don't like:
- Doesn't match the prop for trailingVisual (we could move that inside as well along with leadingVisual)
- It's not intuitive to put contents inside a TextInput because input can't have children, it's hard to predict what the output of this would be.
There was a problem hiding this comment.
@siddharthkp said exactly what I was going to 😅
| <TextInput.Action | ||
| onClick={() => { | ||
| alert('clear input') | ||
| }} | ||
| icon={XIcon} | ||
| iconLabel="Clear input" | ||
| tooltipMessage="Clear" | ||
| sx={{color: 'fg.subtle'}} | ||
| /> |
There was a problem hiding this comment.
Is there a reason we couldn't wrap TextInput.Action with a Tooltip?
<Tooltiparia-label="Clear"><TextInput.Action.../></Tooltip>There was a problem hiding this comment.
Or... should we have a strong opinion about tooltips and automatically make the icon label visible in a tooltip?
There was a problem hiding this comment.
I imagine consumers don't to want to think about when they should use a tooltip
There was a problem hiding this comment.
+1 to always automatically tooltipped
also, would iconLabel and tooltipMessage be different?
There was a problem hiding this comment.
I vote we replace iconLabel and tooltipMessage with an aria-label prop that is required if no children are passed
There was a problem hiding this comment.
@siddharthkp - I thought there would be a case where the iconLabel and tooltipMessage are different, but now I'm second-guessing that... 🤔
I'm going to move forward with @colebemis's suggestion, and we can change that later if we need to.
There was a problem hiding this comment.
Now that I'm implementing this, I'm not sure aria-label is an intuitive prop to use for the tooltip message. Especially for buttons with a text label.
For example, this feels a little strange:
<TextInput.Actionaria-label="Show password">Show</TextInput.Action>I think this is a weird enough use-case that we can just go forward with Cole's suggestion, but I wanted to bring this up.
There was a problem hiding this comment.
Should we start without allowing a tooltip for buttons with text labels? This feels like a reasonable limitation, but I don't like that we would just silently swallow the aria-label
There was a problem hiding this comment.
Should we start without allowing a tooltip for buttons with text labels? This feels like a reasonable limitation
That sounds reasonable!
, but I don't like that we would just silently swallow the aria-label
For actions with text labels, is there a reason not to pass aria-label through to the Button if it's provided?
There was a problem hiding this comment.
I decided not to limit it
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
siddharthkp
left a comment
There was a problem hiding this comment.
Only one tiny piece left: #1947 (comment)
…ct into mp/text-input-trailing-action
Adds the capability to render a trailing action in a text input.
Closeshttps://github.com/github/primer/issues/748
Screenshots
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.