Skip to content

Commit

Permalink
Add custom onChange response
Browse files Browse the repository at this point in the history
  • Loading branch information
Studio384 committed Jul 1, 2022
1 parent 57b50a1 commit 741e8dc
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
8 changes: 7 additions & 1 deletion src/components/InputControl/InputControl.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export interface InputControlProps
/**
* ID of the input
*/
id?: string;
id: string;
/**
* Name of the input
*/
Expand All @@ -28,6 +28,10 @@ export interface InputControlProps
* Placeholder of the input
*/
placeholder?: string;
/**
* The callback for changing values
*/
onChange: (value: any | null) => void;
/**
* Type of the input
*/
Expand All @@ -50,6 +54,7 @@ export const InputControl = ({
type,
placeholder,
helper,
onChange,
...props
}: InputControlProps) => {
const uniqueName = name ?? id;
Expand All @@ -64,6 +69,7 @@ export const InputControl = ({
value={value}
className={clsx("input", className)}
placeholder={placeholder}
onChange={(event) => onChange({ value: event?.target.value, id })}
aria-describedby={helper ? `${uniqueName}-help` : undefined}
{...props}
/>
Expand Down
4 changes: 2 additions & 2 deletions src/components/SelectControl/SelectControl.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export interface SelectControlProps {
/**
* ID of the input
*/
id?: string;
id: string;
/**
* The name attached of the select
*/
Expand Down Expand Up @@ -97,7 +97,7 @@ export const SelectControl = ({
<div className="form-floating">
<Listbox
value={value}
onChange={onChange}
onChange={(value) => onChange({ value, id })}
disabled={disabled}
name={uniqueName}
>
Expand Down

0 comments on commit 741e8dc

Please sign in to comment.