SelectInput
General
SelectInput
A retrievable dropdown menu used to display options.
Show Code
import React, { useState } from "react";
import SelectInput from "pocko-ui/SelectInput";
const dropdown: any = [
{id: 1, name: '1', value: '1'},
{id: 2, name: '2', value: '2'},
{id: 3, name: '3', value: '3'}
]
const [defaultValue, setDefaultValue] = useState<any>('')
const [defaultValue2, setDefaultValue2] = useState<any>('')
const [defaultValue3, setDefaultValue3] = useState<any>('')
<SelectInput
id="id"
name="name"
dropdownRender={dropdown}
onChange={(i: any) => {
console.log(i);
setDefaultValue(i.value)
}}
></SelectInput>
<SelectInput
id="id"
name="name"
dropdownRender={dropdown}
onChange={(i: any) => {
setDefaultValue2(i.value);
}}
defaultValue={defaultValue2}
wrapperClassName="mt-2"
cleanTrigger={{
valid: true,
cleanValueLabel: "Clean",
cleanFunc: () => {
setDefaultValue2("");
},
}}
></SelectInput>
<SelectInput
id="id"
name="name"
dropdownRender={dropdown}
onChange={(i: any) => {
setDefaultValue3(i.value);
}}
defaultValue={defaultValue3}
wrapperClassName="mt-2"
cleanTrigger={{
valid: true,
cleanValueLabel: "Clean",
cleanFunc: () => {
setDefaultValue3("");
},
}}
manualSearchTrigger={true} // When true, disables automatic search on focus or initialization; search must be triggered manually.
></SelectInput>
Multiple Selection
Multiple selection, selecting from existing items.
Show Code
import React, { useState } from "react";
import SelectInput from "pocko-ui/SelectInput";
const dropdown: any = [
{id: 1, name: '1', value: '1'},
{id: 2, name: '2', value: '2'},
{id: 3, name: '3', value: '3'}
]
const [defaultValue, setDefaultValue] = useState<any[]>([]) // *** the type must be array
<SelectInput
id="id"
name="name"
dropdownRender={dropdown}
onChange={(i: any) => {
console.log(i);
setDefaultValue(i)
}}
defaultValue={defaultValue}
wrapperClassName="mt-2"
></SelectInput>Choose Dropdown Position
Select the location where the dropdown box appears
Show Code
import React, { useState } from "react";
import SelectInput from "pocko-ui/SelectInput";
const dropdown: any = [
{id: 1, name: '1', value: '1'},
{id: 2, name: '2', value: '2'},
{id: 3, name: '3', value: '3'}
]
const [defaultValue, setDefaultValue] = useState<any>('')
<SelectInput
label="Top"
type="COMMON"
id="id"
name="name"
dropdownRender={dropdown}
onChange={(i: any) => {
console.log(i);
setDefaultValue(i.value ? i.value : i);
}}
defaultValue={defaultValue}
dropdownPosition="top"
></SelectInput>
<SelectInput
label="Bottom"
type="COMMON"
id="id"
name="name"
dropdownRender={dropdown}
onChange={(i: any) => {
console.log(i);
setDefaultValue(i.value ? i.value : i);
}}
defaultValue={defaultValue}
wrapperClassName="my-2"
dropdownPosition="bottom"
></SelectInput>
<SelectInput
label="Auto"
type="COMMON"
id="id"
name="name"
dropdownRender={dropdown}
onChange={(i: any) => {
console.log(i);
setDefaultValue(i.value ? i.value : i);
}}
defaultValue={defaultValue}
dropdownPosition="auto"
></SelectInput>Input Value as Selected Value
Using the input value as the selected value
Show Code
import React, { useState } from "react";
import SelectInput from "pocko-ui/SelectInput";
const dropdown: any = [
{id: 1, name: '1', value: '1'},
{id: 2, name: '2', value: '2'},
{id: 3, name: '3', value: '3'}
]
const [defaultValue, setDefaultValue] = useState<any>('')
<SelectInput
type="COMMON"
id="id"
name="name"
dropdownRender={dropdown}
onChange={(i: any) => {
console.log(i);
if(i) {
setDefaultValue(i.value)
} else {
setDefaultValue(i)
}
}}
defaultValue={defaultValue}
isHandleInput={true}
></SelectInput>Customize Option Content
You can customize the content of the dropdown options
Show Code
import React, { useState } from "react";
import SelectInput from "pocko-ui/SelectInput";
const dropdown: any = [
{ id: 1, name: "OIE19022", age: "20" },
{ id: 2, name: "OIE19061", age: "22" },
{ id: 3, name: "SWE19048", age: "21" },
];
const [defaultValue, setDefaultValue] = useState<any>("");
<SelectInput
type="COMMON"
id="id"
name="name"
dropdownRender={dropdown}
onChange={(i: any) => {
console.log(i);
setDefaultValue(i.name);
}}
defaultValue={defaultValue}
renderOption={(item: any) => (
<>
<span>{item.name}</span>
<small className="d-flex flex-wrap align-items-center gap-1 text-secondary-emphasis anes-bill-justify-between">
<span>id:{item.id}</span>
<span>age{item.age}</span>
</small>
</>
)}
manualSearchTrigger={false}
></SelectInput>API
SelectInput
import SelectInput from 'pocko-ui/SelectInput';
import 'pocko-ui/SelectInput/index.css'| Property | Type | Default | Description | Required |
|---|---|---|---|---|
wrapperClassName | string | position: relative | The class name of the control wrapper. | - |
wrapperContentInputClassName | string | position: relative; form-control | The class name of the control. | - |
popupMenuClassName | string | position-absolute shadow border rounded... | The class name of the popup menu. | - |
lable | string | React.ReactNode | - | Customize left label render | - |
type | "COMMON" | "MULTI" | 'COMMON' | Set mode of Select | - |
size | string | any | 'auto' | Set size of Select | - |
id | string | any | - | The ID of the object data. | ✔ |
name | string | any | - | The Name of the object data. | ✔ |
kbcode | string | any | 'kb_code' | The keyboard code of the object data. | - |
dropdownRender | any[] | - | Select options. | ✔ |
dropdownPosition | "top" | "bottom" | "auto" | 'auto' | Select the location where the dropdown appears. | - |
onDropdownHide | () => void | - | Callback function that is triggered when the dropdown menu is hidden (e.g. click outside, option selected, or programmatically closed). | - |
renderOption | (item: any) => React.ReactNode | - | Function to customize how each option is rendered. Receives the item as a parameter. | - |
defaultValue | string | any | - | Initial selected option. | - |
cleanTrigger | CleanTriggerConfig | - | Configuration for the clear button at the top of the dropdown list. Contains: | |
- valid: A boolean to enable or disable the clear button. | ||||
- cleanValueLabel: Optional label for the clear button. | ||||
- cleanFunc: Optional custom function to execute when the clear button is clicked. | - | |||
index | string | number | any | - | When using a list, determine which row the component is on in the list. | - |
zIndex | string | any | 1101 | Set the depth value of the control to control the display of the pop-up layer appear above. Please set it when multiple controls are used at the same time. | - |
onChange | Function | - | Called when select an option or input value change. | ✔ |
onKeyDown | Function | any | - | The callback function that is triggered when keyboard is pressed. | - |
isDisable | boolean | false | Whether to disable the input. | - |
isHandleInput | boolean | false | Using the input value as the selected value. | - |
isDisableBodyScroll | boolean | false | Whether disable the body scroll. *you need npm i body-scroll-lock* | - |
dataService | any | - | Add a service class as a parameter to interact with external data sources or APIs. | - |
dataServiceFunction | string | - | The name of the function to be called from the service class. | - |
dataServiceFunctionParams | any[] | - | An array of parameters for the function call. Important: If the array contains $QUERY_STRING, the entered value will be treated as a parameter and passed out. | - |
dataServiceRetrieve | boolean | false | Is this service class function a retrieval class. Important: If the field is set to true, the server's retrieval interface will be called every time the input is entered. If it is not set to true, the interface will only be called once when the mouse is clicked. | - |
manualSearchTrigger | boolean | false | When set to true, disables automatic search on focus or initialization. Search must be triggered manually (e.g., by a button). Useful for scenarios like *input first, then search.* | - |