Skip to content

Commit f4f83ea

Browse files
authored
feat: allow usage without a mask (#99)
1 parent cd000ef commit f4f83ea

File tree

3 files changed

+26
-1
lines changed

3 files changed

+26
-1
lines changed

src/components/MaskedTextInput.test.tsx

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,13 @@ import { Button, Keyboard, InputAccessoryView } from 'react-native';
77
describe('<MaskedTextInput />', () => {
88
const mockedOnChangeText = jest.fn();
99

10+
test('should render correctly without a mask', () => {
11+
const container = render(
12+
<MaskedTextInput value="churrasco" onChangeText={mockedOnChangeText} />,
13+
);
14+
expect(container).toMatchSnapshot();
15+
})
16+
1017
test('should renders correctly with custom mask', () => {
1118
const container = render(
1219
<MaskedTextInput mask="AAA-999" onChangeText={mockedOnChangeText} />,

src/components/MaskedTextInput.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ export const MaskedTextInputComponent: ForwardRefRenderFunction<
6969

7070
const [maskedValue, setMaskedValue] = useState(initialMaskedValue)
7171
const [unMaskedValue, setUnmaskedValue] = useState(initialUnMaskedValue)
72+
const actualValue = pattern || type === "currency" ? maskedValue : unMaskedValue;
7273

7374
function onChange(value: string) {
7475
const newUnMaskedValue = unMask(value, type as 'custom' | 'currency')
@@ -99,7 +100,7 @@ export const MaskedTextInputComponent: ForwardRefRenderFunction<
99100
ref={ref}
100101
maxLength={pattern.length || undefined}
101102
{...rest}
102-
value={maskedValue}
103+
value={actualValue}
103104
style={{...styleSheet} as StyleObj}
104105
/>
105106
{inputAccessoryView}

src/components/__snapshots__/MaskedTextInput.test.tsx.snap

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,22 @@
11
// Jest Snapshot v1, https://goo.gl/fbAQLP
22

3+
exports[`<MaskedTextInput /> should render correctly without a mask 1`] = `
4+
<TextInput
5+
allowFontScaling={true}
6+
onChangeText={[Function]}
7+
rejectResponderTermination={true}
8+
style={
9+
Object {
10+
"fontStyle": undefined,
11+
"fontWeight": undefined,
12+
"textDecorationLine": undefined,
13+
}
14+
}
15+
underlineColorAndroid="transparent"
16+
value="churrasco"
17+
/>
18+
`;
19+
320
exports[`<MaskedTextInput /> should renders correctly with currency mask 1`] = `
421
<TextInput
522
allowFontScaling={true}

0 commit comments

Comments
 (0)