Skip to content

Commit

Permalink
IBX-4791: [Date picker] Cannot open date time picker by clicking on c…
Browse files Browse the repository at this point in the history
…alendar icon in the input (#678)
  • Loading branch information
GrabowskiM authored Feb 15, 2023
1 parent 58b070d commit 6d2074a
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 4 deletions.
11 changes: 11 additions & 0 deletions src/bundle/Resources/public/js/scripts/core/date.time.picker.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,14 @@
time_24hr: true,
formatDate: (date) => formatShortDateTime(date, null),
};

class DateTimePicker {
constructor(config) {
this.container = config.container;
this.fieldWrapper = this.container.querySelector('.ibexa-date-time-picker');
this.inputField = this.fieldWrapper.querySelector('.ibexa-date-time-picker__input');
this.actionsWrapper = this.fieldWrapper.querySelector('.ibexa-input-text-wrapper__actions');
this.calendarBtn = this.actionsWrapper.querySelector('.ibexa-input-text-wrapper__action-btn--calendar');
this.clearBtn = this.fieldWrapper.querySelector('.ibexa-input-text-wrapper__action-btn--clear');
this.customOnChange = config.onChange;

Expand All @@ -23,6 +26,7 @@
...DEFAULT_CONFIG,
inline: this.fieldWrapper.classList.contains('ibexa-date-time-picker--inline-datetime-popup'),
onChange: this.onChange,
ignoredFocusElements: [this.actionsWrapper],
...(config.flatpickrConfig ?? {}),
};

Expand Down Expand Up @@ -95,6 +99,13 @@
this.flatpickrInstance = flatpickr(this.inputField, this.flatpickrConfig);

this.inputField.addEventListener('input', this.onInput, false);
this.calendarBtn.addEventListener(
'click',
() => {
this.flatpickrInstance.open();
},
false,
);

if (this.flatpickrInstance.config.enableTime) {
this.flatpickrInstance.minuteElement.addEventListener('keyup', this.onKeyUp.bind(this, true), false);
Expand Down
24 changes: 22 additions & 2 deletions src/bundle/Resources/public/scss/_date-time-picker.scss
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,10 @@
width: 100%;
}

.ibexa-input-text-wrapper__actions {
top: calculateRem(24px);
.ibexa-input-text-wrapper {
&__actions {
top: calculateRem(24px);
}
}

&--small {
Expand All @@ -35,5 +37,23 @@
margin-bottom: calculateRem(4px);
}
}

.ibexa-input-text-wrapper__action-btn--calendar {
&:hover {
.ibexa-icon {
fill: $ibexa-color-dark;
}
}

&:focus {
color: transparent;
border-color: transparent;
box-shadow: none;

.ibexa-icon {
fill: $ibexa-color-dark;
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,13 @@
{% endblock %}
{% block actions %}
{{ parent() }}
<div class="ibexa-input-text-wrapper__action-btn">
<button
type="button"
class="btn ibexa-btn ibexa-btn--ghost ibexa-btn--no-text ibexa-input-text-wrapper__action-btn ibexa-input-text-wrapper__action-btn--calendar"
>
<svg class="ibexa-icon ibexa-icon--small">
<use xlink:href="{{ ibexa_icon_path('date') }}"></use>
</svg>
</div>
</button>
{% endblock %}
{% endembed %}

0 comments on commit 6d2074a

Please sign in to comment.