Skip to content

feat(docs): expose the search in the small viewport #6966

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 8 commits into from
Mar 28, 2025
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
1 change: 0 additions & 1 deletion packages/docs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
"@builder.io/qwik-labs": "workspace:^",
"@builder.io/qwik-react": "workspace:^",
"@builder.io/sdk-qwik": "0.14.31",
"@docsearch/css": "3.9.0",
"@emotion/react": "11.13.0",
"@emotion/styled": "11.13.0",
"@modular-forms/qwik": "0.23.1",
Expand Down
29 changes: 13 additions & 16 deletions packages/docs/src/components/docsearch/doc-search-modal.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
import { component$, useSignal, noSerialize, useContextProvider, useTask$ } from '@builder.io/qwik';
import {
component$,
useSignal,
noSerialize,
useContextProvider,
useTask$,
type Signal,
} from '@builder.io/qwik';
import { MAX_QUERY_SIZE } from './constants';
import { SearchContext } from './context';
import type { DocSearchProps, DocSearchState } from './doc-search';
Expand All @@ -23,6 +30,7 @@ export type DocSearchModalProps = DocSearchProps & {
translations?: ModalTranslations;
state: DocSearchState;
aiResultOpen?: boolean;
isOpen: Signal<boolean>;
};

export const DocSearchModal = component$(
Expand All @@ -34,6 +42,7 @@ export const DocSearchModal = component$(
transformItems$ = identity,
aiResultOpen,
disableUserPersonalization = false,
isOpen,
}: DocSearchModalProps) => {
const containerRef = useSignal<Element>();
const modalRef = useSignal<Element>();
Expand All @@ -44,7 +53,7 @@ export const DocSearchModal = component$(
const onSelectItem = noSerialize(({ item, event }: any) => {
if (event) {
if (!event.shiftKey && !event.ctrlKey && !event.metaKey) {
state.isOpen = false;
isOpen.value = false;
}
}
}) as any;
Expand Down Expand Up @@ -106,11 +115,6 @@ export const DocSearchModal = component$(
useTask$(() => {
if (isBrowser) {
document.body.classList.add('DocSearch--active');
const isMobileMediaQuery = window.matchMedia('(max-width: 768px)');

if (isMobileMediaQuery.matches) {
state.snippetLength = 5;
}

return () => {
document.body.classList.remove('DocSearch--active');
Expand Down Expand Up @@ -167,20 +171,13 @@ export const DocSearchModal = component$(
tabIndex={0}
onMouseDown$={(event) => {
if (event.target === containerRef.value) {
state.isOpen = false;
isOpen.value = false;
}
}}
>
<div class="DocSearch-Modal" ref={modalRef}>
<header class="DocSearch-SearchBar" ref={formElementRef}>
<SearchBox
state={state}
autoFocus={true}
inputRef={inputRef as any}
onClose$={() => {
state.isOpen = false;
}}
/>
<SearchBox isOpen={isOpen} state={state} autoFocus={true} inputRef={inputRef as any} />
</header>

<div class="DocSearch-Dropdown" ref={dropdownRef}>
Expand Down
Loading