Skip to content

Commit

Permalink
fix(InputMask): fixes defaultValue
Browse files Browse the repository at this point in the history
  • Loading branch information
aditya-kumawat committed Aug 24, 2020
1 parent c1e4bcd commit 3fa730f
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
13 changes: 11 additions & 2 deletions core/components/molecules/inputMask/InputMask.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,18 @@ export interface MaskProps extends BaseProps {
onClear?: (e: React.MouseEvent<HTMLElement>) => void;
}
export type InputMaskProps = InputProps & MaskProps;

/**
* InputMask works as uncontrolled component
* It works as Uncontrolled Input
*
* **Updated value can be passed**
*/
export const InputMask = React.forwardRef<HTMLInputElement, InputMaskProps>((props, forwardRef) => {
const {
mask: maskProp,
value: valueProp,
defaultValue,
placeholderChar = '_',
defaultValue,
mask,
error,
caption,
Expand All @@ -59,6 +62,12 @@ export const InputMask = React.forwardRef<HTMLInputElement, InputMaskProps>((pro
setCaretPos(caret);
}, [caret]);

React.useEffect(() => {
if (ref.current && valueProp) {
setValue(convertToMasked(valueProp));
}
}, [valueProp]);

React.useEffect(() => {
if (ref.current) {
const el = ref.current;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ export const all = () => {
'value',
''
);
const defaultvalue = text(
'defaultvalue',
const defaultValue = text(
'defaultValue',
''
);

Expand Down Expand Up @@ -78,7 +78,7 @@ export const all = () => {
name="input"
type={inputType}
value={value}
defaultValue={defaultvalue}
defaultValue={defaultValue}
disabled={disabled}
onChange={action('on-change')}
onClick={action('on-click')}
Expand Down

0 comments on commit 3fa730f

Please sign in to comment.