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

Conversation

lordrip
Copy link

@lordrip lordrip commented May 2, 2024

Context

Patternfly's TextArea component requires using a ref to provide automatic height.

Unfortunately, with React function components, ref is not directly possible, so a workaround is needed.

Changes

This commit restores the commented lines and also adds the missing ref object.

relates: KaotoIO#1043

Patternfly's `TextArea` component requires using a `ref` in order to
provide automatic height.

Unfortunately, with React function components, `ref` are not directly possible, so a workaround is needed.

This commit restores the commented lines and also add the missing `ref`
object.

relates: KaotoIO#1043
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.

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?

@shivamG640 shivamG640 merged commit 58b4f91 into shivamG640:Fix-1043 May 2, 2024
1 of 5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants