-
Notifications
You must be signed in to change notification settings - Fork 81
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: Update Search component to support i18n #1192
Changes from all commits
ebbc678
fefb023
d64c85d
cdd22c7
c76bf7a
c5dfc77
d87613b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,10 +7,12 @@ import { Form, OptionalFormProps } from '../forms/Form/Form' | |
import { Label } from '../forms/Label/Label' | ||
import { TextInput } from '../forms/TextInput/TextInput' | ||
|
||
interface SearchLocalization { | ||
buttonText: string | ||
} | ||
|
||
interface SearchInputProps { | ||
onSubmit: (event: React.FormEvent<HTMLFormElement>) => void | ||
inputId?: string | ||
inputName?: string | ||
size?: 'big' | 'small' | ||
/** | ||
* @deprecated since 1.6.0, use size | ||
|
@@ -20,21 +22,25 @@ interface SearchInputProps { | |
* @deprecated since 1.6.0, use size | ||
*/ | ||
small?: boolean | ||
label?: React.ReactNode | ||
className?: string | ||
inputName?: string | ||
inputId?: string | ||
placeholder?: string | ||
label?: React.ReactNode | ||
i18n?: SearchLocalization | ||
} | ||
|
||
export const Search = ({ | ||
onSubmit, | ||
inputId = 'search-field', | ||
inputName = 'search', | ||
size, | ||
big, | ||
small, | ||
label = 'Search', | ||
className, | ||
placeholder, | ||
inputName = 'search', | ||
label = 'Search', | ||
inputId = 'search-field', | ||
i18n, | ||
...formProps | ||
}: SearchInputProps & OptionalFormProps): React.ReactElement => { | ||
if (big) { | ||
|
@@ -44,6 +50,8 @@ export const Search = ({ | |
deprecationWarning('Search property small is deprecated. Use size') | ||
} | ||
|
||
const buttonText = i18n?.buttonText || 'Search' | ||
|
||
const isBig = size ? size === 'big' : big | ||
const isSmall = size ? size === 'small' : small | ||
const classes = classnames( | ||
|
@@ -73,7 +81,7 @@ export const Search = ({ | |
/> | ||
<Button type="submit"> | ||
<span className={isSmall ? 'usa-sr-only' : 'usa-search__submit-text'}> | ||
Search | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So while this works and may be perfectly acceptable, I can see a use case where someone may want to the Button text to be different from the label. There's also the thought of following convention for localizations which we established in #990. There we added an My overall preference with this is to follow convention, even if it feels like overkill, in the name of uniform codebase. Plus, to handle the scenario of wanting label and button text to be different we would have to introduce a new prop anyways, so that would be half way to implementing our established i18n pattern. |
||
{buttonText} | ||
</span> | ||
</Button> | ||
</Form> | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you want, you can even declare a default for
i18n
(such as theEN_US
used inDatePicker
). Since this is only one field withini18n
, I'm good with it as is.