Select
TkSelect component description.
- React
- Vue
- Angular
import { TkSelect } from '@takeoff-ui/react'
import { TkSelect } from '@takeoff-ui/vue'
import { TkSelect } from '@takeoff-ui/angular'
Playground
Preview
Generated Code
<TkSelect options={[{"label":"Option 1","value":"1"},{"label":"Option 2","value":"2"},{"label":"Option 3","value":"3"}]} label="Select Option" placeholder="Choose..." size="base" dropdownWidthMode="match-parent" emptyMessage="No options available" selectAllLabel="All"/><TkSelect :options="[{"label":"Option 1","value":"1"},{"label":"Option 2","value":"2"},{"label":"Option 3","value":"3"}]" label="Select Option" placeholder="Choose..." size="base" dropdownWidthMode="match-parent" emptyMessage="No options available" selectAllLabel="All"/><tk-select [options]="[{"label":"Option 1","value":"1"},{"label":"Option 2","value":"2"},{"label":"Option 3","value":"3"}]" label="Select Option" placeholder="Choose..." size="base" dropdownWidthMode="match-parent" emptyMessage="No options available" selectAllLabel="All"/>Controls
Basic
- React
- Vue
- Angular
<TkSelect
label="Text Input"
options={[
{ value: "female", label: "Female" },
{ value: "male", label: "Male" },
{ value: "other", label: "Other" },
]}
hint="Hint text"
placeholder="Placeholder text"
/>
<TkSelect
label="Text Input"
:options="[
{ value: 'female', label: 'Female' },
{ value: 'male', label: 'Male' },
{ value: 'other', label: 'Other' },
]"
hint="Hint text"
placeholder="Placeholder text"
/>
Filter
You can perform filtering either server-side or client-side using the filter emit.
- React
- Vue
- Angular
const selectOptions = [
{ value: "female", label: "Female", searchField: "XX" },
{ value: "male", label: "Male", searchField: "XY" },
{ value: "other", label: "Other", searchField: "00" },
];
const [value, setValue] = useState();
const [value1, setValue1] = useState();
return (
<div>
<TkSelect
editable
label="Default Filter"
options={selectOptions}
value={value}
onTkChange={(e) => setValue(e.detail)}
/>
<br />
<TkSelect
editable
label="Custom Filter Function"
options={selectOptions}
filter={async (text: string, options: any[]) => {
return options.filter(
(item) =>
item.searchField.toLowerCase().indexOf(text.toLowerCase()) > -1
);
}}
value={value1}
onTkChange={(e) => setValue1(e.detail)}
/>
</div>
);
<script setup>
import { TkSelect } from '@takeoff-ui/vue';
const selectOptions = [
{ value: 'female', label: 'Female', searchField: 'XX' },
{ value: 'male', label: 'Male', searchField: 'XY' },
{ value: 'other', label: 'Other', searchField: '00' },
];
</script>
<template>
<div>
<TkSelect
editable
label="Default Filter"
:options="selectOptions"
/>
<TkSelect
editable
label="Custom Filter Function"
:options="selectOptions"
filter="async (text: string, options: any[]) => {
return options.filter(
(item) =>
item.searchField.toLowerCase().indexOf(text.toLowerCase()) > -1
);
}"
/>
</div>
</template>
Loading
You can use loading prop for waiting the response from the server-side.
- React
- Vue
- Angular
const selectOptions = [
{ value: "female", label: "Female"},
{ value: "male", label: "Male"},
{ value: "other", label: "Other"},
];
const [value, setValue] = useState();
const [loading, setLoading] = useState(false);
const fetchData = async (text: string) => {
return new Promise((resolve) => {
setTimeout(() => {
let response;
response = options.filter(
(item) => item.label?.toLowerCase().indexOf(text?.toLowerCase()) > -1
);
resolve(response);
}, 2000);
});
};
return (
<div>
<TkSelect
editable
label="Loading Prop"
loading={loading}
options={selectOptions}
filter={async (text: string, selectOptions: any[]) => {
setLoading(true);
const response = await fetchData(text);
setLoading(false);
return response;
}}
value={value}
onTkChange={(e) => {
setValue(e.detail);
}}
/>
</div>
);
<script setup>
import { TkSelect } from '@takeoff-ui/vue';
import { ref } from "vue"
const selectOptions = [
{ value: 'female', label: 'Female'},
{ value: 'male', label: 'Male'},
{ value: 'other', label: 'Other'},
];
const fetchData = async (text) => {
return new Promise((resolve) => {
setTimeout(() => {
let response;
response = selectOptions.filter(
(item) => item.label?.toLowerCase().indexOf(text?.toLowerCase()) > -1
);
resolve(response);
}, 2000);
});
};
const loading= ref(false)
</script>
<template>
<div>
<TkSelect
editable
label="Loading Prop"
:loading="loading"
:options.prop="selectOptions"
:filter.prop="async (text) => {
loading=!loading
const response = await fetchData(text);
loading=!loading
return response;
}"
:value.prop="value"
/>
</div>
</template>
Custom Item
You can provide a template as an HTML string using the optionHtml prop.
- React
- Vue
- Angular
<TkSelect
label="Custom Item"
optionLabelKey="name"
optionValueKey="code"
options={[
{
code: "SAW",
name: "Sabiha Gökçen Havalimanı",
country: "İstanbul",
},
{ code: "ESB", name: "Esenboğa Havalimanı", country: "Ankara" },
{ code: "AYT", name: "Antalya Havalimanı", country: "Antalya" },
]}
optionHtml={(item) => {
return `<div style="display: flex; flex-direction: column;">
<div style="displaY: flex;justify-content: space-between;">
<div style="font-weight: bold;">${item.name}</div>
<div style="color: var(--primary-base)">${item.code}</div>
</div>
<div>${item.country}</div>
</div>`;
}}
value={value}
onTkChange={(e) => setValue(e.detail)}
/>
<TkSelect
label="Custom Item"
optionLabelKey="name"
optionValueKey="code"
:options="[
{ code: 'SAW', name: 'Sabiha Gökçen Havalimanı', country: 'İstanbul' },
{ code: 'ESB', name: 'Esenboğa Havalimanı', country: 'Ankara' },
{ code: 'AYT', name: 'Antalya Havalimanı', country: 'Antalya' },
]" :optionHtml="(item) => {
return `<div style='display: flex; flex-direction: column;'>
<div style='display: flex;justify-content: space-between;'>
<div style='font-weight: bold;'>${item.name}</div>
<div style='color: var(--primary-base)'>${item.code}</div>
</div>
<div>${item.country}</div>
</div>`;
}"
v-model="value"
/>