Skip to content
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

[react@18] fix field.helpText type issue #192083

Merged
merged 1 commit into from
Sep 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ export const TitleField = ({
<EuiFormRow
label={field.label}
labelAppend={field.labelAppend}
helpText={typeof field.helpText === 'function' ? field.helpText() : field.helpText}
helpText={field.helpText}
error={errorMessage}
isInvalid={isInvalid}
fullWidth
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export const ButtonGroupField = ({ field, euiFieldProps, idAria, ...rest }: Prop
return (
<EuiFormRow
label={field.label}
helpText={typeof field.helpText === 'function' ? field.helpText() : field.helpText}
helpText={field.helpText}
error={errorMessage}
isInvalid={isInvalid}
fullWidth
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export const CardRadioGroupField = ({
<EuiFormRow
label={field.label}
labelType="legend"
helpText={typeof field.helpText === 'function' ? field.helpText() : field.helpText}
helpText={field.helpText}
error={errorMessage}
isInvalid={isInvalid}
fullWidth
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export const CheckBoxField = ({ field, euiFieldProps = {}, idAria, ...rest }: Pr

return (
<EuiFormRow
helpText={typeof field.helpText === 'function' ? field.helpText() : field.helpText}
helpText={field.helpText}
error={errorMessage}
isInvalid={isInvalid}
fullWidth
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ export const ComboBoxField = ({ field, euiFieldProps = {}, idAria, ...rest }: Pr
<EuiFormRow
label={field.label}
labelAppend={field.labelAppend}
helpText={typeof field.helpText === 'function' ? field.helpText() : field.helpText}
helpText={field.helpText}
error={errorMessage}
isInvalid={isInvalid}
fullWidth
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export const DatePickerField = ({ field, euiFieldProps, idAria, ...rest }: Props
return (
<EuiFormRow
label={field.label}
helpText={typeof field.helpText === 'function' ? field.helpText() : field.helpText}
helpText={field.helpText}
error={errorMessage}
isInvalid={isInvalid}
fullWidth
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ export const FilePickerField = ({
<EuiFormRow
label={field.label}
labelAppend={field.labelAppend}
helpText={typeof field.helpText === 'function' ? field.helpText() : field.helpText}
helpText={field.helpText}
error={errorMessage}
isInvalid={isInvalid}
fullWidth
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export const MultiButtonGroupField = ({ field, euiFieldProps, idAria, ...rest }:
return (
<EuiFormRow
label={field.label}
helpText={typeof field.helpText === 'function' ? field.helpText() : field.helpText}
helpText={field.helpText}
error={errorMessage}
isInvalid={isInvalid}
fullWidth
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export const MultiSelectField = ({ field, euiFieldProps = {}, idAria, ...rest }:
return (
<EuiFormRow
label={field.label}
helpText={typeof field.helpText === 'function' ? field.helpText() : field.helpText}
helpText={field.helpText}
error={errorMessage}
isInvalid={isInvalid}
fullWidth
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export const NumericField = ({ field, euiFieldProps = {}, idAria, ...rest }: Pro
return (
<EuiFormRow
label={field.label}
helpText={typeof field.helpText === 'function' ? field.helpText() : field.helpText}
helpText={field.helpText}
error={errorMessage}
isInvalid={isInvalid}
fullWidth
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export const PasswordField = ({ field, euiFieldProps, idAria, ...rest }: Props)
return (
<EuiFormRow
label={field.label}
helpText={typeof field.helpText === 'function' ? field.helpText() : field.helpText}
helpText={field.helpText}
error={errorMessage}
isInvalid={isInvalid}
fullWidth
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export const RadioGroupField = ({ field, euiFieldProps = {}, idAria, ...rest }:
return (
<EuiFormRow
label={field.label}
helpText={typeof field.helpText === 'function' ? field.helpText() : field.helpText}
helpText={field.helpText}
error={errorMessage}
isInvalid={isInvalid}
fullWidth
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export const RangeField = ({ field, euiFieldProps = {}, idAria, ...rest }: Props
return (
<EuiFormRow
label={field.label}
helpText={typeof field.helpText === 'function' ? field.helpText() : field.helpText}
helpText={field.helpText}
error={errorMessage}
isInvalid={isInvalid}
fullWidth
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export const SelectField = ({ field, euiFieldProps, idAria, ...rest }: Props) =>
return (
<EuiFormRow
label={field.label}
helpText={typeof field.helpText === 'function' ? field.helpText() : field.helpText}
helpText={field.helpText}
error={errorMessage}
isInvalid={isInvalid}
fullWidth
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export const SuperSelectField = ({
return (
<EuiFormRow
label={field.label}
helpText={typeof field.helpText === 'function' ? field.helpText() : field.helpText}
helpText={field.helpText}
error={errorMessage}
isInvalid={isInvalid}
fullWidth
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export const TextAreaField = ({ field, euiFieldProps = {}, idAria, ...rest }: Pr
return (
<EuiFormRow
label={field.label}
helpText={typeof field.helpText === 'function' ? field.helpText() : field.helpText}
helpText={field.helpText}
error={errorMessage}
isInvalid={isInvalid}
fullWidth
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export const TextField = ({ field, euiFieldProps = {}, idAria, ...rest }: Props)
<EuiFormRow
label={field.label}
labelAppend={field.labelAppend}
helpText={typeof field.helpText === 'function' ? field.helpText() : field.helpText}
helpText={field.helpText}
error={errorMessage}
isInvalid={isInvalid}
fullWidth
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export const ToggleField = ({ field, euiFieldProps = {}, idAria, ...rest }: Prop

return (
<EuiFormRow
helpText={typeof field.helpText === 'function' ? field.helpText() : field.helpText}
helpText={field.helpText}
error={errorMessage}
isInvalid={isInvalid}
fullWidth
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export const MyComponent = () => {
return (
<EuiFormRow
label={label}
helpText={typeof helpText === 'function' ? helpText() : helpText}
helpText={helpText}
error={errorMessage}
isInvalid={isInvalid}
>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ export const MyComponent = () => {
return (
<EuiFormRow
label={field.label}
helpText={typeof field.helpText === 'function' ? field.helpText() : helpText}
helpText={helpText}
error={errorMessage}
isInvalid={isInvalid}
>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -549,7 +549,7 @@ export const useField = <T, FormType = FormData, I = T>(
type,
label,
labelAppend,
helpText,
helpText: typeof helpText === 'function' ? helpText() : helpText,
Copy link
Contributor Author

@Dosant Dosant Sep 4, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here we're unwraping the lazy helpText so that the useField() receives the ReactNode value. This allows to simplify a bunch of existing places and not to fix a bunch of other places where helpText={helpText} is already used

value,
errors,
isPristine,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ export interface FieldHook<T = unknown, I = T> {
export interface FieldConfig<T = unknown, FormType extends FormData = FormData, I = T> {
readonly label?: string;
readonly labelAppend?: string | ReactNode;
readonly helpText?: string | ReactNode;
readonly helpText?: string | ReactNode | (() => ReactNode);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here we allow a lazy helpText. It is already used like this in some places, it worked because a function could be assigned to ReactNode due to a mistake in @types/react@17. This is no longer allowed with @types/react@18

readonly type?: string;
readonly defaultValue?: T;
readonly validations?: Array<ValidationConfig<FormType, string, I>>;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ export const IndicesSelector = ({ field, euiFieldProps, ...rest }: Props) => {
<EuiFormRow
label={field.label}
labelAppend={field.labelAppend}
helpText={typeof field.helpText === 'function' ? field.helpText() : field.helpText}
helpText={field.helpText}
error={errorMessage}
isInvalid={isInvalid}
fullWidth
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export const MustacheTextFieldWrapper = ({ field, euiFieldProps, idAria, ...rest
describedByIds: idAria ? [idAria] : undefined,
error: errorMessage,
fullWidth: true,
helpText: typeof field.helpText === 'function' ? field.helpText() : field.helpText,
helpText: field.helpText,
isInvalid,
label: field.label,
...rest,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ interface Props {
describedByIds?: string[];
error: string | null;
fullWidth: boolean;
helpText: string;
helpText: React.ReactNode;
isInvalid: boolean;
label?: string;
};
Expand All @@ -45,7 +45,7 @@ const Wrapper = ({
describedByIds?: string[];
error: string | null;
fullWidth: boolean;
helpText: string;
helpText: React.ReactNode;
isInvalid: boolean;
label?: string;
};
Expand Down