react-component / m-calendar

React Mobile Calendar Component (web)
https://react-component.github.io/m-calendar/
38 stars 31 forks source link

type为range ,defatultValue值在初始化就传入的时候,没有选中 #15

Open allroad88888888 opened 5 years ago

allroad88888888 commented 5 years ago

如题

lilbumblebear commented 5 years ago

It seems like this is caused because the constructor calls this.selectDate, but when the visibility changes it calls this.shortcutSelect, which sets the values correctly. Is there a reason that this.shortcutSelect is not called in the constructor?

lilbumblebear commented 5 years ago

I hacked a fix by wrapping the mobile calendar like below

import React from "react";
import {Calendar} from 'antd-mobile';

export default class MobileCalendar extends React.Component {
    constructor(props) {
        super(props);
        this.state = {
            visible: false,
        };
    }

    componentDidMount(){
        this.setState({
            visible: true
        })
    }

    render() {
        const { ...props } = this.props;
        return (
            <Calendar {...props} visible={this.state.visible}/>
        );
    }
}