Skip to content

Commit

Permalink
Fix phone example (#36)
Browse files Browse the repository at this point in the history
  • Loading branch information
istarkov committed Sep 9, 2018
1 parent 9b13f38 commit ac31c9b
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
7 changes: 6 additions & 1 deletion docs/readme.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,10 @@ Example of usage with [string-mask](https://github.com/the-darc/string-mask)
</Value>
</Playground>

if replace attribute is defined input will try to skip refused symbols when reached,
like in 2 examples above it skips '-' symbols.
Or example below. Possibly this need additional prop for simplicity


## Masked Phone Input

Expand All @@ -265,7 +269,8 @@ Example of usage with
<Value initial={''}>
{text => (
<Rifm
replace={v => v.length >= 14}
// do not jump after ) until see number before
replace={text.value.length < 6 && (/[^\\d]+/).test(text.value[3]) ? undefined : v => v.length >= 14}
value={text.value}
onChange={text.set}
format={formatPhone}
Expand Down
7 changes: 6 additions & 1 deletion tests/testFlow.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,12 @@ const numberFormat = (str: string) => {
export const TestFlow = () => (
<Value initial={''}>
{text => (
<Rifm value={text.value} onChange={text.set} format={numberFormat}>
<Rifm
replace={undefined}
value={text.value}
onChange={text.set}
format={numberFormat}
>
{({ value, onChange }) => (
<input
value={value}
Expand Down

0 comments on commit ac31c9b

Please sign in to comment.