Skip to content

Commit

Permalink
feat(phone/ui): forward ref properly on NPWD input wrapper components
Browse files Browse the repository at this point in the history
  • Loading branch information
TasoOneAsia committed Dec 3, 2021
1 parent 3062ead commit 6c34bec
Showing 1 changed file with 38 additions and 40 deletions.
78 changes: 38 additions & 40 deletions phone/src/ui/components/Input.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React from 'react';
import React, { forwardRef } from 'react';
import MUITextField, { TextFieldProps } from '@mui/material/TextField';
import MUIInputBase, { InputBaseProps } from '@mui/material/InputBase';
import { PhoneEvents } from '@typings/phone';
Expand All @@ -10,43 +10,41 @@ const toggleKeys = (keepGameFocus: boolean) =>
keepGameFocus,
}).catch((e) => (isEnvBrowser() ? () => {} : console.error(e)));

export const TextField: React.FC<TextFieldProps> = (props) => {
return (
<MUITextField
{...props}
variant={props.variant ?? 'standard'}
onFocus={(e) => {
toggleKeys(false);
if (props.onFocus) {
props.onFocus(e);
}
}}
onBlur={(e) => {
toggleKeys(true);
if (props.onBlur) {
props.onBlur(e);
}
}}
/>
);
};
export const TextField = forwardRef<HTMLInputElement, TextFieldProps>((props, ref) => (
<MUITextField
ref={ref}
{...props}
variant={props.variant ?? 'standard'}
onFocus={(e) => {
toggleKeys(false);
if (props.onFocus) {
props.onFocus(e);
}
}}
onBlur={(e) => {
toggleKeys(true);
if (props.onBlur) {
props.onBlur(e);
}
}}
/>
));

export const InputBase: React.FC<InputBaseProps> = (props) => {
return (
<MUIInputBase
{...props}
onFocus={(e) => {
toggleKeys(false);
if (props.onFocus) {
props.onFocus(e);
}
}}
onBlur={(e) => {
toggleKeys(true);
if (props.onBlur) {
props.onBlur(e);
}
}}
/>
);
};
export const InputBase: React.FC<InputBaseProps> = forwardRef((props, ref) => (
<MUIInputBase
ref={ref}
{...props}
onFocus={(e) => {
toggleKeys(false);
if (props.onFocus) {
props.onFocus(e);
}
}}
onBlur={(e) => {
toggleKeys(true);
if (props.onBlur) {
props.onBlur(e);
}
}}
/>
));

0 comments on commit 6c34bec

Please sign in to comment.