Skip to content

hide search dropdown on click out #1566

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

Merged
merged 1 commit into from
Jul 16, 2024
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
2 changes: 1 addition & 1 deletion pgml-dashboard/src/components/dropdown/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ pub struct Dropdown {
/// Position of the dropdown menu.
offset: String,

/// Whether or not the dropdown is collapsable.
/// Whether or not the dropdown responds to horizontal collapse, i.e. in product left nav.
collapsable: bool,
offset_collapsed: String,

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,11 @@ export default class extends Controller {
search(id, url) {
this.element.querySelector(`turbo-frame[id=${id}]`).src = url;
}

// Hide the dropdown if the user clicks outside of it.
hideDropdown(e) {
if (!this.element.contains(e.target)) {
this.endSearch();
}
}
}
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
<%
use crate::components::Dropdown;
use crate::components::stimulus::stimulus_action::{StimulusAction, StimulusEvents};

%>
<div data-controller="inputs-text-search-search"
data-search-frame-id="<%= id %>"
data-search-frame-url="<%= search_url %>"
>
data-action='click@document->inputs-text-search-search#hideDropdown'>

<%+ input %>

<%+ Dropdown::new_no_button()
.frame(id, search_url.as_str())
.collapsable()
%>
</div>