Skip to content

Commit

Permalink
feat: allow subscribing for the InputEvent in the TextField compo…
Browse files Browse the repository at this point in the history
…nent
  • Loading branch information
aradzie committed Nov 11, 2024
1 parent 9480fbb commit f7d7438
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
9 changes: 8 additions & 1 deletion packages/keybr-widget/lib/components/textfield/TextField.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export const TextField = forwardRef(function TextField(
type = "text",
value,
onChange,
onInput,
...props
}: TextFieldProps,
ref: ForwardedRef<TextFieldRef>,
Expand Down Expand Up @@ -59,11 +60,15 @@ export const TextField = forwardRef(function TextField(
onChange={(event) => {
onChange?.((event.target as HTMLTextAreaElement).value);
}}
onInput={({ nativeEvent }) => {
onInput?.(nativeEvent as InputEvent);
}}
/>
);
} else {
return (
<input
{...props}
ref={element as RefObject<HTMLInputElement>}
className={clsx(
styles.root,
Expand All @@ -81,7 +86,9 @@ export const TextField = forwardRef(function TextField(
onChange={(event) => {
onChange?.((event.target as HTMLInputElement).value);
}}
{...props}
onInput={({ nativeEvent }) => {
onInput?.(nativeEvent as InputEvent);
}}
/>
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export type TextFieldProps = {
readonly type?: TextFieldType;
readonly value?: string;
readonly onChange?: (value: string) => void;
readonly onInput?: (event: InputEvent) => void;
} & FocusProps &
MouseProps &
KeyboardProps;
Expand Down

0 comments on commit f7d7438

Please sign in to comment.