uvarov-frontend / vanilla-calendar-pro

Vanilla Calendar is a versatile JavaScript date and time picker with TypeScript support, making it compatible with any JavaScript framework or library. It is designed to be lightweight, simple to use, and feature-rich without relying on external dependencies.
https://vanilla-calendar.pro
MIT License
445 stars 58 forks source link

Fix: set minimum width for the calendar 300 #301

Closed roberbnd closed 1 week ago

roberbnd commented 1 month ago

What Add 300 as minimum value for the width in the calendar div

Why calendar.clientWidth was returning 0

uvarov-frontend commented 1 month ago

Hello, thank you for your contribution. Please explain why you need a manually set width? In what cases can ‘calendar.clientWidth’ be 0? I think we need to deal with this and find out the reason and fix it, instead of specifying the width manually.

roberbnd commented 1 month ago

In what cases can ‘calendar.clientWidth’ be 0? In the first render, when you create the calendar

calendar comes from an empty div image

only I am using the value already used in the class .vanilla-calendar image

ghiscoding commented 1 month ago

@roberbnd Do you mean that you're trying to use it inside a newly created modal window and the date picker client width is 0, is that the problem that you're having?

roberbnd commented 1 month ago

@ghiscoding I have the same issue that you fixed: calendar outside of the viewport

I tested your change with slickgrid and still there in the first render.

calendar.clientWidth returns 0 then left + 0 > vw is going to return false when at least we have 300px of width for the calendar

ghiscoding commented 1 month ago

I think the question would be why is the width ever at 0px? Also why did you decide on 300px, the picker is 272px when I query it.

What offsetWidth, is it also 0px? Per this Stack Overflow answer, it looks like we should maybe switch to offsetWidth

The Element.clientWidth property is zero for elements with no CSS or inline layout boxes, otherwise it's the inner width of an element in pixels

roberbnd commented 1 month ago

@ghiscoding why is the width ever at 0px? no always, only in the first render when the code needs to calculate the position, I see the same issue image

why did you decide on 300px, the picker is 272px when I query it. here 272px is the min-width allowed but the width assigned to calendar is 300px image

What offsetWidth, is it also 0px? yes, it is 0px

ghiscoding commented 1 month ago

I'm surprised that .offsetWidth doesn't work, but there's still other things you could try, however both of these other methods will return a string with the px suffix (like "272px" instead of the number 272) so if that works you will have to parse it

window.getComputedStyle(elm).width; // or clientWidth or offsetWidth

// or
elm.getBoundingClientRect().width;

if that also doesn't work then I'm out of idea

uvarov-frontend commented 1 month ago

@roberbnd I'm very interested in looking at the source code and finding out why this happens. Will you be able to reproduce this issue on the codesandbox.io or any other sandbox? Thanks in advance for your time in troubleshooting this issue.

uvarov-frontend commented 1 month ago

@ghiscoding My friend, how can I contact you directly and ask a couple of questions about the calendar? Will you be able to write to me on telegram? Link in my profile.

ghiscoding commented 1 month ago

@uvarov-frontend would it be possible to discuss it just in GitHub? You can open a discussion on one of the project I use your calendar if you want, it's Slickgrid-Universal. I would prefer GitHub mostly because it's easier to share code, I don't use telegram so much and certainly not on the computer. Unless you had something more personal to ask?

uvarov-frontend commented 1 week ago

@ghiscoding I have a couple of personal questions about the project, or more precisely about how best to implement v3.0.0, which I wanted to discuss in private messages. But if this is not possible, don't worry. :)

uvarov-frontend commented 1 week ago

@roberbnd Thanks for your time and input, but I don't think this PR is suitable for everyone who uses this calendar.