Skip to content

Commit

Permalink
Merge pull request #1426 from codidact/cellio/829-auto-focus-search
Browse files Browse the repository at this point in the history
automatically focus in the textbox when you start a search
  • Loading branch information
ArtOfCode- authored Oct 16, 2024
2 parents c790699 + 653b183 commit 2af6d9b
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions app/views/layouts/_header.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,23 @@
<% mobile_logo_path = SiteSetting['MobileLogoPath'] %>
<% sticky_header = user_preference('sticky_header', community: false) == 'true' %>

<script>
const toggleSearchFocus = () => {
const $input = $('#search');

if ($input.is(':focus')) {
$input.blur();
}
else {
$input.focus();
}
};

$(() => {
$('a[data-header-slide="#search-slide"]').on('click', toggleSearchFocus);
});
</script>

<header class="header is-small has-margin-0<%=' is-dark' if SiteSetting['SiteHeaderIsDark'] %><%= ' sticky' if sticky_header %>">
<div class="container header--container">
<div class="header--brand">
Expand Down

0 comments on commit 2af6d9b

Please sign in to comment.