Skip to content

Commit feab0b3

Browse files
committed
change public ref api to support focus and blur HTMLInputElement methods
1 parent 0bea71d commit feab0b3

File tree

1 file changed

+19
-2
lines changed

1 file changed

+19
-2
lines changed

src/InputHints.js

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,10 @@ class InputHints extends Component {
8888
})
8989
}
9090

91+
_getTextInputNode() {
92+
return this.refTextInput
93+
}
94+
9195
tick() {
9296
const {placeholders} = this.props
9397
const {
@@ -138,10 +142,23 @@ class InputHints extends Component {
138142
const placeholder = currentPlaceholder.slice(0, currentCharPos)
139143

140144
return (
141-
<input placeholder={placeholder} {...inputProps} />
145+
<input ref={(e) => this.refTextInput = e} placeholder={placeholder} {...inputProps} />
142146
)
143147
}
144148

145149
}
146150

147-
module.exports = InputHints
151+
function inputWrapper(WrappedComponent) {
152+
class Input extends Component {
153+
focus() { this.c._getTextInputNode().focus() }
154+
blur() { this.c._getTextInputNode().blur() }
155+
156+
render() {
157+
return <WrappedComponent {...this.props} ref={(c) => this.c = c} />
158+
}
159+
}
160+
Input.displayName = WrappedComponent.displayName || 'Component'
161+
return input
162+
}
163+
164+
module.exports = inputWrapper(InputHints)

0 commit comments

Comments
 (0)