Skip to content

Support custom passing children as custom input in Incubator.TextField #1518

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Sep 12, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions generatedTypes/src/incubator/TextField/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* 3. Passing typography preset that includes lineHeight usually cause alignment issues with
* other elements (leading/trailing accessories). It usually best to set lineHeight with undefined
*/
import React, { ReactElement } from 'react';
import React, { PropsWithChildren, ReactElement } from 'react';
import { ViewStyle, TextStyle } from 'react-native';
import { ForwardRefInjectedProps, BaseComponentInjectedProps, MarginModifiers, PaddingModifiers, TypographyModifiers, ColorsModifiers } from '../../commons/new';
import { ValidationMessagePosition, Validator } from './types';
Expand Down Expand Up @@ -70,7 +70,7 @@ export declare type TextFieldProps = MarginModifiers & PaddingModifiers & Typogr
*/
preset?: 'default' | null;
};
export declare type InternalTextFieldProps = TextFieldProps & BaseComponentInjectedProps & ForwardRefInjectedProps;
export declare type InternalTextFieldProps = PropsWithChildren<TextFieldProps & BaseComponentInjectedProps & ForwardRefInjectedProps>;
interface StaticMembers {
validationMessagePositions: typeof ValidationMessagePosition;
}
Expand Down
3 changes: 3 additions & 0 deletions generatedTypes/src/incubator/TextField/usePreset.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ export default function usePreset({ preset, ...props }: InternalTextFieldProps):
containerStyle?: import("react-native").ViewStyle | undefined;
modifiers: import("../../commons/modifiers").ExtractedStyle;
forwardedRef: any;
children?: import("react").ReactNode;
} | {
margin?: boolean | undefined;
marginL?: boolean | undefined;
Expand Down Expand Up @@ -494,6 +495,7 @@ export default function usePreset({ preset, ...props }: InternalTextFieldProps):
containerStyle?: import("react-native").ViewStyle | undefined;
modifiers: import("../../commons/modifiers").ExtractedStyle;
forwardedRef: any;
children?: import("react").ReactNode;
} | {
margin?: boolean | undefined;
marginL?: boolean | undefined;
Expand Down Expand Up @@ -1062,4 +1064,5 @@ export default function usePreset({ preset, ...props }: InternalTextFieldProps):
containerStyle?: import("react-native").ViewStyle | undefined;
modifiers: import("../../commons/modifiers").ExtractedStyle;
forwardedRef: any;
children?: import("react").ReactNode;
};
27 changes: 15 additions & 12 deletions src/incubator/TextField/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* 3. Passing typography preset that includes lineHeight usually cause alignment issues with
* other elements (leading/trailing accessories). It usually best to set lineHeight with undefined
*/
import React, {ReactElement, useMemo} from 'react';
import React, {PropsWithChildren, ReactElement, useMemo} from 'react';
import {ViewStyle, TextStyle} from 'react-native';
import {omit, isFunction} from 'lodash';
import {
Expand Down Expand Up @@ -95,10 +95,10 @@ export type TextFieldProps = MarginModifiers &
preset?: 'default' | null;
};

export type InternalTextFieldProps = TextFieldProps &
export type InternalTextFieldProps = PropsWithChildren<TextFieldProps &
// Omit<FieldStateInjectedProps, keyof InputProps> &
BaseComponentInjectedProps &
ForwardRefInjectedProps;
ForwardRefInjectedProps>;

interface StaticMembers {
validationMessagePositions: typeof ValidationMessagePosition;
Expand Down Expand Up @@ -140,6 +140,7 @@ const TextField = (props: InternalTextFieldProps) => {
charCounterStyle,
// Input
placeholder,
children,
...others
} = usePreset(props);
const {onFocus, onBlur, onChangeText, fieldState, validateField} = useFieldState(others);
Expand Down Expand Up @@ -186,15 +187,17 @@ const TextField = (props: InternalTextFieldProps) => {
validationMessagePosition={validationMessagePosition}
/>
)}
<Input
{...others}
style={[typographyStyle, colorStyle, others.style]}
onFocus={onFocus}
onBlur={onBlur}
onChangeText={onChangeText}
placeholder={floatingPlaceholder ? undefined : placeholder}
hint={hint}
/>
{children || (
<Input
{...others}
style={[typographyStyle, colorStyle, others.style]}
onFocus={onFocus}
onBlur={onBlur}
onChangeText={onChangeText}
placeholder={floatingPlaceholder ? undefined : placeholder}
hint={hint}
/>
)}
</View>
{trailingAccessory}
</View>
Expand Down