vanilla-calendar-pro
vanilla-calendar-pro copied to clipboard
Add gotoSelection
For number 2, I guess something along these lines would probably work... I cloned your repo and tested it, it works. As I mentioned earlier, you could also add an extra option flag if you don't want this to be the default behavior. This is just a suggestion and you could implement it in many different ways, though it would be great to have this kind of enhancement :)
const initSelectedMonthYear = (self: VanillaCalendar) => {
+ if (self.settings.selected.dates?.length && (self.settings.selected.month === undefined && self.settings.selected.year === undefined)) {
+ const selectedDate = getDate(parseDates(self.settings.selected.dates)[0]);
+ self.settings.selected.month = selectedDate.getMonth();
+ self.settings.selected.year = selectedDate.getFullYear();
+ }
const isValidMonth = self.settings.selected.month !== undefined && Number(self.settings.selected.month) >= 0 && Number(self.settings.selected.month) < 12;
const isValidYear = self.settings.selected.year !== undefined && Number(self.settings.selected.year) >= 0 && Number(self.settings.selected.year) <= 9999;
self.selectedMonth = isValidMonth ? Number(self.settings.selected.month) : self.date.today.getMonth();
self.selectedYear = isValidYear ? Number(self.settings.selected.year) : self.date.today.getFullYear();
self.viewYear = self.selectedYear;
};
Originally posted by @ghiscoding in https://github.com/uvarov-frontend/vanilla-calendar-pro/discussions/244#discussioncomment-9027483