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

fix(CanvasForm): Add missing ref into CustomLongTextField #11

Merged
merged 1 commit into from
May 2, 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
2 changes: 1 addition & 1 deletion packages/ui/src/components/Form/CustomAutoField.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { PropertiesField } from './properties/PropertiesField';
import { CustomLongTextField } from './customField/CustomLongTextField';

// Name of the properties that should load CustomLongTextField
const CustomLongTextProps = ['Expression', 'Sasl Jaas Config'];
const CustomLongTextProps = ['Expression', 'Description'];

/**
* Custom AutoField that supports all the fields from Uniforms PatternFly
Expand Down
8 changes: 4 additions & 4 deletions packages/ui/src/components/Form/CustomAutoForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -61,13 +61,13 @@ export const CustomAutoForm = forwardRef<CustomAutoFormRef, CustomAutoFormProps>
>
{props.sortFields ? (
// For some forms, sorting its fields might be beneficial
sortedFieldsNames.map((field) => (
sortedFieldsNames.map((field, index) => (
<AutoField
key={field}
name={field}
// inputRef={(node: HTMLElement) => {
// fieldsRefs.current[index] = node;
// }}
inputRef={(node: HTMLElement) => {
fieldsRefs.current[index] = node;
}}
/>
))
) : (
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import { HTMLFieldProps } from 'uniforms';
import { LongTextField } from '@kaoto-next/uniforms-patternfly';
import { FunctionComponent, RefObject } from 'react';
import './CustomLongTextField.scss';

export type CustomLongTextFieldProps = HTMLFieldProps<string, HTMLDivElement>;
type LongTextFieldProps = Parameters<typeof LongTextField>[0] & { ref: RefObject<HTMLTextAreaElement> };

Copy link
Owner

Choose a reason for hiding this comment

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

Since LongTextFieldProps is the type defined for LongTextField props and since we are adding a new property of ref to it. Giving it a new name should be the preference?

Copy link
Author

Choose a reason for hiding this comment

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

LongTextFieldProps it's not exported from uniforms-patternfly, therefore we could use the name.

export const CustomLongTextField = (props: CustomLongTextFieldProps) => {
return <LongTextField className="custom-long-test-field" {...props} rows={1} autoResize={true} />;
export const CustomLongTextField: FunctionComponent<LongTextFieldProps> = (props) => {
return (
<LongTextField className="custom-long-test-field" {...props} inputRef={props.ref} rows={1} autoResize={true} />
);
Copy link
Owner

@shivamG640 shivamG640 May 2, 2024

Choose a reason for hiding this comment

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

The CustomLongField loads perfectly fine for some fields(like description) without a ref!
Why do it need a ref to load nested fields only?

};
Loading