Skip to content

Commit

Permalink
Fix: Broken layout on some locales due to special characters
Browse files Browse the repository at this point in the history
  • Loading branch information
sandypockets committed Dec 8, 2023
1 parent e4e5cb6 commit 137c8de
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 7 deletions.
2 changes: 1 addition & 1 deletion dist/datepicker.bundle.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/datepicker.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "easy-dates-picker",
"version": "0.0.19",
"version": "0.0.20",
"description": "A super lightweight vanilla JS date picker",
"main": "dist/datepicker.bundle.js",
"files": [
Expand Down
13 changes: 10 additions & 3 deletions src/datePicker.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,13 @@ export default function DatePicker(elementId, options) {
this.render();
attachEventListeners(this.element, this.changeMonth.bind(this), this.handleDayClick.bind(this));
};
this.localizedDate = function (date, locale) {
return date.toLocaleDateString(locale, {
year: 'numeric',
month: 'long',
day: 'numeric',
});
};

this.render = function () {
this.element.innerHTML = '';
Expand All @@ -42,11 +49,11 @@ export default function DatePicker(elementId, options) {

if (this.selectedStartDate) {
if (this.options.mode === 'single') {
input.value = this.selectedStartDate.toDateString();
input.value = this.localizedDate(this.selectedStartDate, this.options.language);
} else if (this.options.mode === 'range') {
let inputValue = this.selectedStartDate.toDateString();
let inputValue = this.localizedDate(this.selectedStartDate, this.options.language);
if (this.selectedEndDate) {
inputValue += ` - ${this.selectedEndDate.toDateString()}`;
inputValue += ` - ${this.localizedDate(this.selectedEndDate, this.options.language)}`;
}
input.value = inputValue;
}
Expand Down
2 changes: 1 addition & 1 deletion src/generateCalendarContainer.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { ariaLabels } from './localization';

export function generateCalendarContainer(currentDate, isDateSelected, isDateInRange, options) {
const container = document.createElement('div');
container.className = 'datepicker-calendar-container';
container.className = `datepicker-calendar-container ${options?.language}`;
container.style.display = options.textInputEnabled ? 'none' : 'block';
container.innerHTML = `
<div class="datepicker-header">
Expand Down
30 changes: 30 additions & 0 deletions src/styles/datepicker.css
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,33 @@
.datepicker-day > span {
display: block;
}

.ja .datepicker-calendar-container {
height: 385px;
}

.ja .datepicker-day {
cursor: pointer;
height: 50px;
font-size: smaller;
display: flex;
justify-content: center;
align-items: center;
border-radius: 0;
}

.zh-CN .datepicker-calendar-container,
.zh-TW .datepicker-calendar-container {
height: 385px;
}

.zh-CN .datepicker-day,
.zh-TW .datepicker-day {
cursor: pointer;
height: 50px;
font-size: smaller;
display: flex;
justify-content: center;
align-items: center;
border-radius: 0;
}

0 comments on commit 137c8de

Please sign in to comment.