Skip to content

Commit 096e54c

Browse files
committed
update examples to hide trailing action when empty
1 parent 2792717 commit 096e54c

File tree

1 file changed

+22
-24
lines changed

1 file changed

+22
-24
lines changed

packages/react/src/TextInput/TextInput.features.stories.tsx

Lines changed: 22 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import React, {useState} from 'react'
2-
import {Box, FormControl} from '..'
2+
import {Box, FormControl, Stack} from '..'
33
import type {TextInputProps} from '../TextInput'
44
import TextInput from '../TextInput'
55
import {CalendarIcon, CheckIcon, XCircleFillIcon} from '@primer/octicons-react'
@@ -121,7 +121,7 @@ export const WithTrailingIcon = () => (
121121
)
122122

123123
export const WithTrailingAction = () => {
124-
const [value, setValue] = useState('')
124+
const [value, setValue] = useState('sample text')
125125

126126
const handleChange = (event: React.ChangeEvent<HTMLInputElement>) => {
127127
setValue(event.target.value)
@@ -131,26 +131,23 @@ export const WithTrailingAction = () => {
131131
<FormControl>
132132
<FormControl.Label>Default label</FormControl.Label>
133133
<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-
}
144134
value={value}
145135
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+
}
146143
/>
147144
</FormControl>
148145
</Box>
149146
)
150147
}
151148

152149
export const WithTooltipDirection = () => {
153-
const [value, setValue] = useState('')
150+
const [value, setValue] = useState('sample text')
154151

155152
const handleChange = (event: React.ChangeEvent<HTMLInputElement>) => {
156153
setValue(event.target.value)
@@ -160,19 +157,20 @@ export const WithTooltipDirection = () => {
160157
<FormControl>
161158
<FormControl.Label>Default label</FormControl.Label>
162159
<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-
}
174160
value={value}
175161
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+
}
176174
/>
177175
</FormControl>
178176
</Box>

0 commit comments

Comments
 (0)