Skip to content

Commit

Permalink
fix: accept id and name props for Search component input field (#183)
Browse files Browse the repository at this point in the history
* fix: accept id and name props for Search component input field
* fix: qualify id and name props for input field to not clash with form
fix #162
  • Loading branch information
duncan-truss authored May 20, 2020
1 parent 8cb5121 commit c39c085
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/components/Search/Search.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export default {
info: `
USWDS 2.0 Search component
Source: https://designsystem.digital.gov/components/header/
Source: https://designsystem.digital.gov/components/search/
`,
},
}
Expand Down
8 changes: 6 additions & 2 deletions src/components/Search/Search.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import { TextInput } from '../forms/TextInput/TextInput'

interface SearchInputProps {
onSubmit: (event: React.FormEvent<HTMLFormElement>) => void
inputId?: string
inputName?: string
big?: boolean
small?: boolean
label?: React.ReactNode
Expand All @@ -19,6 +21,8 @@ export const Search = (
): React.ReactElement => {
const {
onSubmit,
inputId = 'search-field',
inputName = 'search',
big,
small,
label = 'Search',
Expand All @@ -41,10 +45,10 @@ export const Search = (
role="search"
search={true}
{...formProps}>
<Label srOnly={true} htmlFor="search-field">
<Label srOnly={true} htmlFor={inputId}>
{label}
</Label>
<TextInput id="search-field" type="search" name="search" />
<TextInput id={inputId} type="search" name={inputName} />
<Button type="submit">
<span className={small ? 'usa-sr-only' : 'usa-search__submit-text'}>
Search
Expand Down

0 comments on commit c39c085

Please sign in to comment.