mirror of
https://github.com/shadoll/sLogos.git
synced 2025-12-20 08:30:59 +00:00
feat: add global search hotkey functionality and display hint in header
This commit is contained in:
@@ -20,6 +20,26 @@
|
|||||||
export let compactMode = false;
|
export let compactMode = false;
|
||||||
export let setCompactMode = () => {};
|
export let setCompactMode = () => {};
|
||||||
|
|
||||||
|
let searchInput; // Reference to the search input element
|
||||||
|
|
||||||
|
onMount(() => {
|
||||||
|
// Add global keydown listener for the / hotkey
|
||||||
|
function handleKeydown(event) {
|
||||||
|
// Check if the / key is pressed and no input/textarea is focused
|
||||||
|
if (event.key === '/' && !['INPUT', 'TEXTAREA'].includes(document.activeElement?.tagName)) {
|
||||||
|
event.preventDefault(); // Prevent the / character from being typed
|
||||||
|
searchInput?.focus(); // Focus the search input
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
document.addEventListener('keydown', handleKeydown);
|
||||||
|
|
||||||
|
// Cleanup listener on component destroy
|
||||||
|
return () => {
|
||||||
|
document.removeEventListener('keydown', handleKeydown);
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
function onInput(event) {
|
function onInput(event) {
|
||||||
searchQuery = event.target.value;
|
searchQuery = event.target.value;
|
||||||
setSearchQuery(searchQuery);
|
setSearchQuery(searchQuery);
|
||||||
@@ -131,6 +151,7 @@
|
|||||||
type="text"
|
type="text"
|
||||||
placeholder="Search logos..."
|
placeholder="Search logos..."
|
||||||
bind:value={searchQuery}
|
bind:value={searchQuery}
|
||||||
|
bind:this={searchInput}
|
||||||
on:input={onInput}
|
on:input={onInput}
|
||||||
aria-label="Search logos"
|
aria-label="Search logos"
|
||||||
/>
|
/>
|
||||||
@@ -166,6 +187,9 @@
|
|||||||
</svg>
|
</svg>
|
||||||
</button>
|
</button>
|
||||||
{/if}
|
{/if}
|
||||||
|
<div class="hotkey-hint">
|
||||||
|
<kbd>/</kbd>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="tag-filter">
|
<div class="tag-filter">
|
||||||
{#each selectedTags as tagText}
|
{#each selectedTags as tagText}
|
||||||
@@ -328,12 +352,14 @@
|
|||||||
display: flex;
|
display: flex;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
}
|
}
|
||||||
|
|
||||||
.search-bar input {
|
.search-bar input {
|
||||||
padding-right: 2em;
|
padding-right: 4em; /* Increased to accommodate both clear button and hotkey hint */
|
||||||
}
|
}
|
||||||
|
|
||||||
.clear-btn {
|
.clear-btn {
|
||||||
position: absolute;
|
position: absolute;
|
||||||
right: 0.5em;
|
right: 2.5em; /* Positioned to leave space for hotkey hint */
|
||||||
background: none;
|
background: none;
|
||||||
border: none;
|
border: none;
|
||||||
padding: 0;
|
padding: 0;
|
||||||
@@ -345,9 +371,31 @@
|
|||||||
justify-content: center;
|
justify-content: center;
|
||||||
height: 100%;
|
height: 100%;
|
||||||
}
|
}
|
||||||
|
|
||||||
.clear-btn:hover {
|
.clear-btn:hover {
|
||||||
color: #f44336;
|
color: #f44336;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.hotkey-hint {
|
||||||
|
position: absolute;
|
||||||
|
right: 0.5em;
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
pointer-events: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
.hotkey-hint kbd {
|
||||||
|
background: var(--color-border);
|
||||||
|
color: var(--color-text);
|
||||||
|
border: 1px solid var(--color-border);
|
||||||
|
border-radius: 3px;
|
||||||
|
padding: 0.2em 0.4em;
|
||||||
|
font-size: 0.75em;
|
||||||
|
font-family: monospace;
|
||||||
|
font-weight: bold;
|
||||||
|
box-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
|
||||||
|
}
|
||||||
|
|
||||||
.compact-switch-btn {
|
.compact-switch-btn {
|
||||||
background: none;
|
background: none;
|
||||||
border: none;
|
border: none;
|
||||||
|
|||||||
Reference in New Issue
Block a user