Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: mui textfield disappearing #95

Merged
merged 13 commits into from
Nov 22, 2024
2 changes: 1 addition & 1 deletion examples/vite-project/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 13 additions & 3 deletions src/useHookFormMask.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import inputmask from 'inputmask';
import { RefCallback } from 'react';
import {
FieldValues, Path, UseFormRegister, RegisterOptions,
FieldValues, Path,
RegisterOptions,
UseFormRegister,
} from 'react-hook-form';
import { flow, getMaskOptions } from './utils';
import { Mask, Options } from './types';
import { flow, getMaskOptions } from './utils';

export function useHookFormMask<
T extends FieldValues, D extends RegisterOptions,
Expand All @@ -17,7 +19,15 @@ export function useHookFormMask<
const maskInput = inputmask(getMaskOptions(mask, options as any));

const newRef = flow((_ref: HTMLElement) => {
if (_ref) maskInput.mask(_ref);
if (_ref) {
const { nodeName } = _ref;

if (nodeName !== 'INPUT') {
maskInput.mask(_ref.querySelector('input') as HTMLElement);
} else {
maskInput.mask(_ref);
}
}
return _ref;
}, ref) as RefCallback<HTMLElement>;

Expand Down
1 change: 1 addition & 0 deletions src/utils/getMaskOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ export const getMaskOptions = (mask?: Mask, _options?: Options): Options => {
},

// alias for brazilians <3
// ty <3
'brl-currency': {
alias: 'currency',
prefix: 'R$ ',
Expand Down
Loading