@@ -2,6 +2,7 @@ import React, { useState } from "react";
22import { SearchBar } from "../dist/SearchBar" ;
33import { sectionName } from "./sectionName" ;
44import { getStoryFactory } from "./getStory" ;
5+ import { MuiSearchInput } from "./MuiSearchInput" ;
56
67const { meta, getStory } = getStoryFactory ( {
78 sectionName,
@@ -51,53 +52,40 @@ import { SearchBar } from "@codegouvfr/react-dsfr/SearchBar";
5152 }
5253) ;
5354
54- type MySearchInputProps = {
55- className ?: string ;
56- id : string ;
57- placeholder : string ;
58- type : "search" ;
59- } ;
60-
61- function MySearchInput ( props : MySearchInputProps ) {
62- const { className, id, placeholder, type } = props ;
63-
64- const [ search , onSearchChange ] = useState ( "" ) ;
65-
66- const [ inputElement , setInputElement ] = useState < HTMLInputElement | null > ( null ) ;
67-
68- return (
69- < >
70- < input
71- ref = { setInputElement }
72- className = { className }
73- id = { id }
74- placeholder = { placeholder }
75- type = { type }
76- value = { search }
77- onChange = { event => onSearchChange ( event . currentTarget . value ) }
78- onKeyDown = { event => {
79- if ( event . key === "Escape" ) {
80- inputElement ?. blur ( ) ;
81- }
82- } }
83- />
84- < p
85- style = { {
86- "position" : "absolute" ,
87- "top" : 84
88- } }
89- >
90- Search results for: { search }
91- </ p >
92- </ >
93- ) ;
94- }
95-
9655export const WithControlledInput = getStory (
9756 {
98- "renderInput" : ( { className, id, placeholder, type } ) => (
99- < MySearchInput className = { className } id = { id } placeholder = { placeholder } type = { type } />
100- )
57+ "renderInput" : ( { className, id, placeholder, type } ) => {
58+ const [ search , onSearchChange ] = useState ( "" ) ;
59+
60+ const [ inputElement , setInputElement ] = useState < HTMLInputElement | null > ( null ) ;
61+
62+ return (
63+ < >
64+ < input
65+ ref = { setInputElement }
66+ className = { className }
67+ id = { id }
68+ placeholder = { placeholder }
69+ type = { type }
70+ value = { search }
71+ onChange = { event => onSearchChange ( event . currentTarget . value ) }
72+ onKeyDown = { event => {
73+ if ( event . key === "Escape" ) {
74+ inputElement ?. blur ( ) ;
75+ }
76+ } }
77+ />
78+ < p
79+ style = { {
80+ "position" : "absolute" ,
81+ "top" : 84
82+ } }
83+ >
84+ Search results for: { search }
85+ </ p >
86+ </ >
87+ ) ;
88+ }
10189 } ,
10290 {
10391 "description" : `
@@ -148,6 +136,28 @@ function Root(){
148136
149137}
150138\`\`\`
139+ `
140+ }
141+ ) ;
142+
143+ export const WithMuiAutocomplete = getStory (
144+ {
145+ "renderInput" : ( { className, id, placeholder, type } ) => (
146+ < MuiSearchInput
147+ className = { className }
148+ id = { id }
149+ placeholder = { placeholder }
150+ type = { type }
151+ value = ""
152+ onChange = { ( ) => {
153+ /**/
154+ } }
155+ results = { [ ] }
156+ />
157+ )
158+ } ,
159+ {
160+ "description" : `
151161
152162If you want to feature a modern search experience with realtime hinting you can omit providing a \`onSearchButtonClick\` callback and instead
153163make sure you provide an overlay with the search results in the the \`renderSearchInput\` function.
@@ -176,12 +186,12 @@ function MySearchInput(props: MySearchInputProps) {
176186 return (
177187 <Autocomplete
178188 ...
189+ id={id}
179190 renderInput={params =>
180191 <div ref={params.InputProps.ref}>
181192 <input
182193 {...params.inputProps}
183194 className={cx(params.inputProps.className, className)}
184- id={id}
185195 placeholder={placeholder}
186196 type={type}
187197 />
0 commit comments