@@ -14,6 +14,7 @@ import {
1414import inputRules from './inputRules'
1515import inputVariables from './inputVariables'
1616import Icon from '../Icon'
17+ import callable from '../../lib/callable'
1718
1819/**
1920 * An Input
@@ -54,11 +55,20 @@ class Input extends UIComponent<any, any> {
5455 type : 'text' ,
5556 }
5657
58+ inputRef : any
59+
60+ computeTabIndex = props => {
61+ if ( ! _ . isNil ( props . tabIndex ) ) return props . tabIndex
62+ if ( props . onClick ) return 0
63+ }
64+
5765 handleChildOverrides = ( child , defaultProps ) => ( {
5866 ...defaultProps ,
5967 ...child . props ,
6068 } )
6169
70+ handleInputRef = c => ( this . inputRef = c )
71+
6272 partitionProps = ( ) => {
6373 const { type } = this . props
6474
@@ -69,6 +79,7 @@ class Input extends UIComponent<any, any> {
6979 {
7080 ...htmlInputProps ,
7181 type,
82+ onClick : ( ) => this . inputRef . focus ( ) ,
7283 } ,
7384 rest ,
7485 ]
@@ -81,6 +92,12 @@ class Input extends UIComponent<any, any> {
8192 return null
8293 }
8394
95+ handleIconOverrides = predefinedProps => {
96+ return {
97+ tabIndex : this . computeTabIndex ,
98+ }
99+ }
100+
84101 renderComponent ( { ElementType, classes, rest } ) {
85102 const { children, className, icon, input, type } = this . props
86103 const [ htmlInputProps , restProps ] = this . partitionProps ( )
@@ -109,9 +126,15 @@ class Input extends UIComponent<any, any> {
109126 < ElementType { ...rest } className = { classes . root } { ...htmlInputProps } >
110127 { createHTMLInput ( input || type , {
111128 defaultProps : htmlInputProps ,
112- overrideProps : { className : inputClasses } ,
129+ overrideProps : {
130+ className : inputClasses ,
131+ ref : this . handleInputRef ,
132+ } ,
133+ } ) }
134+ { Icon . create ( this . computeIcon ( ) , {
135+ defaultProps : { className : iconClasses } ,
136+ overrideProps : predefinedProps => this . handleIconOverrides ,
113137 } ) }
114- < Icon name = { this . computeIcon ( ) } className = { iconClasses } />
115138 </ ElementType >
116139 )
117140 }
@@ -120,7 +143,10 @@ class Input extends UIComponent<any, any> {
120143 < ElementType { ...rest } className = { classes . root } { ...htmlInputProps } >
121144 { createHTMLInput ( input || type , {
122145 defaultProps : htmlInputProps ,
123- overrideProps : { className : inputClasses } ,
146+ overrideProps : {
147+ className : inputClasses ,
148+ ref : this . handleInputRef ,
149+ } ,
124150 } ) }
125151 </ ElementType >
126152 )
0 commit comments