Skip to content

Choosen

Choosen is select with modal dialog gives you a customizable select box with support for searching, tagging, remote data sets, infinite scrolling, and many other highly used options.

Examples

Choosen

Code
vue
<script setup lang="ts">
import type { BaseChoosenOptionInterface } from '@point-hub/papp'
import { ref } from 'vue'

const options = ref([
  {
    _id: '1',
    label: 'Jane',
    value: 'jane'
  },
  {
    _id: '2',
    label: 'John Doe',
    value: 'john-doe'
  }
])

const modelId = ref()
const selected = ref()
const search = ref()

function onSelect(option?: BaseChoosenOptionInterface) {
  selected.value = option ?? null
}
</script>

<template>
  <base-choosen
    title="Example"
    v-model="modelId" 
    v-model:search="search"
    :options="options"
    @select="onSelect"
  />
  <div class="flex flex-col gap-4">
    <div class="space-x-4">
      <span class="font-bold">Options</span>
      <span>{{ options }}</span>
    </div>
    <div class="space-x-4">
      <span class="font-bold">v-model</span>
      <span>{{ modelId }}</span>
    </div>
    <div class="space-x-4">
      <span class="font-bold">search</span>
      <span>{{ search }}</span>
    </div>
    <div class="space-x-4">
      <span class="font-bold">selected</span>
      <span>{{ selected }}</span>
    </div>
  </div>
</template>

Choosen API

Props

NameTypeDefaultDescription
v-modelstring | nullRequired. Selected option value (id).
v-model:searchstring''Search keyword inside modal.
v-model:errorsstring[]Input error messages.
optionsIOption[][]Available options (can be partial / paginated).
resolveOption(value: string) => IOption | undefinedResolve option when value exists but option is not loaded yet.
titlestringModal title.
labelstringInput label.
descriptionstringInput description.
placeholderstringInput placeholder.
borderBorderTypefullInput border style.
layoutBaseFormLayoutTypehorizontalForm layout.
autofocusbooleanfalseFocus search input when modal opens.
requiredbooleanfalseMark input as required.
disabledbooleanfalseDisable interaction.
readonlybooleanfalseRead-only mode.
helpersstring[]Helper messages below input.
paddinglessbooleanfalseRemove input padding.
isLoadingbooleanfalseShow loading state in option list.
data-testidstringTesting identifier.

Events

NamePayloadDescription
selectIOption | undefinedEmits full option object when selected or undefined when cleared.

Slots

NamePropsDescription
default{ option: IOption }Customize option rendering inside modal.

Automated Test Guide

If you pass a data-testid to the <base-choosen> component, it will automatically generate unique data-testid attributes for testing:

For example, if you set data-testid="user-choosen", the component will generate the following attributes:

Elementdata-testid
Input Fielduser-choosen-input
Search Fielduser-choosen-search
Option with _id = 1user-choosen-1
Option with _id = 2user-choosen-2
Clear Buttonuser-choosen-clear-button

Gherkin Scenario

txt
When I click choosen input "user-choosen-input"
And I type "Durward" into "user-choosen-search"
And I click choosen option "user-choosen-option-1"
And I click choosen clear button "user-choosen-clear-button"

Step Definition

ts
When('I click choosen input {string}', (selector: string) => {
  cy.get(`[data-testid="${selector}"]`).click()
})

When('I click choosen clear button {string}', (selector: string) => {
  cy.get(`[data-testid="${selector}"]`).click()
})

When('I type {string} into {string}', (value: string, selector: string) => {
  cy.get(`[data-testid="${selector}"]`).type(value)
})

When('I click choosen option {string}', (selector: string) => {
  cy.get(`[data-testid="${selector}"]`).click()
})

Code Implementation

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

const userOptions = [
  { _id: '1', label: 'Durward Reynolds' },
  { _id: '2', label: 'Kenton Towne' },
  { _id: '3', label: 'Therese Wunsch' },
  { _id: '4', label: 'Benedict Kessler' }
]
const userSelected = ref()
</script>

<template>
  <base-choosen v-model="userSelected" :options="userOptions" data-testid="user-choosen" />
</template>

Released under the MIT License.