Skip to content
This repository was archived by the owner on Mar 4, 2020. It is now read-only.

Commit 60739ac

Browse files
committed
fixing the input focus issue when clicking on the icon
1 parent 2125308 commit 60739ac

File tree

2 files changed

+30
-3
lines changed

2 files changed

+30
-3
lines changed

src/components/Input/Input.tsx

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import {
1414
import inputRules from './inputRules'
1515
import inputVariables from './inputVariables'
1616
import 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
)

src/components/Input/inputRules.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ const inputRules = {
3131
return {
3232
position: variables.iconPosition,
3333
right: variables.iconRight,
34+
outline: 0,
3435
}
3536
},
3637
}

0 commit comments

Comments
 (0)