2022-05-11 09:46:14 +00:00
|
|
|
import { TextArea, TextAreaProps } from "@patternfly/react-core";
|
|
|
|
import React, { ComponentProps, forwardRef, HTMLProps } from "react";
|
|
|
|
|
|
|
|
// PatternFly changes the signature of the 'onChange' handler for textarea elements.
|
|
|
|
// This causes issues with React Hook Form as it expects the default signature for a textarea element.
|
|
|
|
// So we have to create this wrapper component that takes care of converting these signatures for us.
|
|
|
|
|
|
|
|
export type KeycloakTextAreaProps = Omit<
|
|
|
|
ComponentProps<typeof TextArea>,
|
|
|
|
"onChange"
|
|
|
|
> &
|
|
|
|
Pick<HTMLProps<HTMLTextAreaElement>, "onChange">;
|
|
|
|
|
|
|
|
export const KeycloakTextArea = forwardRef<
|
2022-06-24 11:45:43 +00:00
|
|
|
HTMLTextAreaElement,
|
2022-05-11 09:46:14 +00:00
|
|
|
KeycloakTextAreaProps
|
|
|
|
>(({ onChange, ...props }, ref) => {
|
|
|
|
const onChangeForward: TextAreaProps["onChange"] = (_, event) =>
|
|
|
|
onChange?.(event);
|
|
|
|
|
|
|
|
return <TextArea {...props} ref={ref} onChange={onChangeForward} />;
|
|
|
|
});
|
|
|
|
|
|
|
|
// We need to fake the displayName to match what PatternFly expects.
|
|
|
|
// This is because PatternFly uses it to filter children in certain aspects.
|
|
|
|
// This is a stupid approach, but it's not like we can change that.
|
|
|
|
KeycloakTextArea.displayName = "TextArea";
|