Skip to content

Commit bf8fadf

Browse files
authored
feat(SearchBar): add defaultValue (#381)
1 parent d50c845 commit bf8fadf

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

src/SearchBar/SearchBar.tsx

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import "../assets/search-bar.css";
1212

1313
export type SearchBarProps = {
1414
className?: string;
15+
defaultValue?: string;
1516
id?: string;
1617
/** Default: "Rechercher" (or translation) */
1718
label?: string;
@@ -25,6 +26,7 @@ export type SearchBarProps = {
2526
* the others params can, but it's not mandatory.
2627
**/
2728
params: {
29+
defaultValue?: string;
2830
id: string;
2931
type: "search";
3032
className: string;
@@ -45,13 +47,20 @@ export const SearchBar = memo(
4547
forwardRef<HTMLDivElement, SearchBarProps>((props, ref) => {
4648
const {
4749
className,
50+
defaultValue,
4851
id: id_props,
4952
label: label_props,
5053
big = false,
5154
classes = {},
5255
style,
53-
renderInput = ({ className, id, placeholder, type }) => (
54-
<input className={className} id={id} placeholder={placeholder} type={type} />
56+
renderInput = ({ className, defaultValue, id, placeholder, type }) => (
57+
<input
58+
className={className}
59+
defaultValue={defaultValue}
60+
id={id}
61+
placeholder={placeholder}
62+
type={type}
63+
/>
5564
),
5665
clearInputOnSearch = false,
5766
allowEmptySearch = false,
@@ -92,6 +101,7 @@ export const SearchBar = memo(
92101
one time and only one time in each render to allow useState to be used inline*/}
93102
{renderInput({
94103
"className": fr.cx("fr-input"),
104+
"defaultValue": defaultValue,
95105
"placeholder": label,
96106
"type": "search",
97107
"id": inputId

stories/SearchBar.stories.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ export default meta;
4141

4242
export const DefaultUncontrolled = getStory(
4343
{
44+
"defaultValue": "France",
4445
"label": undefined,
4546
"onButtonClick": text => alert(`TODO: implement search with text: ${text}`)
4647
},

0 commit comments

Comments
 (0)