Skip to content

Commit

Permalink
fix: inputNumber focus
Browse files Browse the repository at this point in the history
  • Loading branch information
yang authored and yang committed May 21, 2021
1 parent be31f7c commit 33e76d1
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions packages/zarm/src/input/InputNumber.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export default class InputNumber extends Component<InputNumberProps, any> {

componentDidMount() {
const { autoFocus, focused } = this.props;
Events.on(document.body, 'click', this.onMaskClick);
this.addBlurListener();

if (autoFocus || focused) {
this.onFocus();
Expand All @@ -57,9 +57,17 @@ export default class InputNumber extends Component<InputNumberProps, any> {
}

componentWillUnmount() {
Events.off(document.body, 'click', this.onMaskClick);
this.removeBlurListener();
}

addBlurListener = () => {
Events.on(document.body, 'click', this.onMaskClick);
};

removeBlurListener = () => {
Events.off(document.body, 'click', this.onMaskClick);
};

onMaskClick = (e) => {
const clsRegExp = new RegExp(`(^|\\s)${this.picker.props.prefixCls}(\\s|$)`, 'g');
if (!this.state.visible || this.state.focused) {
Expand Down Expand Up @@ -156,7 +164,11 @@ export default class InputNumber extends Component<InputNumberProps, any> {
};

focus = () => {
this.removeBlurListener();
this.onFocus();
setTimeout(() => {
this.addBlurListener();
}, 50);
};

blur = () => {
Expand Down

0 comments on commit 33e76d1

Please sign in to comment.