2017-12-12 5 views

答えて

0

1を閉じる必要があります

 let comp = modal ? 
      <div className={styles.calendarInput}> 
       <span onClick={toogleCalendar}>{value ? Dates.format(date, Dates.formats.americanMediumDate) : null}</span> 
       <div className={visible ? '_common_form__show' : '_common_form__hidden'}> 
        {calendar} 
       </div> 
      </div>: 
      calendar; 
     return (
      <div> 
       <label><Label config={{label, helpText}} /></label> 
       {comp} 
      </div> 
     ); 
    }; 

    const CalendarExtended = compose(
     withState('visible', 'setVisible', false), 
     withHandlers({ 
      toogleCalendar: ({setVisible, visible}) =>() => { 
       setVisible(!visible); 
      } 
     }) 
    )(Calendar);. 

..ユーザーは画面上の任意の場所をクリックした場合ときに、カレンダーを閉じたい、我々はクリックでクラスをベースと得ることができます部門外のイベント。 2)デフォルトでは、カレンダークラスの状態はtrueになり、外側をクリックするとfalseに設定されます。これが役立ちます。

constructor(props) { 
 
    super(props); 
 
    this.state = { 
 
     isOpen: true 
 
    }; 
 
    } 
 
    
 
handleClick = (e) => { 
 
    if (this.toogleCalendarClass && 
 
     !this.toogleCalendarClass.contains(e.target)) { 
 
     this.setState({ isOpen: false}); 
 
    } 
 
    } 
 

 

 
componentWillMount =() => { 
 
    document.addEventListener('click', this.handleClick); 
 
    } 
 

 
    componentWillUnmount =() => { 
 
    document.removeEventListener('click', this.handleClick); 
 
    } 
 

 

 
this.toogleCalendarClass = null; 
 
let comp = modal ? 
 
      <div className={styles.calendarInput}> 
 
       <span onClick={toogleCalendar} ref={(input) => { 
 
      this.toogleCalendarClass = input; 
 
     } 
 
     }>{value ? Dates.format(date, Dates.formats.americanMediumDate) : null}</span> 
 
     
 
       <div className={`visible ${this.state.isOpen ? '_common_form__show' : '_common_form__hidden'}`}> 
 
        {calendar} 
 
       </div> 
 
      </div>: 
 
      calendar; 
 
     return (
 
      <div> 
 
       <label><Label config={{label, helpText}} /></label> 
 
       {comp} 
 
      </div> 
 
     ); 
 
    }; 
 

 
    const CalendarExtended = compose(
 
     withState('visible', 'setVisible', false), 
 
     withHandlers({ 
 
      toogleCalendar: ({setVisible, visible}) =>() => { 
 
       setVisible(!visible); 
 
      } 
 
     }) 
 
    )(Calendar);

+0

コードは、私はすでに別のファイルに自分のコンストラクタを定義しだってとにかく大きな助けのためthankss ..少しスニペットを追加した後、正常に動作します。.. –

関連する問題