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

EZP-32311: Dropdown bottom options become inaccessible inside modals #1709

Merged
merged 3 commits into from
Feb 22, 2021
Merged
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
21 changes: 13 additions & 8 deletions src/bundle/Resources/public/js/scripts/core/custom.dropdown.js
Original file line number Diff line number Diff line change
Expand Up @@ -131,16 +131,21 @@
this.sourceInput.dispatchEvent(new CustomEvent(EVENT_VALUE_CHANGED));
}

getItemsContainerHeight(isItemsContainerTop) {
getItemsContainerHeight(isItemsContainerAbove) {
const DROPDOWN_MARGIN = 16;
const SELECTOR_MODAL = '.modal[aria-modal=true]';
const documentElementHeight = doc.documentElement.getBoundingClientRect().height;
const itemsContainerTop = this.itemsContainer.getBoundingClientRect().top;

if (isItemsContainerTop) {
if (isItemsContainerAbove) {
return this.container.querySelector(SELECTOR_SELECTION_INFO).getBoundingClientRect().top - DROPDOWN_MARGIN;
}

return (
document.documentElement.getBoundingClientRect().height - this.itemsContainer.getBoundingClientRect().top - DROPDOWN_MARGIN
);
if (this.itemsContainer.closest(SELECTOR_MODAL)) {
return itemsContainerTop - DROPDOWN_MARGIN;
}

return documentElementHeight - itemsContainerTop - DROPDOWN_MARGIN;
}

onInputClick(event) {
Expand All @@ -156,10 +161,10 @@
if (isListHidden) {
const viewportHeight = window.innerHeight || document.documentElement.clientHeight;
const { top } = this.itemsContainer.getBoundingClientRect();
const isItemsContainerTop = top + ITEMS_LIST_MAX_HEIGHT > viewportHeight;
const itemsListMethodName = isItemsContainerTop ? 'add' : 'remove';
const isItemsContainerAbove = top + ITEMS_LIST_MAX_HEIGHT > viewportHeight;
const itemsListMethodName = isItemsContainerAbove ? 'add' : 'remove';

this.itemsContainer.style['max-height'] = `${this.getItemsContainerHeight(isItemsContainerTop)}px`;
this.itemsContainer.style['max-height'] = `${this.getItemsContainerHeight(isItemsContainerAbove)}px`;
this.itemsContainer.classList[itemsListMethodName](CLASS_ITEMS_POSITION_TOP);
}

Expand Down