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

Does show prop still work? #57

Open
sudravi opened this issue Jul 1, 2020 · 1 comment
Open

Does show prop still work? #57

sudravi opened this issue Jul 1, 2020 · 1 comment

Comments

@sudravi
Copy link

sudravi commented Jul 1, 2020

In the Code Sandbox link below, if you set react-month-picker version greater than or equal to 2.0.1, show prop doesn't work anymore.

https://codesandbox.io/s/holy-lake-636cb?file=/src/index.js

@mdrayer
Copy link

mdrayer commented Sep 29, 2020

That's what it seems like to me. You will need to call the show() method via refs. For example:

import React from 'react';
import MonthPicker from 'react-month-picker';

const Example = () => {
  const [yearMonth, setYearMonth] = React.useState({ year: 2020, month: 9 });
  const monthPickerRef = React.useRef<MonthPicker>(null);

  const showPicker = () => {
    if (monthPickerRef && monthPickerRef.current) {
      monthPickerRef.current.show();
    }
  };

  const handlePickerChange = (year: number, month: number) => {
    setYearMonth({ year, month });
  };

  return (
    <MonthPicker
      ref={monthPickerRef}
      value={yearMonth}
      onChange={handlePickerChange}
    >
      <span onClick={showPicker}>
        {yearMonth.month} {yearMonth.year}
      </span>
    </MonthPicker>
  );
};

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants