Skip to content

fix: smaller screen view and search for mobile views #689

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

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
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
1 change: 1 addition & 0 deletions doc/changelog.d/689.fixed.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
smaller screen view and search for mobile views
58 changes: 46 additions & 12 deletions src/ansys_sphinx_theme/assets/styles/ast-search.scss
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
/* Static Search Results Container */

.bd-search{
display: flex;
}
.static-search-results {
display: flex;
flex-direction: column;
Expand Down Expand Up @@ -81,10 +85,6 @@ html[data-theme="light"] .highlight {
.bd-search .search-button__kbd-shortcut {
background-color: var(--ast-search-bar-enable-background) !important;
box-shadow: none !important;
height: 2.25rem; /* 36px */
display: flex;
flex-wrap: wrap;
align-content: center;
}

/* Index Select Dropdown */
Expand Down Expand Up @@ -150,20 +150,54 @@ html[data-theme="light"] .highlight {
}

/* Responsive Styles */
@media (max-width: 48rem) { /* 768px */
.bd-search input.expanded {
width: 6.25rem; /* 100px */
@media (min-width: 64rem) and (max-width: 85.375rem) {
.bd-search input.form-control.expanded {
width: 100%; /* 320px */
}

.bd-search input.form-control {
width: 100%; /* 240px */
}

.bd-search .search-button__kbd-shortcut {
display: none !important;
}

.static-search-results {
width: 30%; /* 480px */
}
}

@media (max-width: 64rem) {

.bd-search input.form-control.expanded {
width: 100%; /* 320px */
}

.form-control {
width: 3.125rem; /* 50px */
.bd-search input.form-control {
width: 100%; /* 240px */
}

.result {
width: 6.25rem; /* 100px */
.static-search-results {
width: 30%; /* 480px */
}

.bd-search .search-button__kbd-shortcut {
display: none;
display: none !important;
}
}

// laptop
@media (min-width: 85.375rem) and (max-width: 128rem) {
.bd-search input.form-control.expanded {
width: 35rem; /* 560px */
}

.bd-search input.form-control {
width: 100%; /* 240px */
}

.static-search-results {
width: 37rem; /* 600px */
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

<div class="search-bar pst-js-only" id="search-bar">
<div class="search-bar" id="search-bar">
<form class="bd-search d-flex align-items-center" action="{{ pathto('search') }}" method="get">
<i class="fa-solid fa-magnifying-glass"></i>
<input type="search" class="form-control" name="q" placeholder="{{ theme_search_bar_text }}"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,30 @@
const SEARCH_BAR = document.getElementById("search-bar");
const SEARCH_INPUT = SEARCH_BAR.querySelector(".bd-search input.form-control");
const RESULTS = document.getElementById("static-search-results");
// Determine which search bar to use (mobile or desktop)
let SEARCH_BAR;

if (window.innerWidth < 960) {
SEARCH_BAR = document.querySelector(".navbar-persistent--mobile #search-bar");
} else {
SEARCH_BAR = document.getElementById("search-bar");
}

// Fallback if nothing is found
if (!SEARCH_BAR) {
console.warn("SEARCH_BAR not found for current view.");
}

// Get input and results area

const SEARCH_INPUT = SEARCH_BAR?.querySelector(".bd-search input.form-control");

let RESULTS;
if (window.innerWidth < 960) {
RESULTS = document.querySelector(
".navbar-persistent--mobile .static-search-results",
);
} else {
RESULTS = document.querySelector(".static-search-results");
}

const MAIN_PAGE_CONTENT = document.querySelector(".bd-main");
let CURRENT_INDEX = -1;

Expand Down Expand Up @@ -144,7 +168,6 @@ require(["fuse"], function (Fuse) {
searchingBanner.className = "searching-banner";
searchingBanner.textContent = "Searching...";
searchingBanner.style.display = "block";
console.log("Searching...");
searchingBanner.style.fontStyle = "italic";
RESULTS.appendChild(searchingBanner);
}
Expand Down Expand Up @@ -248,7 +271,6 @@ require(["fuse"], function (Fuse) {
}
}

// Add event listeners
SEARCH_INPUT.addEventListener("click", expandSearchInput);
SEARCH_INPUT.addEventListener("keydown", handleKeyDownSearchInput);
document.addEventListener("keydown", handleGlobalKeyDown);
Expand Down
Loading