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

Form Stepper demo and a bug fix #4021

Merged
merged 2 commits into from
Sep 23, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/components/form/demos/demo1.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
DatePicker,
Selector,
Slider,
Stepper,
} from 'antd-mobile'
import { DemoBlock } from 'demos'
import dayjs from 'dayjs'
Expand Down Expand Up @@ -83,6 +84,9 @@ export default () => {
<Form.Item name='slider-demo' label='滑块选择'>
<Slider ticks step={10} />
</Form.Item>
<Form.Item name='stepper-demo' label='数量'>
<Stepper />
</Form.Item>
<Form.Item name='disabledField' label='禁用' disabled>
<Input placeholder='禁止输入' />
</Form.Item>
Expand Down
9 changes: 6 additions & 3 deletions src/components/stepper/stepper.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,6 @@ export const Stepper = withDefaultProps(defaultProps)<StepperProps>(props => {
target = parseFloat(target.toFixed(props.digits))
}
setValue(target)
if (!hasFocus) {
setInputValue(target.toString())
}
}

const [hasFocus, setHasFocus] = useState(false)
Expand All @@ -52,6 +49,12 @@ export const Stepper = withDefaultProps(defaultProps)<StepperProps>(props => {
}
}, [hasFocus])

useEffect(() => {
if (!hasFocus) {
setInputValue(value.toString())
}
}, [value])

const handleInputChange = (v: string) => {
setInputValue(v)
setValueWithCheck(parseFloat(v))
Expand Down