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(InputMasked): updating value from undefined to 0 should work #4090

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import React, { useState } from 'react'
import { Wrapper, Box } from 'storybook-utils/helpers'
import emailMask from '../addons/emailMask'
import { InputMasked, FormSet, ToggleButton } from '../..'
import { InputMasked, FormSet, ToggleButton, Button } from '../..'
import { Hr } from '../../..'
import styled from '@emotion/styled'
import { Provider } from '../../../shared'
Expand Down Expand Up @@ -330,3 +330,71 @@ function MultiInputMaskStatuses() {
</>
)
}

function Test({ form }) {
return (
<InputMasked
as_percent
on_change={({ numberValue }: { numberValue: number }) =>
console.log('hello')
}
value={form.value}
/>
)
}

export function State0ExternalComp() {
const [form, setForm] = useState({ value: undefined })
return (
<div id="div">
<Test form={form} />
<br />
<Button
style={{ backgroundColor: 'red' }}
onClick={() => setForm({ value: 0 })}
text="click me"
/>
</div>
)
}

export function State0InternalComp() {
function TestInternal({ form }) {
return (
<InputMasked
as_percent
on_change={({ numberValue }: { numberValue: number }) =>
console.log('hello')
}
value={form.value}
/>
)
}
const [form, setForm] = useState({ value: undefined })
return (
<div id="div">
<TestInternal form={form} />
<br />
<Button
style={{ backgroundColor: 'red' }}
onClick={() => setForm({ value: 0 })}
text="click me"
/>
</div>
)
}

export function State1() {
const [form, setForm] = useState({ value: undefined })
return (
<div id="div">
<Test form={form} />
<br />
<Button
style={{ backgroundColor: 'red' }}
onClick={() => setForm({ value: 1 })}
text="click me"
/>
</div>
)
}
Loading