rc-simple-select
v1.10.2
Published
This is a customizable Select component for React applications. It provides a dropdown selection interface with support for single and multi-select options, search functionality, and custom styling.
Downloads
26
Readme
Rc Simple Select
This is a customizable Select component for React applications. It provides a dropdown selection interface with support for single and multi-select options, search functionality, and custom styling.
Features
- Single and multi-select modes
- Searchable options
- Customizable styling
- Keyboard navigation support
- Custom rendering of selected values
- Accessible
- Individual option customization
Installation
yarn add rc-simple-select
or
npm install rc-simple-select
Usage
Here's a basic example of how to use the Select component with Options:
import React from 'react';
import { Select,Option } from 'rc-simple-select';
const MyComponent = () => {
const handleSelect = (value) => {
console.log('Selected value:', value);
};
return (
<Select onSelect={handleSelect}>
<Option value="option1">Option 1</Option>
<Option value="option2">Option 2</Option>
<Option value="option3" disabled>Option 3</Option>
<Option value="option4" hidden>Option 4</Option>
</Select>
);
};
Select Component Props
The Select
component accepts the following props:
isMulti
: Boolean to enable multi-select modevalues
: Selected value(s)closeOnSelect
: Boolean to close the dropdown on selection (default: true)selectClassName
: Custom class name for the select containeroptionWrapperClassName
: Custom class name for the options wrapperoptionShowerClassName
: Custom class name for the selected option displayisSearchable
: Boolean to enable search functionalityplaceholder
: Placeholder text when no option is selectedinputPlaceholder
: Placeholder text for the search inputlabel
: Label for the select componentselectRef
: Ref object for the select containerIconComponent
: Custom component for the dropdown icononSelect
: Callback function called when an option is selectedrenderValue
: Custom render function for selected valuesonMenuOpen
: Callback function called when the dropdown opensonMenuClose
: Callback function called when the dropdown closes
Option Component Props
The Option
component is used to define individual options within the Select component. It accepts the following props:
value
: (Required) The value of the optionhidden
: Boolean to hide the optiondisabled
: Boolean to disable the optionoptionClassName
: Custom class name for the optionoptionSelectedClassName
: Custom class name for the selected state of the optionoptionRef
: Ref object for the option elementonRender
: Custom render function for the option
Accessibility
The component is built with accessibility in mind, using appropriate ARIA attributes and keyboard navigation support. The Option
component uses the role="option"
attribute and includes aria-disabled
for disabled options.
Customization
You can customize the rendering of individual options by using the onRender
prop of the Option
component. This allows you to create complex option layouts or add additional functionality to each option.
Contributing
Contributions are welcome! If you find any issues or want to add new features, feel free to open an issue or submit a pull request.
License
This project is licensed under the MIT License.