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>('')
<SelectInput
id="id"
name="name"
dropdownRender={dropdown}
inputId={"demo1-input-id"}
titleId={"demo1-title-id"}
onChange={(i: any) => {
console.log(i);
setDefaultValue(i.value)
}}
></SelectInput>
<SelectInput
id="id"
name="name"
dropdownRender={dropdown}
inputId={"demo1_1-input-id"}
titleId={"demo1_1-title-id"}
onChange={(i: any) => {
setDefaultValue2(i.value);
}}
defaultValue={defaultValue2}
wrapperClassName="mt-2"
cleanTrigger={{
valid: true,
cleanValueLabel: "Clean",
cleanFunc: () => {
setDefaultValue2("");
},
}}
></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}
inputId={"demo2-input-id"}
titleId={"demo2-title-id"}
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}
inputId={"demoTop-input-id"}
titleId={"demoTop-title-id"}
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}
inputId={"demoTop-input-id"}
titleId={"demoTop-title-id"}
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}
inputId={"demoTop-input-id"}
titleId={"demoTop-title-id"}
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}
inputId={"demo3-input-id"}
titleId={"demo3-title-id"}
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", value: "1" },
{ id: 2, name: "OIE19061", value: "2" },
{ id: 3, name: "SWE19048", value: "3" },
];
const [defaultValue, setDefaultValue] = useState<any>("");
<SelectInput
type="COMMON"
id="id"
name="name"
dropdownRender={dropdown}
inputId={"demo4-custom-input-id"}
titleId={"demo4-custom-title-id"}
onChange={(i: any) => {
console.log(i);
setDefaultValue(i.value ? i.value : i);
}}
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>value:{item.value}</span>
</small>
</>
)}
></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. | - |
renderOption | (item: any) => React.ReactNode | - | Function to customize how each option is rendered. Receives the item as a parameter. | - |
inputId | string | any | - | ❗ The inputId of the internal component, which identifies the uniqueness of the component. | ✔ |
titleId | string | any | - | ❗ The titleId of the internal component, which identifies the uniqueness of the component. | ✔ |
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. | - |