Skip to content
New issue

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

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

Already on GitHub? # to your account

EZP-31347: Added functionality to show dropdown above select field #1218

Merged
Merged
Changes from 2 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
15 changes: 13 additions & 2 deletions src/bundle/Resources/public/js/scripts/core/custom.dropdown.js
Original file line number Diff line number Diff line change
@@ -2,6 +2,7 @@
const CLASS_CUSTOM_DROPDOWN = 'ez-custom-dropdown';
const CLASS_CUSTOM_DROPDOWN_ITEM = 'ez-custom-dropdown__item';
const CLASS_ITEMS_HIDDEN = 'ez-custom-dropdown__items--hidden';
const CLASS_ITEMS_POSITION_TOP = 'ez-custom-dropdown__items--position-top';
const CLASS_REMOVE_SELECTION = 'ez-custom-dropdown__remove-selection';
const CLASS_ITEM_SELECTED_IN_LIST = 'ez-custom-dropdown__item--selected';
const SELECTOR_ITEM = '.ez-custom-dropdown__item';
@@ -10,6 +11,7 @@
const SELECTOR_SELECTION_INFO = '.ez-custom-dropdown__selection-info';
const SELECTOR_PLACEHOLDER = '[data-value=""]';
const EVENT_VALUE_CHANGED = 'valueChanged';
const ITEMS_LIST_MAX_HEIGHT = 300;

class CustomDropdown {
constructor(config) {
@@ -131,10 +133,19 @@
return;
}

const methodName = this.itemsContainer.classList.contains(CLASS_ITEMS_HIDDEN) ? 'addEventListener' : 'removeEventListener';
const isListHidden = this.itemsContainer.classList.contains(CLASS_ITEMS_HIDDEN);
const bodyMethodName = isListHidden ? 'addEventListener' : 'removeEventListener';

if (isListHidden) {
const viewportHeight = window.innerHeight || document.documentElement.clientHeight;
const { top } = this.itemsContainer.getBoundingClientRect();
const itemsListMethodName = top + ITEMS_LIST_MAX_HEIGHT > viewportHeight ? 'add' : 'remove';

this.itemsContainer.classList[itemsListMethodName](CLASS_ITEMS_POSITION_TOP);
}

this.itemsContainer.classList.toggle(CLASS_ITEMS_HIDDEN);
doc.body[methodName]('click', this.onClickOutside, false);
doc.body[bodyMethodName]('click', this.onClickOutside, false);
}

onOptionClick({ target }) {
8 changes: 7 additions & 1 deletion src/bundle/Resources/public/scss/core/_custom.dropdown.scss
Original file line number Diff line number Diff line change
@@ -110,7 +110,7 @@
top: 100%;
transform: scaleY(1);
transform-origin: top center;
transition: all 0.2s $ez-admin-transition;
transition: transform 0.2s $ez-admin-transition;
width: 50%;
border: calculateRem(1px) solid $ez-ground-primary;
background: $ez-white;
@@ -121,6 +121,12 @@
&--hidden {
transform: scaleY(0);
}

&--position-top {
top: initial;
bottom: 100%;
transform-origin: bottom center;
}
}

&__item {
Original file line number Diff line number Diff line change
@@ -8,6 +8,8 @@
&__items {
border: none;
box-shadow: 0 calculateRem(2px) calculateRem(4px) 0 rgba(0, 0, 0, 0.45);
max-height: calculateRem(300px);
overflow-y: scroll;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

always scroll? I think better will be auto

}

&__item {