Skip to content

Commit

Permalink
fix(onchange callback): change sending event instead of value (#95)
Browse files Browse the repository at this point in the history
  • Loading branch information
karelhala authored Apr 5, 2024
1 parent cf20cbf commit a2e2537
Show file tree
Hide file tree
Showing 5 changed files with 6 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import * as React from 'react';
import { FieldInputProps } from 'formik';

export const onChangePFAdapter = <T = React.FormEvent<HTMLInputElement>, E = boolean>(field: FieldInputProps<T>) => {
return (_: T, e: E) => {
export const onChangePFAdapter = <T = React.FormEvent<HTMLInputElement>>(field: FieldInputProps<T>) => {
return (e: T) => {
return field.onChange(e);
};
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export const FormSelect: React.FunctionComponent<FormSelectProps> = (props) => {
<PFFormSelect
{ ...withoutOuiaProps(props) }
{ ...field }
onChange={ onChangePFAdapter<React.FormEvent<HTMLSelectElement>, string | number>(field) }
onChange={ onChangePFAdapter<React.FormEvent<HTMLSelectElement>>(field) }
isRequired={ props.isRequired }
validated={ (isValid) ? 'default' : 'error' }
>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export const FormTextArea: React.FunctionComponent<FormTextAreaProps> = (props)
value={ field.value || '' }
validated={ (isValid) ? 'default' : 'error' }
isRequired={ props.isRequired }
onChange={ onChangePFAdapter<React.FormEvent<HTMLTextAreaElement>, string | number>(field) }
onChange={ onChangePFAdapter<React.FormEvent<HTMLTextAreaElement>>(field) }
/>
{meta.error && <FormHelperText>
<HelperText>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export const FormTextInput: React.FunctionComponent<FormTextInputProps> = (props
{ ...field }
validated={ (isValid) ? 'default' : 'error' }
value={ field.value !== undefined ? field.value.toString() : '' }
onChange={ onChangePFAdapter<React.FormEvent<HTMLInputElement>, string | number>(field) }
onChange={ onChangePFAdapter<React.FormEvent<HTMLInputElement>>(field) }
/>
{ hint && <Text component={ TextVariants.small }>{ hint }</Text> }
{meta.error && <FormHelperText>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export const Switch: React.FunctionComponent<SwitchProps> = (props) => {
ouiaId="pf-switch"
ouiaSafe={ props.ouiaSafe }
label={ label }
onChange={ onChangePFAdapter<React.FormEvent<HTMLInputElement>, boolean>(field) }
onChange={ onChangePFAdapter<React.FormEvent<HTMLInputElement>>(field) }
/>
{meta.error && <FormHelperText>
<HelperText>
Expand Down

0 comments on commit a2e2537

Please sign in to comment.