-
Notifications
You must be signed in to change notification settings - Fork 645
Add trailingAction to TextInput #1947
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
Changes from 43 commits
c9f34f1
26976c7
5157087
258ed6c
245b568
6c1f358
81a1022
89b0e44
e964c11
5388500
0473333
070612f
097e8fb
f2f52c7
79fbe76
4a4fcc0
1bdf6d1
5f14db8
3464982
d586a80
ced3de3
8bc639e
eebc472
2b18aee
52d2e1a
5cfc485
fc0eeef
8bf281d
e785ccd
a3dc21d
fffa764
f9ad318
18d6135
3f6b35e
8af0c07
16ad284
ac012f1
e94c13c
2781e4c
46f1daf
0dabb66
5781c4d
12c5f76
b26b765
f573158
1339d9d
6d1e442
641a276
b1d60a2
a16fb1b
e73b569
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| '@primer/react': minor | ||
| --- | ||
|
|
||
| Adds the option to render a trailing action inside of the TextInput component |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -108,6 +108,42 @@ const WithIconAndLoadingIndicator = () => { | |
| render(<WithIconAndLoadingIndicator />) | ||
| ``` | ||
|
|
||
| ### With trailing action | ||
|
|
||
| ```jsx live | ||
| <Box display="grid" sx={{gap: 3}}> | ||
| <FormControl> | ||
| <FormControl.Label>Icon action</FormControl.Label> | ||
| <TextInput | ||
| trailingAction={ | ||
| <TextInput.Action | ||
| onClick={() => { | ||
| alert('clear input') | ||
| }} | ||
| icon={XIcon} | ||
| iconLabel="Clear input" | ||
| sx={{color: 'fg.subtle'}} | ||
| /> | ||
| } | ||
| /> | ||
| </FormControl> | ||
| <FormControl> | ||
| <FormControl.Label>Text action</FormControl.Label> | ||
| <TextInput | ||
| trailingAction={ | ||
| <TextInput.Action | ||
| onClick={() => { | ||
| alert('clear input') | ||
| }} | ||
| > | ||
| Clear | ||
| </TextInput.Action> | ||
| } | ||
| /> | ||
| </FormControl> | ||
| </Box> | ||
| ``` | ||
|
|
||
| ### With error and warning states | ||
|
|
||
| ```jsx live | ||
|
|
@@ -160,61 +196,63 @@ render(<WithIconAndLoadingIndicator />) | |
|
|
||
| <PropsTable> | ||
| <PropsTableRow name="aria-label" type="string" description="Allows input to be accessible." /> | ||
| <PropsTableRow | ||
| name="block" | ||
| type="boolean" | ||
| defaultValue="false" | ||
| description="Creates a full-width input element" | ||
| /> | ||
| <PropsTableRow name="block" type="boolean" defaultValue="false" description="Creates a full-width input element" /> | ||
| <PropsTableRow | ||
| name="contrast" | ||
| type="boolean" | ||
| defaultValue="false" | ||
| description="Changes background color to a higher contrast color" | ||
| /> | ||
| <PropsTableRow name='size' type="'small' | 'medium' | 'large'" description="Creates a smaller or larger input than the default." /> | ||
|
|
||
| <PropsTableRow name="loading" type="boolean" description="Whether to show a loading indicator in the input" /> | ||
| <PropsTableRow | ||
| name="loaderPosition" | ||
| type="'auto' | 'leading' | 'trailing'" | ||
| description={ | ||
| <> | ||
| <div>Which position to render the loading indicator</div> | ||
| <ul> | ||
| <li> | ||
| 'auto' (default): at the end of the input, unless a `leadingVisual` is passed. Then, it will render at the | ||
| beginning | ||
| </li> | ||
| <li>'leading': at the beginning of the input</li> | ||
| <li>'trailing': at the end of the input</li> | ||
| </ul> | ||
| </> | ||
| } | ||
| /> | ||
| <PropsTableRow | ||
| name="leadingVisual" | ||
| type={<>string | React.ComponentType</>} | ||
| description="Visual positioned on the left edge inside the input" | ||
| /> | ||
| <PropsTableRow name="monospace" type="boolean" defaultValue="false" description="Shows input in monospace font" /> | ||
| <PropsTableRow | ||
| name="trailingVisual" | ||
| type={<>string | React.ComponentType</>} | ||
| description="Visual positioned on the right edge inside the input" | ||
| /> | ||
| <PropsTableRow | ||
| name="validationStatus" | ||
| type="'error' | 'success' | 'warning'" | ||
| description="Style the input to match the status" | ||
| /> | ||
| <PropsTableRow | ||
| name="variant" | ||
| type="'small' | 'medium' | 'large'" | ||
| description="(Use size) Creates a smaller or larger input than the default." | ||
| deprecated | ||
| /> | ||
|
|
||
| <PropsTableRow | ||
| name="size" | ||
| type="'small' | 'medium' | 'large'" | ||
| description="Creates a smaller or larger input than the default." | ||
| /> | ||
| <PropsTableRow name="loading" type="boolean" description="Whether to show a loading indicator in the input" /> | ||
| <PropsTableRow | ||
| name="loaderPosition" | ||
| type="'auto' | 'leading' | 'trailing'" | ||
| description={ | ||
| <> | ||
| <div>Which position to render the loading indicator</div> | ||
| <ul> | ||
| <li> | ||
| 'auto' (default): at the end of the input, unless a `leadingVisual` is passed. Then, it will render at the | ||
| beginning | ||
| </li> | ||
| <li>'leading': at the beginning of the input</li> | ||
| <li>'trailing': at the end of the input</li> | ||
| </ul> | ||
| </> | ||
| } | ||
| /> | ||
| <PropsTableRow | ||
| name="leadingVisual" | ||
| type={<>string | React.ComponentType</>} | ||
| description="Visual positioned on the left edge inside the input" | ||
| /> | ||
| <PropsTableRow name="monospace" type="boolean" defaultValue="false" description="Shows input in monospace font" /> | ||
| <PropsTableRow | ||
| name="trailingVisual" | ||
| type={<>string | React.ComponentType</>} | ||
| description="Visual positioned on the right edge inside the input" | ||
| /> | ||
| <PropsTableRow | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is the only thing that was added. The rest of the changes are just indentation.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could we add a props table for |
||
| name="trailingAction" | ||
| type="React.ReactElement<HTMLProps<HTMLButtonElement>>" | ||
| description="A visual that renders inside the input after the typing area" | ||
| /> | ||
| <PropsTableRow | ||
| name="validationStatus" | ||
| type="'error' | 'success' | 'warning'" | ||
| description="Style the input to match the status" | ||
| /> | ||
| <PropsTableRow | ||
| name="variant" | ||
| type="'small' | 'medium' | 'large'" | ||
| description="(Use size) Creates a smaller or larger input than the default." | ||
| deprecated | ||
| /> | ||
| <PropsTableRow | ||
| name="width" | ||
| type={ | ||
|
|
@@ -265,6 +303,29 @@ render(<WithIconAndLoadingIndicator />) | |
| /> | ||
| </PropsTable> | ||
|
|
||
| ### TextInput.Action | ||
|
|
||
| <PropsTable> | ||
| <PropsTableRow | ||
| name="aria-label" | ||
| type="string" | ||
| description="Text that appears in a tooltip. If an icon is passed, this is also used as the label used by assistive technologies." | ||
| /> | ||
| <PropsTableRow name="icon" type="React.FunctionComponent" description="The icon to render inside the button" /> | ||
| <PropsTableRow | ||
| name="variant" | ||
| type="'default' | 'primary' | 'invisible' | 'danger'" | ||
| description="Determine's the styles on a button" | ||
| /> | ||
| <PropsTableBasePropRows | ||
| elementType="button" | ||
| refType="HTMLButtonElement" | ||
| passthroughPropsLink={ | ||
| <Link href="https://developer.mozilla.org/en-US/docs/Web/HTML/Element/button#attributes">MDN</Link> | ||
| } | ||
| /> | ||
| </PropsTable> | ||
|
|
||
| ## Status | ||
|
|
||
| <ComponentChecklist | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -21,6 +21,7 @@ const InputLabel: React.FC<Props & SxProp> = ({children, disabled, required, vis | |
| display: 'block', | ||
| color: disabled ? 'fg.muted' : 'fg.default', | ||
| cursor: disabled ? 'default' : 'pointer', | ||
| alignSelf: 'flex-start', | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not relevant to this PR. I just noticed the label was clickable even if the user's cursor wasn't on the text. |
||
| ...sx | ||
| }} | ||
| > | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.
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 not super confident about this but what do you think about an API like this:
cc @siddharthkp
Uh oh!
There was an error while loading. Please reload this page.
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.
Oh yeah! Me and @mperrotti went through a bunch of options and this was one of them!
What I like:
What I don't like:
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.
@siddharthkp said exactly what I was going to 😅