1
0
Fork 0
mirror of synced 2024-09-19 02:39:37 +12:00

Auto focus search input when adding component

This commit is contained in:
Andrew Kingston 2022-05-10 18:48:43 +01:00
parent c7f4978d05
commit 68b20b69d4
3 changed files with 12 additions and 1 deletions

View file

@ -8,6 +8,8 @@
export let id = null export let id = null
export let updateOnChange = true export let updateOnChange = true
export let quiet = false export let quiet = false
export let inputRef
const dispatch = createEventDispatcher() const dispatch = createEventDispatcher()
let focus = false let focus = false
@ -68,6 +70,7 @@
type="search" type="search"
class="spectrum-Textfield-input spectrum-Search-input" class="spectrum-Textfield-input spectrum-Search-input"
autocomplete="off" autocomplete="off"
bind:this={inputRef}
/> />
</div> </div>
<button <button

View file

@ -10,6 +10,7 @@
export let disabled = false export let disabled = false
export let updateOnChange = true export let updateOnChange = true
export let quiet = false export let quiet = false
export let inputRef
const dispatch = createEventDispatcher() const dispatch = createEventDispatcher()
const onChange = e => { const onChange = e => {
@ -25,6 +26,7 @@
{value} {value}
{placeholder} {placeholder}
{quiet} {quiet}
bind:inputRef
on:change={onChange} on:change={onChange}
on:click on:click
on:input on:input

View file

@ -14,9 +14,11 @@
} from "@budibase/bbui" } from "@budibase/bbui"
import structure from "./componentStructure.json" import structure from "./componentStructure.json"
import { store } from "builderStore" import { store } from "builderStore"
import { onMount } from "svelte"
let section = "components" let section = "components"
let searchString let searchString
let searchRef
$: enrichedStructure = enrichStructure(structure, $store.components) $: enrichedStructure = enrichStructure(structure, $store.components)
$: filteredStructure = filterStructure( $: filteredStructure = filterStructure(
@ -52,7 +54,6 @@
if (!structure?.length) { if (!structure?.length) {
return [] return []
} }
if (section === "components") { if (section === "components") {
structure = structure.filter(category => category.name !== "Blocks") structure = structure.filter(category => category.name !== "Blocks")
} else { } else {
@ -91,6 +92,10 @@
notifications.error("Error creating component") notifications.error("Error creating component")
} }
} }
onMount(() => {
searchRef.focus()
})
</script> </script>
<NavigationPanel <NavigationPanel
@ -121,6 +126,7 @@
placeholder="Search" placeholder="Search"
value={searchString} value={searchString}
on:change={e => (searchString = e.detail)} on:change={e => (searchString = e.detail)}
bind:inputRef={searchRef}
/> />
</Layout> </Layout>
{/if} {/if}