Skip to content

Commit 67ee0d0

Browse files
Merge pull request #508 from web-ridge/copilot/fix-czech-locale-date-format
Fix date truncation for locales with spaces in date format
2 parents 91b9091 + e638095 commit 67ee0d0

2 files changed

Lines changed: 63 additions & 1 deletion

File tree

src/TextInputMask.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ function TextInputWithMask(
8787
onChange={(e) => {
8888
onChange && onChange(e)
8989
}}
90-
maxLength={10}
90+
maxLength={mask.length}
9191
right={inputButton}
9292
/>
9393
)
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
import { render } from '@testing-library/react-native'
2+
import TextInputWithMask from '../TextInputMask'
3+
4+
const noop = () => null
5+
6+
describe('TextInputMask', () => {
7+
it('should set maxLength based on mask length for standard format', () => {
8+
const { getByTestId } = render(
9+
<TextInputWithMask
10+
testID="date-input"
11+
value=""
12+
mask="MM/DD/YYYY"
13+
inputButton={null}
14+
onChangeText={noop}
15+
/>
16+
)
17+
const input = getByTestId('date-input')
18+
expect(input.props.maxLength).toBe(10)
19+
})
20+
21+
it('should set maxLength based on mask length for Czech locale format', () => {
22+
const { getByTestId } = render(
23+
<TextInputWithMask
24+
testID="date-input"
25+
value=""
26+
mask="DD. MM. YYYY"
27+
inputButton={null}
28+
onChangeText={noop}
29+
/>
30+
)
31+
const input = getByTestId('date-input')
32+
expect(input.props.maxLength).toBe(12)
33+
})
34+
35+
it('should set maxLength based on mask length for Hungarian locale format', () => {
36+
const { getByTestId } = render(
37+
<TextInputWithMask
38+
testID="date-input"
39+
value=""
40+
mask="YYYY. MM. DD."
41+
inputButton={null}
42+
onChangeText={noop}
43+
/>
44+
)
45+
const input = getByTestId('date-input')
46+
expect(input.props.maxLength).toBe(13)
47+
})
48+
49+
it('should set maxLength based on mask length for German locale format', () => {
50+
const { getByTestId } = render(
51+
<TextInputWithMask
52+
testID="date-input"
53+
value=""
54+
mask="DD.MM.YYYY"
55+
inputButton={null}
56+
onChangeText={noop}
57+
/>
58+
)
59+
const input = getByTestId('date-input')
60+
expect(input.props.maxLength).toBe(10)
61+
})
62+
})

0 commit comments

Comments
 (0)