Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IBX-4791: [Date picker] Cannot open date time picker by clicking on calendar icon in the input #678

Merged
merged 6 commits into from
Feb 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 %}