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

Commit

Permalink
Refactor: unify autoFocus prop and add autoCorrect prop into the Tags…
Browse files Browse the repository at this point in the history
…Input
  • Loading branch information
FilipMessa authored and RobinCsl committed Feb 22, 2019
1 parent 4bbfed9 commit 0fbdb90
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 12 deletions.
14 changes: 9 additions & 5 deletions src/TagsInput/TagsInput.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ type Props = {|
+onKeyPress?: (e: Event) => void,
+placeholder?: string,
+value?: string,
+autofocus: boolean,
+autoFocus: boolean,
+autoCorrect: boolean,
|};

type State = {
Expand All @@ -50,7 +51,8 @@ export default class TagsInput extends React.Component<Props, State> {
static defaultProps = {
fontSize: parseFloat(defaultTokens.fontSizeButtonLarge),
tags: [],
autofocus: false,
autoFocus: false,
autoCorrect: false,
};

constructor(props: Props) {
Expand All @@ -60,7 +62,7 @@ export default class TagsInput extends React.Component<Props, State> {

this.state = {
value: props.value || '',
isFocus: props.autofocus,
isFocus: props.autoFocus,
};
}

Expand Down Expand Up @@ -119,7 +121,8 @@ export default class TagsInput extends React.Component<Props, State> {
label,
onKeyPress,
tags,
autofocus,
autoFocus,
autoCorrect,
} = this.props;
const { isFocus, value } = this.state;

Expand Down Expand Up @@ -156,7 +159,8 @@ export default class TagsInput extends React.Component<Props, State> {
>
<TagsContainer tags={tags} fontSize={fontSize} />
<InputField
autofocus={autofocus}
autoCorrect={autoCorrect}
autoFocus={autoFocus}
onKeyPress={onKeyPress}
onFocus={this.handleOnFocus}
onBlur={this.handleOnBlur}
Expand Down
16 changes: 12 additions & 4 deletions src/TagsInput/TagsInput.stories.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,13 @@
import React from 'react';
import { View } from 'react-native';
import { storiesOf } from '@storybook/react-native';
import { text, withKnobs, object, number } from '@storybook/addon-knobs';
import {
text,
withKnobs,
object,
number,
boolean,
} from '@storybook/addon-knobs';
import { action } from '@storybook/addon-actions';

import TagsInput from './TagsInput';
Expand All @@ -18,7 +24,7 @@ storiesOf('TagsInput', module)
onChangeText={action('onChangeText')}
label="From:"
placeholder="Departure point"
autofocus
autoFocus
/>
</View>
))
Expand All @@ -29,7 +35,7 @@ storiesOf('TagsInput', module)
onChangeText={action('onChangeText')}
label="From:"
placeholder="Departure point"
autofocus
autoFocus
/>
</View>
))
Expand All @@ -42,12 +48,14 @@ storiesOf('TagsInput', module)
step: 1,
});
const label = text('Label', 'From:');
const autoCorrect = boolean('Auto correct', false);

const placeholder = text('Placeholder', 'Departure point');
return (
<View style={{ margin: 20 }}>
<TagsInput
autofocus
autoCorrect={autoCorrect}
autoFocus
fontSize={fontSize}
tags={tags}
onChangeText={action('onChangeText')}
Expand Down
9 changes: 6 additions & 3 deletions src/TagsInput/components/InputField.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ type Props = {|
+maxWidth?: number,
+placeholder?: string,
+onKeyPress?: (e: ViewLayoutEvent) => void,
+autofocus?: boolean,
+autoFocus?: boolean,
+autoCorrect?: boolean,
|};

type State = {|
Expand Down Expand Up @@ -100,7 +101,8 @@ class InputField extends React.Component<Props, State> {
onFocus,
onBlur,
onKeyPress,
autofocus,
autoFocus,
autoCorrect,
} = this.props;
const { componentWidth } = this.state;

Expand All @@ -116,7 +118,8 @@ class InputField extends React.Component<Props, State> {
return (
<View style={styles.container}>
<TextInput
autoFocus={autofocus}
autoCorrect={autoCorrect}
autoFocus={autoFocus}
onKeyPress={onKeyPress}
onBlur={onBlur}
onFocus={onFocus}
Expand Down

0 comments on commit 0fbdb90

Please sign in to comment.