From 2d3fe8f7790646373e3774a770e24ffdd71b65d9 Mon Sep 17 00:00:00 2001 From: Yury Uvarov Date: Mon, 2 Oct 2023 15:05:15 +0300 Subject: [PATCH] fix selection --- package/src/scripts/helpers/getColumnID.ts | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/package/src/scripts/helpers/getColumnID.ts b/package/src/scripts/helpers/getColumnID.ts index dc799743..7807665d 100644 --- a/package/src/scripts/helpers/getColumnID.ts +++ b/package/src/scripts/helpers/getColumnID.ts @@ -2,17 +2,11 @@ import { IVanillaCalendar } from '../../types'; const getColumnID = (self: IVanillaCalendar, columnClass: string, personalClass: string, id: number, dataAttr: string) => { const columnEls = (self.HTMLElement as HTMLElement).querySelectorAll(`.${self.CSSClasses.column}`) as NodeListOf; - const firstColumnID = Number((columnEls[0].querySelector(`.${personalClass}`) as HTMLElement).getAttribute(dataAttr)); - const lastColumnID = Number((columnEls[columnEls.length - 1].querySelector(`.${personalClass}`) as HTMLElement).getAttribute(dataAttr)); const indexColumn = [...columnEls].findIndex((column) => column.classList.contains(columnClass)); + const currentValue = Number((columnEls[indexColumn].querySelector(`.${personalClass}`) as HTMLElement).getAttribute(dataAttr)); - if (firstColumnID === lastColumnID || indexColumn < 0) { - return id; - } - - if (firstColumnID < lastColumnID || (self.currentType !== 'year' && firstColumnID > lastColumnID)) { - return id - indexColumn; - } + if (self.currentType === 'month' && indexColumn >= 0) return id - indexColumn; + if (self.currentType === 'year' && self.selectedYear !== currentValue) return id - 1; return id; };