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'
PropertyTypeDefaultDescriptionRequired
wrapperClassNamestringposition: relativeThe class name of the control wrapper.-
wrapperContentInputClassNamestringposition: relative; form-controlThe class name of the control.-
popupMenuClassNamestringposition-absolute shadow border rounded...The class name of the popup menu.-
lablestring | React.ReactNode-Customize left label render-
type"COMMON" | "MULTI"'COMMON'Set mode of Select-
sizestring | any'auto'Set size of Select-
idstring | any-The ID of the object data.
namestring | any-The Name of the object data.
kbcodestring | any'kb_code'The keyboard code of the object data.-
dropdownRenderany[]-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.-
inputIdstring | any-❗ The inputId of the internal component, which identifies the uniqueness of the component.
titleIdstring | any-❗ The titleId of the internal component, which identifies the uniqueness of the component.
defaultValuestring | any-Initial selected option.-
cleanTriggerCleanTriggerConfig-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.-
indexstring | number | any-When using a list, determine which row the component is on in the list.-
zIndexstring | any1101Set 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.-
onChangeFunction-Called when select an option or input value change.
onKeyDownFunction | any-The callback function that is triggered when keyboard is pressed.-
isDisablebooleanfalseWhether to disable the input.-
isHandleInputbooleanfalseUsing the input value as the selected value.-
isDisableBodyScrollbooleanfalseWhether disable the body scroll. *you need npm i body-scroll-lock*-
dataServiceany-Add a service class as a parameter to interact with external data sources or APIs.-
dataServiceFunctionstring-The name of the function to be called from the service class.-
dataServiceFunctionParamsany[]-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.-
dataServiceRetrievebooleanfalseIs 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.-