Appearance
Select
The select are a fundamental part of any project, with HopeKit you can add a select with a single line of code.
Basic Usage
The select have themes: default, transparent.
<template>
<div class="grid grid-cols-2 gap-6 items-start">
<HcSelect
v-model="value1"
:options="options"
label="Default theme"
placeholder="Select"
/>
<HcSelect
v-model="value2"
:options="options"
label="Transparent theme"
placeholder="Select"
theme="transparent"
/>
</div>
</template>
<script lang="ts" setup>
import { SelectOption, HcSelect } from '@deeepvision/hope-component-kit';
import { ref } from 'vue';
const value1 = ref('');
const value2 = ref('');
const options = ref<SelectOption[]>([
{
value: 'option_1',
label: 'Option 1',
imageUrl: 'https://media.istockphoto.com/photos/colored-powder-explosion-on-black-background-picture-id1057506940?k=20&m=1057506940&s=612x612&w=0&h=3j5EA6YFVg3q-laNqTGtLxfCKVR3_o6gcVZZseNaWGk=',
},
{
value: 'option_2',
label: 'Option 2',
imageUrl: 'https://media.istockphoto.com/photos/colored-powder-explosion-on-black-background-picture-id1057506940?k=20&m=1057506940&s=612x612&w=0&h=3j5EA6YFVg3q-laNqTGtLxfCKVR3_o6gcVZZseNaWGk=',
},
{
value: 'option_3',
label: 'Option 3',
imageUrl: 'https://media.istockphoto.com/photos/colored-powder-explosion-on-black-background-picture-id1057506940?k=20&m=1057506940&s=612x612&w=0&h=3j5EA6YFVg3q-laNqTGtLxfCKVR3_o6gcVZZseNaWGk=',
},
{
value: 'option_4',
label: 'Option 4',
imageUrl: 'https://media.istockphoto.com/photos/colored-powder-explosion-on-black-background-picture-id1057506940?k=20&m=1057506940&s=612x612&w=0&h=3j5EA6YFVg3q-laNqTGtLxfCKVR3_o6gcVZZseNaWGk=',
},
{
value: 'option_5',
label: 'Option 5',
imageUrl: 'https://storage.googleapis.com/hc-jetstream-assets/brand/jsb:aUZ6wROWsTv/logo-1640108628.png',
},
{
value: 'option_6',
label: 'Option 6',
imageUrl: 'https://storage.googleapis.com/hc-jetstream-assets/brand/jsb:5df5e6e1650/logo-1637338094.png',
disabled: true,
},
]);
</script>
Sizes
The inputs have text sizes: small, medium. The inputs have sizes: small, medium.
<template>
<div class="">
<div class="grid grid-cols-2 gap-6 items-start">
<HcSelect
v-model="value1"
:options="options"
label="Medium text size"
placeholder="Select"
:max-length="50"
text-size="medium"
/>
<HcSelect
v-model="value2"
:options="options"
label="Small text size"
placeholder="Select"
:max-length="50"
text-size="small"
/>
</div>
<div class="mt-5">
<HcSelect
v-model="value3"
:options="options"
label="Medium size"
placeholder="Select"
:max-length="50"
size="medium"
/>
<HcSelect
v-model="value4"
:options="options"
label="Small size"
placeholder="Select"
:max-length="50"
size="small"
class="mt-5"
/>
</div>
</div>
</template>
<script lang="ts" setup>
import { SelectOption, HcSelect } from '@deeepvision/hope-component-kit';
import { ref } from 'vue';
const value1 = ref('');
const value2 = ref('');
const value3 = ref('');
const value4 = ref('');
const options = ref<SelectOption[]>([
{
value: 'option_1',
label: 'Option 1',
imageUrl: 'https://media.istockphoto.com/photos/colored-powder-explosion-on-black-background-picture-id1057506940?k=20&m=1057506940&s=612x612&w=0&h=3j5EA6YFVg3q-laNqTGtLxfCKVR3_o6gcVZZseNaWGk=',
},
{
value: 'option_2',
label: 'Option 2',
imageUrl: 'https://media.istockphoto.com/photos/colored-powder-explosion-on-black-background-picture-id1057506940?k=20&m=1057506940&s=612x612&w=0&h=3j5EA6YFVg3q-laNqTGtLxfCKVR3_o6gcVZZseNaWGk=',
},
{
value: 'option_3',
label: 'Option 3',
imageUrl: 'https://media.istockphoto.com/photos/colored-powder-explosion-on-black-background-picture-id1057506940?k=20&m=1057506940&s=612x612&w=0&h=3j5EA6YFVg3q-laNqTGtLxfCKVR3_o6gcVZZseNaWGk=',
},
{
value: 'option_4',
label: 'Option 4',
imageUrl: 'https://media.istockphoto.com/photos/colored-powder-explosion-on-black-background-picture-id1057506940?k=20&m=1057506940&s=612x612&w=0&h=3j5EA6YFVg3q-laNqTGtLxfCKVR3_o6gcVZZseNaWGk=',
},
{
value: 'option_5',
label: 'Option 5',
imageUrl: 'https://storage.googleapis.com/hc-jetstream-assets/brand/jsb:aUZ6wROWsTv/logo-1640108628.png',
},
{
value: 'option_6',
label: 'Option 6',
imageUrl: 'https://storage.googleapis.com/hc-jetstream-assets/brand/jsb:5df5e6e1650/logo-1637338094.png',
disabled: true,
},
]);
</script>
Disabled & readonly
Change the state of the button to disabled with the disabled property, the property is a boolean so you can add it without any value.
Change the state of the button to readonly with the readonly property.
<template>
<div class="grid grid-cols-2 gap-6 items-start">
<HcSelect
v-model="value1"
:options="options"
label="Disabled"
placeholder="Select"
disabled
/>
<HcSelect
v-model="value2"
:options="options"
label="Readonly"
placeholder="Select"
readonly
/>
</div>
</template>
<script lang="ts" setup>
import { SelectOption, HcSelect } from '@deeepvision/hope-component-kit';
import { ref } from 'vue';
const value1 = ref('');
const value2 = ref('');
const options = ref<SelectOption[]>([
{
value: 'option_1',
label: 'Option 1',
imageUrl: 'https://media.istockphoto.com/photos/colored-powder-explosion-on-black-background-picture-id1057506940?k=20&m=1057506940&s=612x612&w=0&h=3j5EA6YFVg3q-laNqTGtLxfCKVR3_o6gcVZZseNaWGk=',
},
{
value: 'option_2',
label: 'Option 2',
imageUrl: 'https://media.istockphoto.com/photos/colored-powder-explosion-on-black-background-picture-id1057506940?k=20&m=1057506940&s=612x612&w=0&h=3j5EA6YFVg3q-laNqTGtLxfCKVR3_o6gcVZZseNaWGk=',
},
{
value: 'option_3',
label: 'Option 3',
imageUrl: 'https://media.istockphoto.com/photos/colored-powder-explosion-on-black-background-picture-id1057506940?k=20&m=1057506940&s=612x612&w=0&h=3j5EA6YFVg3q-laNqTGtLxfCKVR3_o6gcVZZseNaWGk=',
},
{
value: 'option_4',
label: 'Option 4',
imageUrl: 'https://media.istockphoto.com/photos/colored-powder-explosion-on-black-background-picture-id1057506940?k=20&m=1057506940&s=612x612&w=0&h=3j5EA6YFVg3q-laNqTGtLxfCKVR3_o6gcVZZseNaWGk=',
},
{
value: 'option_5',
label: 'Option 5',
imageUrl: 'https://storage.googleapis.com/hc-jetstream-assets/brand/jsb:aUZ6wROWsTv/logo-1640108628.png',
},
{
value: 'option_6',
label: 'Option 6',
imageUrl: 'https://storage.googleapis.com/hc-jetstream-assets/brand/jsb:5df5e6e1650/logo-1637338094.png',
disabled: true,
},
]);
</script>
Errors
Use props errorMsg to show error message or use prop boolean error to detarmitate error state of the component
<template>
<div>
<div class="grid grid-cols-2 gap-6 items-start">
<HcSelect
v-model="value1"
:options="options"
label="Error"
placeholder="Select"
error
/>
<HcSelect
v-model="value2"
:options="options"
label="Error message"
placeholder="Select"
error-msg="This is an error message"
/>
</div>
<div class="grid grid-cols-2 gap-6 items-start mt-5">
<HcSelect
v-model="value3"
:options="options"
label="Error and disabled"
placeholder="Select"
error
disabled
/>
<HcSelect
v-model="value4"
:options="options"
label="Error and readonly"
placeholder="Select"
error
readonly
/>
</div>
</div>
</template>
<script lang="ts" setup>
import { SelectOption, HcSelect } from '@deeepvision/hope-component-kit';
import { ref } from 'vue';
const value1 = ref('');
const value2 = ref('');
const value3 = ref('');
const value4 = ref('');
const options = ref<SelectOption[]>([
{
value: 'option_1',
label: 'Option 1',
imageUrl: 'https://media.istockphoto.com/photos/colored-powder-explosion-on-black-background-picture-id1057506940?k=20&m=1057506940&s=612x612&w=0&h=3j5EA6YFVg3q-laNqTGtLxfCKVR3_o6gcVZZseNaWGk=',
},
{
value: 'option_2',
label: 'Option 2',
imageUrl: 'https://media.istockphoto.com/photos/colored-powder-explosion-on-black-background-picture-id1057506940?k=20&m=1057506940&s=612x612&w=0&h=3j5EA6YFVg3q-laNqTGtLxfCKVR3_o6gcVZZseNaWGk=',
},
{
value: 'option_3',
label: 'Option 3',
imageUrl: 'https://media.istockphoto.com/photos/colored-powder-explosion-on-black-background-picture-id1057506940?k=20&m=1057506940&s=612x612&w=0&h=3j5EA6YFVg3q-laNqTGtLxfCKVR3_o6gcVZZseNaWGk=',
},
{
value: 'option_4',
label: 'Option 4',
imageUrl: 'https://media.istockphoto.com/photos/colored-powder-explosion-on-black-background-picture-id1057506940?k=20&m=1057506940&s=612x612&w=0&h=3j5EA6YFVg3q-laNqTGtLxfCKVR3_o6gcVZZseNaWGk=',
},
{
value: 'option_5',
label: 'Option 5',
imageUrl: 'https://storage.googleapis.com/hc-jetstream-assets/brand/jsb:aUZ6wROWsTv/logo-1640108628.png',
},
{
value: 'option_6',
label: 'Option 6',
imageUrl: 'https://storage.googleapis.com/hc-jetstream-assets/brand/jsb:5df5e6e1650/logo-1637338094.png',
disabled: true,
},
]);
</script>
Multiple and clearable
Use props clearable to show clear button and allow user to clear modelValue. Use prop multiple to allow use select more that one option. Use multipleLimit with props multiple to determinate the max value of selected options.
<template>
<div class="">
<div class="grid grid-cols-2 gap-6 items-start mt-5">
<HcSelect
v-model="value1"
:options="options"
label="Clearable"
placeholder="Select"
clearable
/>
<HcSelect
v-model="value2"
:options="options"
label="Multiple"
placeholder="Select"
multiple
:multiple-limit="5"
/>
</div>
</div>
</template>
<script lang="ts" setup>
import { SelectOption, HcSelect } from '@deeepvision/hope-component-kit';
import { ref } from 'vue';
const value1 = ref('');
const value2 = ref('');
const options = ref<SelectOption[]>([
{
value: 'option_1',
label: 'Option 1',
imageUrl: 'https://media.istockphoto.com/photos/colored-powder-explosion-on-black-background-picture-id1057506940?k=20&m=1057506940&s=612x612&w=0&h=3j5EA6YFVg3q-laNqTGtLxfCKVR3_o6gcVZZseNaWGk=',
},
{
value: 'option_2',
label: 'Option 2',
imageUrl: 'https://media.istockphoto.com/photos/colored-powder-explosion-on-black-background-picture-id1057506940?k=20&m=1057506940&s=612x612&w=0&h=3j5EA6YFVg3q-laNqTGtLxfCKVR3_o6gcVZZseNaWGk=',
},
{
value: 'option_3',
label: 'Option 3',
imageUrl: 'https://media.istockphoto.com/photos/colored-powder-explosion-on-black-background-picture-id1057506940?k=20&m=1057506940&s=612x612&w=0&h=3j5EA6YFVg3q-laNqTGtLxfCKVR3_o6gcVZZseNaWGk=',
},
{
value: 'option_4',
label: 'Option 4',
imageUrl: 'https://media.istockphoto.com/photos/colored-powder-explosion-on-black-background-picture-id1057506940?k=20&m=1057506940&s=612x612&w=0&h=3j5EA6YFVg3q-laNqTGtLxfCKVR3_o6gcVZZseNaWGk=',
},
{
value: 'option_5',
label: 'Option 5',
imageUrl: 'https://storage.googleapis.com/hc-jetstream-assets/brand/jsb:aUZ6wROWsTv/logo-1640108628.png',
},
{
value: 'option_6',
label: 'Option 6',
imageUrl: 'https://storage.googleapis.com/hc-jetstream-assets/brand/jsb:5df5e6e1650/logo-1637338094.png',
disabled: true,
},
]);
</script>
Filterable
Filterable
<template>
<div class="grid grid-cols-2 gap-6 items-start mt-5">
<HcSelect
v-model="value1"
:options="options"
placeholder="Enter to filter"
filterable
/>
</div>
</template>
<script lang="ts" setup>
import { SelectOption, HcSelect } from '@deeepvision/hope-component-kit';
import { ref } from 'vue';
const value1 = ref('');
const options = ref<SelectOption[]>([
{
value: 'option_1',
label: 'Option 1',
imageUrl: 'https://media.istockphoto.com/photos/colored-powder-explosion-on-black-background-picture-id1057506940?k=20&m=1057506940&s=612x612&w=0&h=3j5EA6YFVg3q-laNqTGtLxfCKVR3_o6gcVZZseNaWGk=',
},
{
value: 'option_2',
label: 'Option 2',
imageUrl: 'https://media.istockphoto.com/photos/colored-powder-explosion-on-black-background-picture-id1057506940?k=20&m=1057506940&s=612x612&w=0&h=3j5EA6YFVg3q-laNqTGtLxfCKVR3_o6gcVZZseNaWGk=',
},
{
value: 'option_3',
label: 'Option 3',
imageUrl: 'https://media.istockphoto.com/photos/colored-powder-explosion-on-black-background-picture-id1057506940?k=20&m=1057506940&s=612x612&w=0&h=3j5EA6YFVg3q-laNqTGtLxfCKVR3_o6gcVZZseNaWGk=',
},
{
value: 'option_4',
label: 'Option 4',
imageUrl: 'https://media.istockphoto.com/photos/colored-powder-explosion-on-black-background-picture-id1057506940?k=20&m=1057506940&s=612x612&w=0&h=3j5EA6YFVg3q-laNqTGtLxfCKVR3_o6gcVZZseNaWGk=',
},
{
value: 'option_5',
label: 'Option 5',
imageUrl: 'https://storage.googleapis.com/hc-jetstream-assets/brand/jsb:aUZ6wROWsTv/logo-1640108628.png',
},
{
value: 'option_6',
label: 'Option 6',
imageUrl: 'https://storage.googleapis.com/hc-jetstream-assets/brand/jsb:5df5e6e1650/logo-1637338094.png',
disabled: true,
},
]);
</script>
AllowCreate
AllowCreate
<template>
<div class="grid grid-cols-2 gap-6 items-start mt-5">
<HcSelect
v-model="value1"
:options="options"
placeholder="Select"
allow-create
filterable
create-label-text="Add option"
:create-method="createMethod"
/>
</div>
</template>
<script lang="ts" setup>
import { SelectOption, HcSelect } from '@deeepvision/hope-component-kit';
import { ref } from 'vue';
const value1 = ref('');
const options = ref<SelectOption[]>([
{
value: 'option_1',
label: 'Option 1',
imageUrl: 'https://media.istockphoto.com/photos/colored-powder-explosion-on-black-background-picture-id1057506940?k=20&m=1057506940&s=612x612&w=0&h=3j5EA6YFVg3q-laNqTGtLxfCKVR3_o6gcVZZseNaWGk=',
},
{
value: 'option_2',
label: 'Option 2',
imageUrl: 'https://media.istockphoto.com/photos/colored-powder-explosion-on-black-background-picture-id1057506940?k=20&m=1057506940&s=612x612&w=0&h=3j5EA6YFVg3q-laNqTGtLxfCKVR3_o6gcVZZseNaWGk=',
},
{
value: 'option_3',
label: 'Option 3',
imageUrl: 'https://media.istockphoto.com/photos/colored-powder-explosion-on-black-background-picture-id1057506940?k=20&m=1057506940&s=612x612&w=0&h=3j5EA6YFVg3q-laNqTGtLxfCKVR3_o6gcVZZseNaWGk=',
},
{
value: 'option_4',
label: 'Option 4',
imageUrl: 'https://media.istockphoto.com/photos/colored-powder-explosion-on-black-background-picture-id1057506940?k=20&m=1057506940&s=612x612&w=0&h=3j5EA6YFVg3q-laNqTGtLxfCKVR3_o6gcVZZseNaWGk=',
},
{
value: 'option_5',
label: 'Option 5',
imageUrl: 'https://storage.googleapis.com/hc-jetstream-assets/brand/jsb:aUZ6wROWsTv/logo-1640108628.png',
},
{
value: 'option_6',
label: 'Option 6',
imageUrl: 'https://storage.googleapis.com/hc-jetstream-assets/brand/jsb:5df5e6e1650/logo-1637338094.png',
disabled: true,
},
]);
const createMethod = (newValue: string) => {
return new Promise((resolve) => {
setTimeout(() => {
const newOption = {
value: newValue,
label: newValue,
};
options.value.unshift(newOption);
resolve(null);
}, 1000);
});
};
</script>
Types
SelectOptionValue = string | number | boolean;
SelectOption:
| Option | Type |
|---|---|
| id | string |
| label | string |
| value | SelectOptionValue |
| imageUrl | string |
| disabled | boolean |
Props
| Property | Type | Values | Description | Default |
|---|---|---|---|---|
| id | String | String | native 'id' attribute | |
| modelValue | String | String | binding value | false |
| options | SelectOption[] | SelectOption[] | items of select | [] |
| label | String | String | label text | |
| placeholder | String | String | placeholder text | |
| error | Boolean | Boolean | determine if the component has error and change its style to that state. | false |
| errorMsg | String | String | error message | |
| disabled | Boolean | Boolean | whether component is disabled | false |
| readonly | Boolean | Boolean | whether component is read only | false |
| imageType | String | squarecircle | image style in option | square |
| filterable | Boolean | Boolean | whether options are filterable | false |
| allowCreate | Boolean | Boolean | whether allow to create item in select | false |
| createLabelText | String | String | create text in option (use when `allowCreate` is true) | Add |
| createMethod | Function | Function | create method | undefined |
| clearable | boolean | truefalse | whether show clearable button | false |
| theme | String | defaulttransparent | component theme | default |
| noDataText | String | String | text in popover when there are no options | No date |
| popperClass | String | String | custom popper class | |
| noMatchText | String | String | text in popover when filterable and there are no options | No date |
| teleported | boolean | truefalse | whether poopver is teleported to body | true |
| loading | boolean | truefalse | whether is options loading | false |
| remote | boolean | truefalse | is remote search active | true |
| remoteMethod | Function | Function | remote method | undefined |
| filterMethod | Function | Function | filter method | undefined |
| valueKey | String | String | valueKey | value |
| size | String | smallmedium | component size | medium |
| textSize | String | smallmedium | component field text size | small |
| multiple | boolean | truefalse | whether use can select more that one option | false |
| multipleLimit | Number | Number | amount of options that user can seelct (when multiple is true) | 1 |
Slots
| Property | Type | Values | Description | Default |
|---|---|---|---|---|
| label-suffix | - | customize label suffix content |
Events
| Property | Type | Values | Description | Default |
|---|---|---|---|---|
| update:model-value | Function | value - SelectOptionValue | triggers when the selected value changes | |
| change | Function | value - SelectOptionValue | triggers when the selected value changes | |
| clear | Function | - | triggers when the clear icon is clicked in a clearable Select | |
| focus | Function | - | triggers when Select focuses | |
| blur | Function | - | triggers when Select blurs | |
| visible-change | Function | value - boolean | triggers when the dropdown appears/disappears | |
| load-more | Function | - | triggers when scroll in dropdown to bottom |