@@ -2,7 +2,7 @@ import { css } from 'emotion';
22import * as React from 'react' ;
33import { TypographyProps } from '../typography/typography' ;
44import { merge , mergeProps , pipe } from '../util/hoc.util' ;
5- import { ThemeContext , PaletteTheme } from '../util/theme' ;
5+ import { PaletteTheme , ThemeContext } from '../util/theme' ;
66
77export enum LabelType {
88 float ,
@@ -251,7 +251,15 @@ export const TextInput: React.FunctionComponent<TextInputPropsExtended> = React.
251251 ...defaultHostProps
252252 } = props ;
253253 const theme = defaultTheme ( React . useContext ( ThemeContext ) ) ;
254- const hostProps = mergeProps ( TextInputRootClass ( theme ) , defaultHostProps ) ;
254+ const hostProps = mergeProps (
255+ TextInputRootClass ( theme ) ,
256+ {
257+ onClick : ( ) => setActive ( true ) ,
258+ onFocus : ( ) => setActive ( true ) ,
259+ onBlur : ( ) => setActive ( false ) ,
260+ } ,
261+ defaultHostProps
262+ ) ;
255263 const labelProps = mergeProps (
256264 TypographyProps ( { scale : 'Caption' , baselineTop : 20 } ) ,
257265 LabelClass ( theme , labelType , value , status , isActive )
@@ -262,17 +270,24 @@ export const TextInput: React.FunctionComponent<TextInputPropsExtended> = React.
262270 } ) ;
263271 const activIndicatorProps = ActiveIndicatorClass ( theme , status , isActive ) ;
264272 return (
265- < div
266- ref = { forwardedRef }
267- { ...hostProps }
268- onClick = { ( ) => setActive ( true ) }
269- onFocus = { ( ) => setActive ( true ) }
270- onBlur = { ( ) => setActive ( false ) }
271- >
273+ < div ref = { forwardedRef } { ...hostProps } >
272274 < div { ...labelProps } > { label } </ div >
273275 < input { ...inputProps } ref = { inputRef } />
274276 < div { ...activIndicatorProps } />
275277 </ div >
276278 ) ;
277279 }
278280) ;
281+
282+ export const TextInputFocus : React . FunctionComponent < TextInputPropsExtended > = React . forwardRef (
283+ ( props : TextInputPropsExtended , forwardedRef ) => {
284+ const { value, onNewVal, ...defaultHostProps } = props ;
285+ const [ inputVal , setInputVal ] = React . useState ( value ) ;
286+ React . useEffect ( ( ) => setInputVal ( value ) , [ value ] ) ;
287+ const inputOnNewVal = React . useCallback ( e => setInputVal ( e ) , [ ] ) ;
288+ const hostProps = mergeProps ( defaultHostProps , { onBlur : ( ) => onNewVal ( inputVal ) } ) ;
289+ return (
290+ < TextInput ref = { forwardedRef } { ...hostProps } value = { inputVal } onNewVal = { inputOnNewVal } />
291+ ) ;
292+ }
293+ ) ;
0 commit comments