mirror of
https://github.com/freeCodeCamp/freeCodeCamp.git
synced 2026-05-13 16:04:36 -04:00
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:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user