Skip to content

Commit

Permalink
fix(ref): input ref
Browse files Browse the repository at this point in the history
  • Loading branch information
duspada-builders committed Sep 21, 2021
1 parent e2d0660 commit ff126d8
Show file tree
Hide file tree
Showing 11 changed files with 1,260 additions and 1,993 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@platformbuilders/react-native-elements",
"version": "0.3.3",
"version": "0.3.4",
"description": "Platform Builders Shared Components Library For React Native",
"main": "dist/index.js",
"types": "dist/index.d.ts",
Expand Down
13 changes: 3 additions & 10 deletions src/components/MaskedText/lib/text-input-mask.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
/* eslint-disable react/jsx-filename-extension */
import React from 'react';
import { TextInput } from 'react-native';
import BaseTextComponent from './base-text-component';

export default class TextInputMask extends BaseTextComponent {
getElement() {
return this._inputElement;
return this.props.inputRef || this._inputElement;
}

_onChangeText(text) {
Expand Down Expand Up @@ -52,15 +53,7 @@ export default class TextInputMask extends BaseTextComponent {

return (
<Input
ref={(ref) => {
if (ref) {
this._inputElement = ref;

if (typeof this.props.refInput === 'function') {
this.props.refInput(ref);
}
}
}}
ref={this.getElement()}
keyboardType={this._getKeyboardType()}
{...this.props}
{...customTextInputProps}
Expand Down
41 changes: 37 additions & 4 deletions src/components/SearchInput/__tests__/Search.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,12 @@ describe('<Search />', () => {
const onChange = jest.fn();
const wrapper = renderer.create(
<ThemeProvider theme={theme}>
<Search id="test" accessibility="" onChange={onChange} />
<Search
inputRef="$text"
id="test"
accessibility=""
onChange={onChange}
/>
</ThemeProvider>,
);

Expand All @@ -24,6 +29,7 @@ describe('<Search />', () => {
const wrapper = renderer.create(
<ThemeProvider theme={theme}>
<Search
inputRef="$text"
id="test"
accessibility=""
onChange={onChange}
Expand All @@ -40,6 +46,7 @@ describe('<Search />', () => {
const wrapper = renderer.create(
<ThemeProvider theme={theme}>
<Search
inputRef="$text"
id="test"
accessibility=""
onChange={onChange}
Expand All @@ -56,6 +63,7 @@ describe('<Search />', () => {
const wrapper = renderer.create(
<ThemeProvider theme={theme}>
<Search
inputRef="$text"
id="test"
accessibility=""
onChange={onChange}
Expand All @@ -72,6 +80,7 @@ describe('<Search />', () => {
const wrapper = renderer.create(
<ThemeProvider theme={theme}>
<Search
inputRef="$text"
id="test"
accessibility=""
onChange={onChange}
Expand All @@ -87,7 +96,13 @@ describe('<Search />', () => {
const onChange = jest.fn();
const wrapper = renderer.create(
<ThemeProvider theme={theme}>
<Search id="test" accessibility="" onChange={onChange} iconSize={24} />
<Search
inputRef="$text"
id="test"
accessibility=""
onChange={onChange}
iconSize={24}
/>
</ThemeProvider>,
);

Expand All @@ -98,7 +113,13 @@ describe('<Search />', () => {
const onChange = jest.fn();
const wrapper = renderer.create(
<ThemeProvider theme={theme}>
<Search id="test" accessibility="" onChange={onChange} hasShadow />
<Search
inputRef="$text"
id="test"
accessibility=""
onChange={onChange}
hasShadow
/>
</ThemeProvider>,
);

Expand All @@ -110,6 +131,7 @@ describe('<Search />', () => {
const wrapper = renderer.create(
<ThemeProvider theme={theme}>
<Search
inputRef="$text"
id="test"
accessibility=""
onChange={onChange}
Expand All @@ -126,6 +148,7 @@ describe('<Search />', () => {
const wrapper = renderer.create(
<ThemeProvider theme={theme}>
<Search
inputRef="$text"
id="test"
accessibility=""
onChange={onChange}
Expand All @@ -142,6 +165,7 @@ describe('<Search />', () => {
const wrapper = renderer.create(
<ThemeProvider theme={theme}>
<Search
inputRef="$text"
id="test"
accessibility=""
onChange={onChange}
Expand All @@ -158,6 +182,7 @@ describe('<Search />', () => {
const wrapper = renderer.create(
<ThemeProvider theme={theme}>
<Search
inputRef="$text"
id="test"
accessibility=""
onChange={onChange}
Expand All @@ -173,7 +198,13 @@ describe('<Search />', () => {
const onChange = jest.fn();
const wrapper = renderer.create(
<ThemeProvider theme={theme}>
<Search id="test" accessibility="" onChange={onChange} autoFocus />
<Search
inputRef="$text"
id="test"
accessibility=""
onChange={onChange}
autoFocus
/>
</ThemeProvider>,
);

Expand All @@ -185,6 +216,7 @@ describe('<Search />', () => {
const wrapper = renderer.create(
<ThemeProvider theme={theme}>
<Search
inputRef="$text"
id="test"
accessibility=""
onChange={onChange}
Expand All @@ -201,6 +233,7 @@ describe('<Search />', () => {
const wrapper = renderer.create(
<ThemeProvider theme={theme}>
<Search
inputRef="$text"
id="test"
accessibility=""
onChange={onChange}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ exports[`<Search /> should render search 1`] = `
centered={false}
contrast={false}
id="test"
inputRef="$text"
isPlaceholder={true}
keyboardType="default"
large={false}
Expand Down Expand Up @@ -311,6 +312,7 @@ exports[`<Search /> should render search with auto focus 1`] = `
centered={false}
contrast={false}
id="test"
inputRef="$text"
isPlaceholder={false}
keyboardType="default"
large={false}
Expand Down Expand Up @@ -522,6 +524,7 @@ exports[`<Search /> should render search with custom container style 1`] = `
centered={false}
contrast={false}
id="test"
inputRef="$text"
isPlaceholder={false}
keyboardType="default"
large={false}
Expand Down Expand Up @@ -730,6 +733,7 @@ exports[`<Search /> should render search with custom icon color 1`] = `
centered={false}
contrast={false}
id="test"
inputRef="$text"
isPlaceholder={false}
keyboardType="default"
large={false}
Expand Down Expand Up @@ -941,6 +945,7 @@ exports[`<Search /> should render search with custom input style 1`] = `
centered={false}
contrast={false}
id="test"
inputRef="$text"
isPlaceholder={true}
keyboardType="default"
large={false}
Expand Down Expand Up @@ -1149,6 +1154,7 @@ exports[`<Search /> should render search with custom placeholder 1`] = `
centered={false}
contrast={false}
id="test"
inputRef="$text"
isPlaceholder={true}
keyboardType="default"
large={false}
Expand Down Expand Up @@ -1357,6 +1363,7 @@ exports[`<Search /> should render search with custom placeholder color 1`] = `
centered={false}
contrast={false}
id="test"
inputRef="$text"
isPlaceholder={true}
keyboardType="default"
large={false}
Expand Down Expand Up @@ -1565,6 +1572,7 @@ exports[`<Search /> should render search with custom text style 1`] = `
centered={false}
contrast={false}
id="test"
inputRef="$text"
isPlaceholder={false}
keyboardType="default"
large={false}
Expand Down Expand Up @@ -1775,6 +1783,7 @@ exports[`<Search /> should render search with icon size 1`] = `
centered={false}
contrast={false}
id="test"
inputRef="$text"
isPlaceholder={false}
keyboardType="default"
large={false}
Expand Down Expand Up @@ -2029,6 +2038,7 @@ exports[`<Search /> should render search with left icon 1`] = `
centered={false}
contrast={false}
id="test"
inputRef="$text"
isPlaceholder={false}
keyboardType="default"
large={false}
Expand Down Expand Up @@ -2193,6 +2203,7 @@ exports[`<Search /> should render search with padding 1`] = `
centered={false}
contrast={false}
id="test"
inputRef="$text"
isPlaceholder={true}
keyboardType="default"
large={false}
Expand Down Expand Up @@ -2401,6 +2412,7 @@ exports[`<Search /> should render search with right icon 1`] = `
centered={false}
contrast={false}
id="test"
inputRef="$text"
isPlaceholder={true}
keyboardType="default"
large={false}
Expand Down Expand Up @@ -2616,6 +2628,7 @@ exports[`<Search /> should render search with shadow 1`] = `
centered={false}
contrast={false}
id="test"
inputRef="$text"
isPlaceholder={true}
keyboardType="default"
large={false}
Expand Down Expand Up @@ -2825,6 +2838,7 @@ exports[`<Search /> should render search with wrapper height 1`] = `
centered={false}
contrast={false}
id="test"
inputRef="$text"
isPlaceholder={false}
keyboardType="default"
large={false}
Expand Down
4 changes: 3 additions & 1 deletion src/components/SearchInput/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ type Props = {
autoFocus?: boolean;
rightIconName?: string;
leftIconName?: string;
inputRef?: any;
};

const SearchInput: React.FC<Props> = ({
Expand All @@ -49,12 +50,13 @@ const SearchInput: React.FC<Props> = ({
autoFocus = false,
rightIconName,
leftIconName,
inputRef,
...rest
}) => {
const [searchText, setSearchText] = useState('');
const [isSearching, setSearching] = useState(false);
const [isFocused, setFocused] = useState(false);
const ref = useRef<HTMLInputElement>(null);
const ref = inputRef || useRef<HTMLInputElement>(null);

const onPressIcon = (): void => {
if (onIconPress) {
Expand Down
2 changes: 1 addition & 1 deletion src/components/TextInput/MaskedTextInput/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const MaskedTextInput: FC<MaskedTextInputType> = ({
accessibility={accessibility}
testID={id || accessibility}
accessibilityLabel={accessibility}
ref={inputRef}
inputRef={inputRef}
contrast={contrast}
multiline={multiline}
type={maskType}
Expand Down
2 changes: 1 addition & 1 deletion src/components/TextInput/__tests__/PasswordInput.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ describe('<PasswordInput />', () => {
it('should render PasswordInput', () => {
const wrapper = renderer.create(
<ThemeProvider theme={theme}>
<PasswordInput id="test" accessibility="test" />
<PasswordInput inputRef="$text" id="test" accessibility="test" />
</ThemeProvider>,
);

Expand Down
2 changes: 1 addition & 1 deletion src/components/TextInput/__tests__/TextInput.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ describe('<TextInput />', () => {
it('should render textinput', () => {
const wrapper = renderer.create(
<ThemeProvider theme={theme}>
<TextInput id="test" accessibility="" />
<TextInput inputRef="$text" id="test" accessibility="" />
</ThemeProvider>,
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ exports[`<PasswordInput /> should render PasswordInput 1`] = `
centered={false}
contrast={false}
id="test"
inputRef="$text"
isPlaceholder={true}
keyboardType="default"
large={false}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ exports[`<TextInput /> should render textinput 1`] = `
centered={false}
contrast={false}
id="test"
inputRef="$text"
isPlaceholder={true}
keyboardType="default"
large={false}
Expand Down
Loading

0 comments on commit ff126d8

Please sign in to comment.