-
Notifications
You must be signed in to change notification settings - Fork 16
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-3922: Fix dropdown inside modal #584
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -444,16 +444,14 @@ | |
return; | ||
} | ||
|
||
const modalDialog = this.container.closest('.modal-dialog'); | ||
|
||
this.itemsPopover = new DropdownPopover( | ||
this.selectedItemsContainer, | ||
{ | ||
html: true, | ||
placement: 'bottom', | ||
customClass: 'ibexa-dropdown-popover', | ||
content: this.itemsPopoverContent, | ||
container: modalDialog || 'body', | ||
container: 'body', | ||
}, | ||
{ dropdown: this }, | ||
); | ||
|
@@ -478,6 +476,31 @@ | |
.forEach((option) => option.addEventListener('click', this.onOptionClick, false)); | ||
|
||
if (this.itemsFilterInput) { | ||
const modal = this.container.closest('.modal'); | ||
const popupInputs = this.itemsContainer.querySelectorAll('input'); | ||
|
||
popupInputs.forEach((popupInput) => | ||
popupInput.addEventListener( | ||
'focusin', | ||
() => { | ||
const modalInstance = bootstrap.Modal.getInstance(modal); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I get an instance every time just in case it changes etc. I also assume that this event may be in some very rare cases called before any instance was created and I don't want to create an instance inside the dropdown class. |
||
|
||
if (modalInstance) { | ||
modalInstance._focustrap.deactivate(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Bootstrap modal uses FocusTrap which steals focus if it is outside the modal |
||
|
||
this.itemsFilterInput.addEventListener( | ||
'focusout', | ||
() => { | ||
modalInstance._focustrap.activate(); | ||
}, | ||
{ once: true }, | ||
); | ||
} | ||
}, | ||
false, | ||
), | ||
); | ||
|
||
this.itemsFilterInput.addEventListener('keyup', this.filterItems, false); | ||
this.itemsFilterInput.addEventListener('input', this.filterItems, false); | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Having a dropdown popup inside a modal caused problems when the modal was embedded inside a tab, which has
overflow: hidden
CSS style.