Skip to content

Commit

Permalink
Merge pull request #135 from uvarov-frontend/hotfix/input_position
Browse files Browse the repository at this point in the history
Hotfix/input position
  • Loading branch information
uvarov-frontend authored Oct 12, 2023
2 parents 7916a4a + 19d12e3 commit af96831
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 7 deletions.
2 changes: 1 addition & 1 deletion demo/index.css
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
}

.wrapper-calendar {
@apply w-[550px] max-w-max justify-center items-center flex flex-col mb-4
@apply w-[550px] max-w-max justify-center items-center flex flex-col mb-4 relative
}

.input {
Expand Down
12 changes: 8 additions & 4 deletions package/src/scripts/methods/handlerInput.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,18 @@ import resetCalendar from './resetCalendar';

let currentSelf: null | IVanillaCalendar = null;

const setPositionCalendar = (input: HTMLInputElement, calendar: HTMLElement) => {
const inputInfo = input.getBoundingClientRect();
calendar.style.left = `${inputInfo.left}px`;
calendar.style.top = `${inputInfo.top + inputInfo.height}px`;
};

const createCalendarToInput = (self: IVanillaCalendar) => {
if (!self.HTMLInputElement) return;

const calendar = document.createElement('div');
calendar.className = `${self.CSSClasses.calendar} ${self.CSSClasses.calendarToInput} ${self.CSSClasses.calendarHidden}`;
calendar.style.left = `${self.HTMLInputElement.offsetLeft}px`;
calendar.style.top = `${self.HTMLInputElement.offsetTop + self.HTMLInputElement.clientHeight}px`;
setPositionCalendar(self.HTMLInputElement, calendar);
self.HTMLElement = calendar;
document.body.append(self.HTMLElement);

Expand All @@ -35,8 +40,7 @@ const handlerInput = (self: IVanillaCalendar) => {

self.HTMLInputElement.addEventListener('click', () => {
if (self.HTMLElement && self.HTMLInputElement) {
self.HTMLElement.style.left = `${self.HTMLInputElement.offsetLeft}px`;
self.HTMLElement.style.top = `${self.HTMLInputElement.offsetTop + self.HTMLInputElement.clientHeight}px`;
setPositionCalendar(self.HTMLInputElement, self.HTMLElement);
self.HTMLElement.classList.remove(self.CSSClasses.calendarHidden);
} else if (self.HTMLElement) {
self.HTMLElement.classList.remove(self.CSSClasses.calendarHidden);
Expand Down
2 changes: 1 addition & 1 deletion package/src/styles/vanilla-calendar.css
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
.vanilla-calendar {
@apply p-4 rounded-xl opacity-100 transition-all relative flex flex-col min-w-[275px] max-w-full h-max
@apply p-4 rounded-xl opacity-100 transition-opacity relative flex flex-col min-w-[275px] max-w-full h-max
}

.vanilla-calendar button:focus-visible {
Expand Down
2 changes: 1 addition & 1 deletion tailwind.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
/** @type {import('tailwindcss').Config} */
module.exports = {
content: [
'./demo/index.html',
'./demo/**/*.{html,css}',
'./src/**/*.{js,ts}',
],
theme: {
Expand Down

0 comments on commit af96831

Please sign in to comment.