Skip to main content

Dropdown

TkDropdown creates a dropdown with a trigger element. Items in the options prop can be listed and templated.

import { TkDropdown } from '@takeoff-ui/react'

Basic​

Demonstrates how to open and close the dialog with simple content.

View Code
const options = [
{ label: "Lorem Ipsum", value: "1" },
{ label: "It is established", value: "2" },
{ label: "Many desktop", value: "3" },
];

return (
<TkDropdown options={options}>
<TkButton
label="Select"
icon="keyboard_arrow_down"
iconPosition="right"
slot="trigger"
/>
</TkDropdown>
);

Position​

This demo demonstrates how to use the position prop to determine the opening direction of the dropdown component. The position prop can accept the following values: bottom, bottom-end, bottom-start, left, left-end, left-start, right, right-end, right-start, top, top-end, top-start.

View Code
<TkDropdown options={options} position="bottom">
<TkButton label="Bottom" slot="trigger" />
</TkDropdown>
<TkDropdown options={options} position="bottom-start">
<TkButton label="Bottom Start" slot="trigger" />
</TkDropdown>
<TkDropdown options={options} position="bottom-end">
<TkButton label="Bottom End" slot="trigger" />
</TkDropdown>

<TkDropdown options={options} position="right">
<TkButton label="Right" slot="trigger" />
</TkDropdown>
<TkDropdown options={options} position="right-start">
<TkButton label="Right Start" slot="trigger" />
</TkDropdown>
<TkDropdown options={options} position="right-end">
<TkButton label="Right End" slot="trigger" />
</TkDropdown>

Option Disable​

You can pass disable: true for the option you want to disable.

View Code
const options = [
{ label: "Enable Item", value: "1" },
{ label: "Disabled Item", value: "2", disabled: true },
{ label: "Enable Item", value: "3" },
];
return (
<TkDropdown options={options}>
<TkButton label="Disable Item Example" slot="trigger" />
</TkDropdown>
);

Custom Item​

You can add custom items using optionHtml prop.

View Code
 <TkDropdown
optionLabelKey="name"
optionValueKey="code"
options={[
{
code: "SAW",
name: "Sabiha Gökçen Havalimanı",
},
{ code: "ESB", name: "Esenboğa Havalimanı" },
{ code: "AYT", name: "Antalya Havalimanı" },
]}
optionHtml={(item: { name: any; code: any }) => {
return `<div class="flex justify-between gap-4">
<div style="font-weight: bold;">${item.name}</div>
<div style="color: var(--primary-base)">${item.code}</div>
</div>`;
}}
>
<TkButton
label="Custom Item Example"
icon="keyboard_arrow_down"
iconPosition="right"
slot="trigger"
/>
</TkDropdown>

Item Click​

You can click an item from dropdown using tk-item-click event.

View Code
const options = [
{ label: "Lorem Ipsum", value: "1" },
{ label: "It is established", value: "2" },
{ label: "Many desktop", value: "3" },
];

return (
<TkDropdown
options={options}
onTkItemClick={(e: any) => {
alert(`${e.detail.label} has been clicked`);
}}
>
<TkButton
label="Item Click Example"
icon="keyboard_arrow_down"
iconPosition="right"
slot="trigger"
/>
</TkDropdown>
);

API​

Props​

NameTypeDefaultDescription
booleanfalseThe disabled status.
string'Nooptionsavailable'The message to display when there is no data available.
string'groupName'The key to use for group names when options are grouped
string'options'The key to use for grouped options array
FunctionnullProvides a function to customize the options.
string'label'The key to use for option labels
string'value'The key to use for option values
any[]nullThe list of options to be displayed in the select box.
"center", "left", "right"'left'Indicates the alignment of options.
"bottom", "bottom-end", "bottom-start", "left", "left-end", "left-start", "right", "right-end", "right-start", "top", "top-end", "top-start"'bottom'Sets the position of the tooltip.

Events​

NameDescription
tk-item-clickEmitted when the value has changed.

Slots​

NameDescription
empty-dataSet how the dropdown will appear when there is no data
triggerThe trigger slot defines the element that will trigger the dropdown