1
1
import React , { useState } from 'react'
2
- import { Box , FormControl } from '..'
2
+ import { Box , FormControl , Stack } from '..'
3
3
import type { TextInputProps } from '../TextInput'
4
4
import TextInput from '../TextInput'
5
5
import { CalendarIcon , CheckIcon , XCircleFillIcon } from '@primer/octicons-react'
@@ -121,7 +121,7 @@ export const WithTrailingIcon = () => (
121
121
)
122
122
123
123
export const WithTrailingAction = ( ) => {
124
- const [ value , setValue ] = useState ( '' )
124
+ const [ value , setValue ] = useState ( 'sample text ' )
125
125
126
126
const handleChange = ( event : React . ChangeEvent < HTMLInputElement > ) => {
127
127
setValue ( event . target . value )
@@ -131,26 +131,23 @@ export const WithTrailingAction = () => {
131
131
< FormControl >
132
132
< FormControl . Label > Default label</ FormControl . Label >
133
133
< TextInput
134
- trailingAction = {
135
- < TextInput . Action
136
- onClick = { ( ) => {
137
- setValue ( '' )
138
- } }
139
- icon = { XCircleFillIcon }
140
- aria-label = "Clear input"
141
- sx = { { color : 'fg.subtle' } }
142
- />
143
- }
144
134
value = { value }
145
135
onChange = { handleChange }
136
+ trailingAction = {
137
+ < Stack justify = "center" style = { { minWidth : '34px' } } >
138
+ { value . length ? (
139
+ < TextInput . Action onClick = { ( ) => setValue ( '' ) } icon = { XCircleFillIcon } aria-label = "Clear input" />
140
+ ) : undefined }
141
+ </ Stack >
142
+ }
146
143
/>
147
144
</ FormControl >
148
145
</ Box >
149
146
)
150
147
}
151
148
152
149
export const WithTooltipDirection = ( ) => {
153
- const [ value , setValue ] = useState ( '' )
150
+ const [ value , setValue ] = useState ( 'sample text ' )
154
151
155
152
const handleChange = ( event : React . ChangeEvent < HTMLInputElement > ) => {
156
153
setValue ( event . target . value )
@@ -160,19 +157,20 @@ export const WithTooltipDirection = () => {
160
157
< FormControl >
161
158
< FormControl . Label > Default label</ FormControl . Label >
162
159
< TextInput
163
- trailingAction = {
164
- < TextInput . Action
165
- onClick = { ( ) => {
166
- setValue ( '' )
167
- } }
168
- icon = { XCircleFillIcon }
169
- aria-label = "Clear input"
170
- tooltipDirection = "nw"
171
- sx = { { color : 'fg.subtle' } }
172
- />
173
- }
174
160
value = { value }
175
161
onChange = { handleChange }
162
+ trailingAction = {
163
+ < Stack justify = "center" style = { { minWidth : '34px' } } >
164
+ { value . length ? (
165
+ < TextInput . Action
166
+ onClick = { ( ) => setValue ( '' ) }
167
+ icon = { XCircleFillIcon }
168
+ aria-label = "Clear input"
169
+ tooltipDirection = "nw"
170
+ />
171
+ ) : undefined }
172
+ </ Stack >
173
+ }
176
174
/>
177
175
</ FormControl >
178
176
</ Box >
0 commit comments