fix(striker-ui): add option to disable autofill in outlined input

main
Tsu-ba-me 11 months ago
parent 1cfd588448
commit d40efa9289
  1. 42
      striker-ui/components/OutlinedInput/OutlinedInput.tsx
  2. 4
      striker-ui/components/OutlinedInputWithLabel.tsx

@ -15,6 +15,7 @@ import { GREY, TEXT, UNSELECTED } from '../../lib/consts/DEFAULT_THEME';
import INPUT_TYPES from '../../lib/consts/INPUT_TYPES'; import INPUT_TYPES from '../../lib/consts/INPUT_TYPES';
type OutlinedInputOptionalProps = { type OutlinedInputOptionalProps = {
disableAutofill?: boolean;
onPasswordVisibilityAppend?: ( onPasswordVisibilityAppend?: (
inputType: string, inputType: string,
...restArgs: Parameters<Exclude<MUIIconButtonProps['onClick'], undefined>> ...restArgs: Parameters<Exclude<MUIIconButtonProps['onClick'], undefined>>
@ -25,13 +26,15 @@ type OutlinedInputProps = MUIOutlinedInputProps & OutlinedInputOptionalProps;
const OUTLINED_INPUT_DEFAULT_PROPS: Pick< const OUTLINED_INPUT_DEFAULT_PROPS: Pick<
OutlinedInputOptionalProps, OutlinedInputOptionalProps,
'onPasswordVisibilityAppend' 'disableAutofill' | 'onPasswordVisibilityAppend'
> = { > = {
disableAutofill: false,
onPasswordVisibilityAppend: undefined, onPasswordVisibilityAppend: undefined,
}; };
const OutlinedInput: FC<OutlinedInputProps> = (outlinedInputProps) => { const OutlinedInput: FC<OutlinedInputProps> = (outlinedInputProps) => {
const { const {
disableAutofill = false,
endAdornment, endAdornment,
label, label,
onPasswordVisibilityAppend, onPasswordVisibilityAppend,
@ -68,6 +71,7 @@ const OutlinedInput: FC<OutlinedInputProps> = (outlinedInputProps) => {
</> </>
); );
}, [initialType, onPasswordVisibilityAppend, type]); }, [initialType, onPasswordVisibilityAppend, type]);
const combinedSx = useMemo( const combinedSx = useMemo(
() => ({ () => ({
color: GREY, color: GREY,
@ -102,6 +106,7 @@ const OutlinedInput: FC<OutlinedInputProps> = (outlinedInputProps) => {
}), }),
[label, sx], [label, sx],
); );
const combinedEndAdornment = useMemo(() => { const combinedEndAdornment = useMemo(() => {
let result; let result;
@ -125,18 +130,33 @@ const OutlinedInput: FC<OutlinedInputProps> = (outlinedInputProps) => {
return result; return result;
}, [passwordVisibilityButton, endAdornment]); }, [passwordVisibilityButton, endAdornment]);
const autofillLock = useMemo<
Pick<MUIOutlinedInputProps, 'onFocus' | 'readOnly'> | undefined
>(
() =>
disableAutofill
? {
onFocus: (...args) => {
const [event] = args;
event.target.readOnly = false;
outlinedInputRestProps?.onFocus?.call(null, ...args);
},
readOnly: true,
}
: undefined,
[disableAutofill, outlinedInputRestProps?.onFocus],
);
return ( return (
<MUIOutlinedInput <MUIOutlinedInput
{...{ endAdornment={combinedEndAdornment}
endAdornment: combinedEndAdornment, label={label}
label, inputProps={{ type, ...inputRestProps }}
inputProps: { {...outlinedInputRestProps}
type, {...autofillLock}
...inputRestProps, sx={combinedSx}
},
...outlinedInputRestProps,
sx: combinedSx,
}}
/> />
); );
}; };

@ -44,7 +44,7 @@ type OutlinedInputWithLabelOptionalProps =
type OutlinedInputWithLabelProps = Pick< type OutlinedInputWithLabelProps = Pick<
OutlinedInputProps, OutlinedInputProps,
'name' | 'onBlur' | 'onChange' | 'onFocus' 'disableAutofill' | 'name' | 'onBlur' | 'onChange' | 'onFocus'
> & > &
OutlinedInputWithLabelOptionalProps & { OutlinedInputWithLabelOptionalProps & {
label: string; label: string;
@ -69,6 +69,7 @@ const OUTLINED_INPUT_WITH_LABEL_DEFAULT_PROPS: Required<OutlinedInputWithLabelOp
const OutlinedInputWithLabel: FC<OutlinedInputWithLabelProps> = ({ const OutlinedInputWithLabel: FC<OutlinedInputWithLabelProps> = ({
baseInputProps, baseInputProps,
disableAutofill,
fillRow: isFillRow = OUTLINED_INPUT_WITH_LABEL_DEFAULT_PROPS.fillRow, fillRow: isFillRow = OUTLINED_INPUT_WITH_LABEL_DEFAULT_PROPS.fillRow,
formControlProps = OUTLINED_INPUT_WITH_LABEL_DEFAULT_PROPS.formControlProps, formControlProps = OUTLINED_INPUT_WITH_LABEL_DEFAULT_PROPS.formControlProps,
helpMessageBoxProps = OUTLINED_INPUT_WITH_LABEL_DEFAULT_PROPS.helpMessageBoxProps, helpMessageBoxProps = OUTLINED_INPUT_WITH_LABEL_DEFAULT_PROPS.helpMessageBoxProps,
@ -148,6 +149,7 @@ const OutlinedInputWithLabel: FC<OutlinedInputWithLabelProps> = ({
{label} {label}
</OutlinedInputLabel> </OutlinedInputLabel>
<OutlinedInput <OutlinedInput
disableAutofill={disableAutofill}
endAdornment={ endAdornment={
<MUIInputAdornment <MUIInputAdornment
position="end" position="end"

Loading…
Cancel
Save