Skip to content

Commit

Permalink
update examples to hide trailing action when empty
Browse files Browse the repository at this point in the history
  • Loading branch information
siddharthkp committed Aug 8, 2024
1 parent 2792717 commit 096e54c
Showing 1 changed file with 22 additions and 24 deletions.
46 changes: 22 additions & 24 deletions packages/react/src/TextInput/TextInput.features.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React, {useState} from 'react'
import {Box, FormControl} from '..'
import {Box, FormControl, Stack} from '..'
import type {TextInputProps} from '../TextInput'
import TextInput from '../TextInput'
import {CalendarIcon, CheckIcon, XCircleFillIcon} from '@primer/octicons-react'
Expand Down Expand Up @@ -121,7 +121,7 @@ export const WithTrailingIcon = () => (
)

export const WithTrailingAction = () => {
const [value, setValue] = useState('')
const [value, setValue] = useState('sample text')

const handleChange = (event: React.ChangeEvent<HTMLInputElement>) => {
setValue(event.target.value)
Expand All @@ -131,26 +131,23 @@ export const WithTrailingAction = () => {
<FormControl>
<FormControl.Label>Default label</FormControl.Label>
<TextInput
trailingAction={
<TextInput.Action
onClick={() => {
setValue('')
}}
icon={XCircleFillIcon}
aria-label="Clear input"
sx={{color: 'fg.subtle'}}
/>
}
value={value}
onChange={handleChange}
trailingAction={
<Stack justify="center" style={{minWidth: '34px'}}>
{value.length ? (
<TextInput.Action onClick={() => setValue('')} icon={XCircleFillIcon} aria-label="Clear input" />
) : undefined}
</Stack>
}
/>
</FormControl>
</Box>
)
}

export const WithTooltipDirection = () => {
const [value, setValue] = useState('')
const [value, setValue] = useState('sample text')

const handleChange = (event: React.ChangeEvent<HTMLInputElement>) => {
setValue(event.target.value)
Expand All @@ -160,19 +157,20 @@ export const WithTooltipDirection = () => {
<FormControl>
<FormControl.Label>Default label</FormControl.Label>
<TextInput
trailingAction={
<TextInput.Action
onClick={() => {
setValue('')
}}
icon={XCircleFillIcon}
aria-label="Clear input"
tooltipDirection="nw"
sx={{color: 'fg.subtle'}}
/>
}
value={value}
onChange={handleChange}
trailingAction={
<Stack justify="center" style={{minWidth: '34px'}}>
{value.length ? (
<TextInput.Action
onClick={() => setValue('')}
icon={XCircleFillIcon}
aria-label="Clear input"
tooltipDirection="nw"
/>
) : undefined}
</Stack>
}
/>
</FormControl>
</Box>
Expand Down

0 comments on commit 096e54c

Please sign in to comment.