mirror of
https://github.com/sissbruecker/linkding.git
synced 2025-08-07 18:58:30 +02:00
Fix search options not opening on iOS (#549)
* Fix search options not opening on iOS * cleanup
This commit is contained in:
36
bookmarks/frontend/behaviors/dropdown.js
Normal file
36
bookmarks/frontend/behaviors/dropdown.js
Normal file
@@ -0,0 +1,36 @@
|
|||||||
|
import { registerBehavior } from "./index";
|
||||||
|
|
||||||
|
class DropdownBehavior {
|
||||||
|
constructor(element) {
|
||||||
|
this.element = element;
|
||||||
|
this.opened = false;
|
||||||
|
this.onOutsideClick = this.onOutsideClick.bind(this);
|
||||||
|
|
||||||
|
const toggle = element.querySelector(".dropdown-toggle");
|
||||||
|
toggle.addEventListener("click", () => {
|
||||||
|
if (this.opened) {
|
||||||
|
this.close();
|
||||||
|
} else {
|
||||||
|
this.open();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
open() {
|
||||||
|
this.element.classList.add("active");
|
||||||
|
document.addEventListener("click", this.onOutsideClick);
|
||||||
|
}
|
||||||
|
|
||||||
|
close() {
|
||||||
|
this.element.classList.remove("active");
|
||||||
|
document.removeEventListener("click", this.onOutsideClick);
|
||||||
|
}
|
||||||
|
|
||||||
|
onOutsideClick(event) {
|
||||||
|
if (!this.element.contains(event.target)) {
|
||||||
|
this.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
registerBehavior("ld-dropdown", DropdownBehavior);
|
@@ -4,6 +4,7 @@ import { ApiClient } from "./api";
|
|||||||
import "./behaviors/bookmark-page";
|
import "./behaviors/bookmark-page";
|
||||||
import "./behaviors/bulk-edit";
|
import "./behaviors/bulk-edit";
|
||||||
import "./behaviors/confirm-button";
|
import "./behaviors/confirm-button";
|
||||||
|
import "./behaviors/dropdown";
|
||||||
import "./behaviors/modal";
|
import "./behaviors/modal";
|
||||||
import "./behaviors/global-shortcuts";
|
import "./behaviors/global-shortcuts";
|
||||||
import "./behaviors/tag-autocomplete";
|
import "./behaviors/tag-autocomplete";
|
||||||
|
@@ -74,12 +74,6 @@
|
|||||||
min-width: 250px;
|
min-width: 250px;
|
||||||
}
|
}
|
||||||
|
|
||||||
&:focus-within {
|
|
||||||
.menu {
|
|
||||||
display: block;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
.menu .actions {
|
.menu .actions {
|
||||||
margin-top: $unit-4;
|
margin-top: $unit-4;
|
||||||
display: flex;
|
display: flex;
|
||||||
|
@@ -44,8 +44,8 @@
|
|||||||
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 6v6m0 0v6m0-6h6m-6 0H6"/>
|
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 6v6m0 0v6m0-6h6m-6 0H6"/>
|
||||||
</svg>
|
</svg>
|
||||||
</a>
|
</a>
|
||||||
<div class="dropdown dropdown-right">
|
<div ld-dropdown class="dropdown dropdown-right">
|
||||||
<a href="#" id="mobile-nav-menu-trigger" class="btn btn-link dropdown-toggle" tabindex="0">
|
<a href="#" class="btn btn-link dropdown-toggle" tabindex="0">
|
||||||
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke="currentColor"
|
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke="currentColor"
|
||||||
style="width: 24px; height: 24px">
|
style="width: 24px; height: 24px">
|
||||||
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M4 6h16M4 12h16M4 18h16"/>
|
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M4 6h16M4 12h16M4 18h16"/>
|
||||||
@@ -80,22 +80,3 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
{% endhtmlmin %}
|
{% endhtmlmin %}
|
||||||
<script>
|
|
||||||
// Hide mobile menu on outside click
|
|
||||||
// The Spectre CSS component relies on focus changes to show/hide the dropdown, however mobile browsers like
|
|
||||||
// Safari will not trigger a blur event when clicking on a non-focusable element, so we have to simulate the
|
|
||||||
// behaviour through Javascript
|
|
||||||
const mobileNavMenuTrigger = document.getElementById('mobile-nav-menu-trigger');
|
|
||||||
|
|
||||||
function mobileNavMenuOutsideClickHandler(clickEvent) {
|
|
||||||
if (mobileNavMenuTrigger.parentElement.contains(clickEvent.target)) return
|
|
||||||
mobileNavMenuTrigger.blur();
|
|
||||||
}
|
|
||||||
|
|
||||||
mobileNavMenuTrigger.addEventListener('focus', function () {
|
|
||||||
document.addEventListener('click', mobileNavMenuOutsideClickHandler);
|
|
||||||
})
|
|
||||||
mobileNavMenuTrigger.addEventListener('blur', function () {
|
|
||||||
document.removeEventListener('click', mobileNavMenuOutsideClickHandler);
|
|
||||||
})
|
|
||||||
</script>
|
|
||||||
|
@@ -9,7 +9,7 @@
|
|||||||
{{ hidden_field }}
|
{{ hidden_field }}
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</form>
|
</form>
|
||||||
<div class="search-options dropdown dropdown-right">
|
<div ld-dropdown class="search-options dropdown dropdown-right">
|
||||||
<button type="button" class="btn dropdown-toggle{% if search.has_modified_preferences %} badge{% endif %}">
|
<button type="button" class="btn dropdown-toggle{% if search.has_modified_preferences %} badge{% endif %}">
|
||||||
<svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" stroke-width="2"
|
<svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" stroke-width="2"
|
||||||
stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round">
|
stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round">
|
||||||
|
Reference in New Issue
Block a user