PXD

Search Input

Pre-configured search input with a magnifying glass icon and clear button.

Default

<script setup>
import { ref } from 'vue'

const val = ref('')
</script>

<template>
  <PSearchInput v-model="val" placeholder="Enter some text..." />
</template>

Disabled

<script setup>
import { ref } from 'vue'

const val = ref('')
</script>

<template>
  <PSearchInput v-model="val" disabled placeholder="Enter some text..." />
</template>

Loading

<script setup>
import { ref } from 'vue'

const val = ref('')
const loading = ref(false)

function handleSearch() {
  loading.value = true

  setTimeout(() => {
    loading.value = false
  }, 2000)
}
</script>

<template>
  <PSearchInput v-model="val" :loading="loading" placeholder="Enter some text..." @search="handleSearch" />
</template>

Custom Prefix

<script setup>
import { ref } from 'vue'
import SparklesIcon from '@gdsicon/vue/sparkles'

const val = ref('')
</script>

<template>
  <PSearchInput v-model="val" placeholder="Enter some text...">
    <template #prefix>
      <SparklesIcon />
    </template>
  </PSearchInput>
</template>

Props

SearchInput forwards the input props below to PInput.

NameTypeDefaultDescription
loadingbooleanfalseReplaces the prefix with a loading icon.
size'xs' | 'sm' | 'md' | 'lg'-Input size.
errorboolean | string-Error state.
minnumber | string-Minimum value.
maxnumber | string-Maximum value.
align'left' | 'center' | 'right'leftText alignment.
readonlyboolean-Makes the input read-only.
disabledboolean-Disables the input.
passwordboolean-Enables password input mode.
autofocusboolean-Focuses the input automatically.
input-typestring-Native input type.
input-mode'none' | 'text' | 'tel' | 'url' | 'email' | 'numeric' | 'decimal' | 'search'-Preferred virtual keyboard.
min-lengthnumber | string-Minimum input length.
max-lengthnumber | string-Maximum input length.
trim-overflowbooleanfalseTrims overflow after composition ends when max-length is set.
clearableboolean-Shows a clear button when the input has a value.
clear-valuestring | number | null-Value used after clearing.
model-valuestring | number | null-Current input value. Use v-model for two-way binding.
placeholderstring-Placeholder text.
prefix-classstring | any[] | object-Additional prefix classes.
suffix-classstring | any[] | object-Additional suffix classes.
select-on-focusboolean-Selects the input value on focus.
show-word-limitboolean | string-Shows the current word count.
word-limit-position'inside' | 'outside'insideWord count position.
clear-on-press-escapebooleantrueClears the input when Escape is pressed.
default-prefix-stylebooleanfalseControls the prefix container style.
default-suffix-stylebooleantrueControls the suffix container style.

Events

NameTypeDescription
search(value: string) => voidEmitted when Enter is pressed with a non-empty value while not loading.
click(event: MouseEvent) => voidEmitted when the input container is clicked.
change(value: string, event: Event) => voidEmitted when the input value changes.
focus(event: FocusEvent) => voidEmitted when the input gains focus.
blur(event: FocusEvent) => voidEmitted when the input loses focus.
keydown(event: KeyboardEvent) => voidEmitted when a key is pressed.
update:modelValue(value: string) => voidEmitted when the input value changes. Used by v-model.
compositionstart(event: CompositionEvent) => voidEmitted when text composition starts.
compositionupdate(event: CompositionEvent) => voidEmitted when text composition updates.
compositionend(event: CompositionEvent) => voidEmitted when text composition ends.
input(event: Event) => voidNative DOM input event from the inner <input>, forwarded through attribute fallthrough rather than declared by this component.

Slots

NameDescription
prefixCustom prefix content. The loading icon replaces this slot while loading is true.
suffixCustom suffix content, forwarded to PInput.

Methods

NameTypeDescription
blur() => voidBlur the underlying input.
clear(event?: Event) => voidClear the underlying input and emit change.
focus() => voidFocus the underlying input.
select() => voidSelect the text of the underlying input.

Source

Source