Skip to content
This repository has been archived by the owner on Jan 13, 2023. It is now read-only.

Commit

Permalink
Forward TextField focus
Browse files Browse the repository at this point in the history
  • Loading branch information
Morgan Laco committed Oct 2, 2018
1 parent 62e816e commit 6359f4b
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 0 deletions.
2 changes: 2 additions & 0 deletions boilerplate/src/views/shared/text-field/text-field.props.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,6 @@ export interface TextFieldProps extends TextInputProperties {
* Various look & feels.
*/
preset?: "default"

forwardedRef?: any
}
22 changes: 22 additions & 0 deletions boilerplate/src/views/shared/text-field/text-field.story.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,28 @@ storiesOf("TextField", module)
borderRadius: 4,
borderColor: "hotpink",
}}
.add("Ref Forwarding", () => (
<Story>
<UseCase
text="Ref Forwarding"
usage=""
>
<State initial={{ value: "fancy colour" }}>
{({ state, setState }) => (
<TextField
onChangeText={value => setState({ value })}
value={state.value}
label="Name"
inputStyle={{
backgroundColor: "rebeccapurple",
color: "white",
padding: 40,
borderWidth: 10,
borderRadius: 4,
borderColor: "hotpink",
}}
forwardedRef={ref => ref && ref.focus()}
onFocus={() => console.tron.log("focus")}
/>
)}
</State>
Expand Down
2 changes: 2 additions & 0 deletions boilerplate/src/views/shared/text-field/text-field.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ export class TextField extends React.Component<TextFieldProps, {}> {
preset = "default",
style: styleOverride,
inputStyle: inputStyleOverride,
forwardedRef,
...rest,
} = this.props
const containerStyle: ViewStyle = { ...CONTAINER, ...PRESETS[preset], ...styleOverride }
Expand All @@ -52,6 +53,7 @@ export class TextField extends React.Component<TextFieldProps, {}> {
underlineColorAndroid={color.transparent}
{...rest}
style={inputStyle}
ref={forwardedRef}
/>
</View>
)
Expand Down

0 comments on commit 6359f4b

Please sign in to comment.