Skip to content

Commit

Permalink
Merge pull request #120 from uvarov-frontend/hotfix/year_selection_in…
Browse files Browse the repository at this point in the history
…_type_multiple

Fix year selection in type: 'multiple'
  • Loading branch information
uvarov-frontend authored Oct 2, 2023
2 parents ce16c32 + 2d3fe8f commit ae9a498
Showing 1 changed file with 3 additions and 9 deletions.
12 changes: 3 additions & 9 deletions package/src/scripts/helpers/getColumnID.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<HTMLElement>;
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;
};
Expand Down

0 comments on commit ae9a498

Please sign in to comment.