Add Shortcut "/" for search, don't auto focus
This commit is contained in:
parent
5669567f15
commit
9d992e4557
1 changed files with 22 additions and 2 deletions
|
@ -1,4 +1,6 @@
|
||||||
---
|
---
|
||||||
|
import KeyboardControls from 'astro-keyboard-controls';
|
||||||
|
|
||||||
export interface Props {
|
export interface Props {
|
||||||
readonly id?: string;
|
readonly id?: string;
|
||||||
readonly className?: string;
|
readonly className?: string;
|
||||||
|
@ -9,6 +11,8 @@ export interface Props {
|
||||||
const { id, className, query, uiOptions = {} } = Astro.props;
|
const { id, className, query, uiOptions = {} } = Astro.props;
|
||||||
const bundlePath = `${import.meta.env.BASE_URL}pagefind/`;
|
const bundlePath = `${import.meta.env.BASE_URL}pagefind/`;
|
||||||
---
|
---
|
||||||
|
<KeyboardControls selector=".pagefind-ui__search-input" key="/" />
|
||||||
|
|
||||||
|
|
||||||
<button class="mobile-s" onclick="MobileCloseSearch()" id="search-close">Close</button>
|
<button class="mobile-s" onclick="MobileCloseSearch()" id="search-close">Close</button>
|
||||||
|
|
||||||
|
@ -32,6 +36,24 @@ function MobileCloseSearch() {
|
||||||
data-ui-options={JSON.stringify(uiOptions)}
|
data-ui-options={JSON.stringify(uiOptions)}
|
||||||
>
|
>
|
||||||
</div>
|
</div>
|
||||||
|
<span id="key">/</span>
|
||||||
|
<style lang="scss">
|
||||||
|
#key {
|
||||||
|
display: block;
|
||||||
|
background: #222;
|
||||||
|
aspect-ratio: 1;
|
||||||
|
padding: 4px 10px;
|
||||||
|
border-radius: 6px;
|
||||||
|
font-size: 14px;
|
||||||
|
margin-left: -42px;
|
||||||
|
pointer-events: none;
|
||||||
|
opacity: 0.5;
|
||||||
|
}
|
||||||
|
@media screen and (max-width: 775px) {
|
||||||
|
#key {display: none}
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
import { PagefindUI } from "@pagefind/default-ui";
|
import { PagefindUI } from "@pagefind/default-ui";
|
||||||
|
@ -65,8 +87,6 @@ function MobileCloseSearch() {
|
||||||
|
|
||||||
const input = el.querySelector<HTMLInputElement>(`input[type="text"]`);
|
const input = el.querySelector<HTMLInputElement>(`input[type="text"]`);
|
||||||
|
|
||||||
input?.focus();
|
|
||||||
|
|
||||||
if (input) {
|
if (input) {
|
||||||
input.value = query;
|
input.value = query;
|
||||||
input.dispatchEvent(new Event("input", { bubbles: true }));
|
input.dispatchEvent(new Event("input", { bubbles: true }));
|
||||||
|
|
Loading…
Add table
Reference in a new issue