Skip to content

Commit

Permalink
fix(Search): Add placeholder to Search input #403 (#415)
Browse files Browse the repository at this point in the history
Co-authored-by: Schaffer Stewart <schaestewart@gmail.com>
  • Loading branch information
haworku and SchaeStewart authored Aug 18, 2020
1 parent b9b23b3 commit ca31eb4
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 2 deletions.
6 changes: 5 additions & 1 deletion src/components/Search/Search.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,9 @@ export const bigSearch = (): React.ReactElement => (
)

export const smallSearch = (): React.ReactElement => (
<Search size="small" onSubmit={mockSubmit} />
<Search
placeholder="(Optional) Placeholder Text"
size="small"
onSubmit={mockSubmit}
/>
)
12 changes: 12 additions & 0 deletions src/components/Search/Search.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,18 @@ describe('Search component', () => {
expect(mockSubmit).toHaveBeenCalledTimes(1)
})

it('renders a placeholder', () => {
const mockSubmit = jest.fn()
const placeholder = 'Search here'
const { queryByTestId } = render(
<Search onSubmit={mockSubmit} placeholder={placeholder}></Search>
)
expect(queryByTestId('textInput')).toHaveAttribute(
'placeholder',
placeholder
)
})

describe('renders size classes', () => {
beforeEach(() => {
jest.clearAllMocks()
Expand Down
9 changes: 8 additions & 1 deletion src/components/Search/Search.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ interface SearchInputProps {
small?: boolean
label?: React.ReactNode
className?: string
placeholder?: string
}

export const Search = (
Expand All @@ -36,6 +37,7 @@ export const Search = (
small,
label = 'Search',
className,
placeholder,
...formProps
} = props
if (big) {
Expand Down Expand Up @@ -66,7 +68,12 @@ export const Search = (
<Label srOnly={true} htmlFor={inputId}>
{label}
</Label>
<TextInput id={inputId} type="search" name={inputName} />
<TextInput
id={inputId}
type="search"
name={inputName}
placeholder={placeholder}
/>
<Button type="submit">
<span className={isSmall ? 'usa-sr-only' : 'usa-search__submit-text'}>
Search
Expand Down

0 comments on commit ca31eb4

Please sign in to comment.