chrisdavies / tiny-date-picker

A small, modern, dependency-free date picker
https://chrisdavies.github.io/tiny-date-picker/
415 stars 87 forks source link

el.close() doesn't work #46

Closed cmnstmntmn closed 7 years ago

cmnstmntmn commented 7 years ago

is there a way to close the calendar box?

el.open() works as expected on the other hand

chrisdavies commented 7 years ago

Hm. It's not exposed programmatically, which is dumb on my part, since open is exposed. The other dumb thing is that close is a string (used for localization of the "Close" button text. So, changing close to be a function is a breaking change, though probably not a big one, since it's unlikely that anyone is using the context.close other than internal code.

I'll try to have this exposed by Monday. (Kind of in a busy period on other projects.)

chrisdavies commented 7 years ago

Yes. I think if you set focus to anything else on the page, the modal should close, so that's a hacky workaround for now.

chrisdavies commented 7 years ago

Finally got some spare time to look into this. You're right. It was documented in the readme but unsupported by the API. Added it to the API. Let me know if you run into any problems!

techpines commented 7 years ago

Just ran into this bug as well. The fix does seem to work, thanks!

stalkerg commented 7 years ago

it's not working for me.

stalkerg commented 7 years ago

because for modal dialog you just not call hideCalendar:

close: function () {
      if (context.el) {
        returnFocusFromModal(input);

        // For dropdown calendars, we need to allow the focus
        // event to play out before hiding, or else the focus
        // event will re-show the calendar.
        context.isBelow && buffer(10, function () {
          hideCalendar(context);
        })();
      }
    },

in my case, I just back to the previous page by extra mouse button and dialog didn't hide.

warmwhisky commented 7 years ago

So how do I get this to close? It does not close when I click the close button or when I click a date.

The examples in the readme didn't work, so I used the html in the tests folder and the initializing js from there, still no close.

stalkerg commented 7 years ago

So how do I get this to close?

My stupid solution:

const modal = document.querySelector('.dp-modal');
if (modal != null) {
  modal.parentNode.removeChild(modal);
}
chrisdavies commented 7 years ago

Hm... What browser are you using?

I have an update coming that will hopefully fix this, but it's a different major version. I'd like v2 to be bug free, too, at least on major features like this.

On Mon, Sep 11, 2017 at 3:00 AM, Yury Zhuravlev notifications@github.com wrote:

So how do I get this to close?

My stupid solution:

const modal = document.querySelector('.dp-modal');if (modal != null) { modal.parentNode.removeChild(modal); }

— You are receiving this because you modified the open/close state. Reply to this email directly, view it on GitHub https://github.com/chrisdavies/tiny-date-picker/issues/46#issuecomment-328435469, or mute the thread https://github.com/notifications/unsubscribe-auth/AAy3YVsuiEOyLnkZBwh3i-EVRQMHV2sIks5shNqegaJpZM4Owzf0 .

chrisdavies commented 7 years ago

I've released a new version of the date picker (mostly a big code refactor and some API cleanup). If you were using all of the features / options in v2, there are some breaking changes, but not too many.

It has some good tests behind it, including around the close scenario. (Though close also seemed to work in v2 in my local box and test environments.)

Maybe give v3 a spin and see if it works for you.

ryanlitalien commented 7 years ago

@chrisdavies I tried out 3.0 and there was a breaking change of "setValue" not being available. Could you update the docs on conversion from 2.x -> 3.x? I understand where you're going with setting state (React), but could you help document the transition?

chrisdavies commented 7 years ago

@ryanlitalien Did npm auto-upgrade you? (I hope not, as it is a major version change.)

Here's the guide:

https://github.com/chrisdavies/tiny-date-picker/wiki/Changes-from-2.0-to-3.0

I'm sorry for the hassle of breaking changes. I was going to try to keep the API backwards compatible, as 3.x originated simply as a code-cleanup task. 2.x and previous were written as an experiment in minimizing size and dependencies with no thought for code-quality or long-term usage at all.

3.x cleaned up a lot of internals. But I also realized I had made some pretty bad API choices in 2.x, such as conflating language options with general options. I tried to make 3.x have a more consistent and general API... I hope I succeeded... and I hope it's worth the breaking changes!

stalkerg commented 7 years ago

I can try on the next week.