fix(client): add type to warn misuse of attributes in formControl (#48696)

* feat: add type to warn miss usage of attributes in formControl

Co-authored-by: Oliver Eyton-Williams <ojeytonwilliams@gmail.com>

* refactor the value type

Co-authored-by: sembauke <semboot699@gmail.com>

* add condition type for readyonly and onchange types

* warn when using readonly and onchange props together

Co-authored-by: Ahmad Abdolsaheb <ahmad.abdolsaheb@gmail.com>

* allow value to be undefined

* Make read-only undefined

Co-authored-by: Ahmad Abdolsaheb <ahmad.abdolsaheb@gmail.com>

---------

Co-authored-by: Oliver Eyton-Williams <ojeytonwilliams@gmail.com>
Co-authored-by: sembauke <semboot699@gmail.com>
Co-authored-by: Ahmad Abdolsaheb <ahmad.abdolsaheb@gmail.com>
This commit is contained in:
Muhammed Mustafa
2023-02-10 15:24:23 +02:00
committed by GitHub
parent 6e53c852de
commit 47ffd20f74

View File

@@ -2,20 +2,34 @@ import React from 'react';
export type FormControlElement = HTMLInputElement | HTMLTextAreaElement;
export interface FormControlProps
extends React.HTMLAttributes<FormControlElement> {
type ChangibleValues =
| {
value?: never;
onChange?: never;
readonly?: never;
}
| {
value: string;
onChange?: never;
readonly: boolean;
}
| {
value: string;
onChange: (event: React.ChangeEvent<FormControlElement>) => void;
readonly?: never;
};
export type FormControlProps = React.HTMLAttributes<FormControlElement> & {
className?: string;
id?: string;
testId?: string;
onChange?: React.ChangeEventHandler<FormControlElement>;
value?: string;
componentClass?: typeof React.Component;
placeholder?: string;
name?: string;
required?: boolean;
rows?: number;
type?: 'text' | 'email' | 'url';
}
} & ChangibleValues;
export interface FormControlVariationProps {
className?: string;