Skip to content

Commit

Permalink
Extend Form provider suppressedError to TextInput component (#274)
Browse files Browse the repository at this point in the history
* Update form package export types

* import type

* Allow form suppressError on TextInputs

* suppress Error on dynamic flat list example screen

* Added changesets
  • Loading branch information
JDMathew authored Nov 18, 2024
1 parent 9cdde2d commit 4c437e9
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 23 deletions.
11 changes: 11 additions & 0 deletions .changeset/six-kings-complain.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
---
'@react-native-ama/forms': patch
'@react-native-ama/lists': patch
'@react-native-ama/animations': patch
'@react-native-ama/core': patch
'@react-native-ama/extras': patch
'@react-native-ama/internal': patch
'@react-native-ama/react-native': patch
---

Added `suppressError` to `forms` package Form provider
1 change: 1 addition & 0 deletions examples/shared/src/screens/FlatListDynamic.screen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ export const FlatListDynamicScreen = () => {
<View style={styles.container}>
<Spacer height="normal" />
<TextInput
suppressError={true}
labelComponent={<Text>Filter:</Text>}
returnKeyType={'done'}
style={styles.input}
Expand Down
1 change: 0 additions & 1 deletion packages/forms/src/components/FormField.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ export const FormField = ({
typeof TouchableWithoutFeedback
> | null>(null);

// @ts-ignore
const formProps = useFormField({
hasFocusCallback: false,
ref: viewRef,
Expand Down
2 changes: 1 addition & 1 deletion packages/forms/src/components/FormSwitch.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {
SwitchListItem,
SwitchListItemProps,
type SwitchListItemProps,
} from '@react-native-ama/react-native';
import React from 'react';

Expand Down
29 changes: 13 additions & 16 deletions packages/forms/src/components/TextInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,18 @@ import {
TextInputProps as RNTextInputProps,
} from 'react-native';

import { useTextInput } from '../hooks/useTextInput';
import { UseTextInput, useTextInput } from '../hooks/useTextInput';

export type TextInputProps = RNTextInputProps & {
labelComponent: JSX.Element;
labelPosition?: 'beforeInput' | 'afterInput';
nextFormField?: React.RefObject<RNTextInput>;
id?: string;
nextFieldId?: string;
hasValidation: boolean;
errorComponent?: JSX.Element;
hasError?: boolean;
errorPosition?: 'belowLabel' | 'afterInput';
errorMessage?: string;
};
export type TextInputProps = RNTextInputProps &
Omit<UseTextInput, 'required' | 'accessibilityLabel'> & {
labelComponent: JSX.Element;
labelPosition?: 'beforeInput' | 'afterInput';
nextFormField?: React.RefObject<RNTextInput>;
id?: string;
nextFieldId?: string;
errorComponent?: JSX.Element;
errorPosition?: 'belowLabel' | 'afterInput';
};

export const TextInput = React.forwardRef<RNTextInput, TextInputProps>(
(
Expand Down Expand Up @@ -55,18 +53,17 @@ export const TextInput = React.forwardRef<RNTextInput, TextInputProps>(
[labelComponent, rest.accessibilityLabel],
);

// @ts-ignore
const textInputProps = useTextInput({
required: false,
...rest,
ref: inputRef,
id,
nextFieldId,
nextFormFieldRef: nextFormField,
hasError,
hasValidation,
errorMessage,
required: false,
accessibilityLabel,
...rest,
});

const checks = __DEV__ ? useChecks?.() : undefined;
Expand Down
2 changes: 1 addition & 1 deletion packages/forms/src/hooks/useTextInput.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import type {
import { TextInputProps } from '../components/TextInput';
import { UseFormField, useFormField } from './useFormField';

type UseTextInput = Omit<UseFormField, 'hasFocusCallback'> & {
export type UseTextInput = Omit<UseFormField, 'hasFocusCallback'> & {
onLayout?: (event: LayoutChangeEvent) => void;
returnKeyType?: ReturnKeyTypeOptions;
onSubmitEditing?: (
Expand Down
8 changes: 4 additions & 4 deletions packages/forms/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import { isFocused } from '@react-native-ama/internal';

import {
FormActions,
FormProps,
Form as FormProvider,
type FormProps,
} from './components/Form';
import { FormField, FormFieldProps } from './components/FormField';
import { FormSubmit, FormSubmitProps } from './components/FormSubmit';
Expand All @@ -26,11 +26,11 @@ Form.Switch = FormSwitch;
export { Form, FormField, FormSubmit, FormSwitch };

// Components
export { TextInput } from './components/TextInput';
export { TextInput, type TextInputProps } from './components/TextInput';

// Hooks
export { useFormField } from './hooks/useFormField';
export { useTextInput } from './hooks/useTextInput';
export { useFormField, type UseFormField } from './hooks/useFormField';
export { useTextInput, type UseTextInput } from './hooks/useTextInput';

// utils
export { isFocused };
Expand Down

0 comments on commit 4c437e9

Please sign in to comment.