2.7.0 • Published 1 year ago

agr-custom-dropdown v2.7.0

Weekly downloads
-
License
ISC
Repository
github
Last release
1 year ago

A simple and customizable dropdown component built with React and TypeScript.

Features

  • Searchable dropdown list with the input field
  • Select an option with a click
  • On change event
  • Keyboard navigation using the arrow keys to move up and down the options
  • Required field validation optionnel
  • Required message optionnel
  • Customizable styles

Installation

You can install the CustomDropdown component using npm: npm install agr-custom-dropdown or yarn add agr-custom-dropdown

Usage

Here is a basic example of how to use the CustomDropdown component:

import React from "react";
import CustomDropdown from "./CustomDropdown";

const options = [
  { label: "Option 1", value: 1 },
  { label: "Option 2", value: 2 },
  { label: "Option 3", value: 3 }
];

const handleChange = (selectedOption) => {
  console.log(selectedOption);
};

function App() {
  return (
    <div>
      <CustomDropdown
        options={options}
        onChange={handleChange}
        required={true}
        requiredMessage="A option must be selected."
        forceRequired={false}
        placeholder="Select an option"
      />
    </div>
  );
}

export default App;

Keyboard Actions

  • Use the up and down arrow keys to navigate the options.
  • Press Enter to select the currently highlighted option.
  • Press Esc to close the options dropdown.

Props

The CustomDropdown component takes the following props:

PropTypeRequiredDescription
optionsOption[]YesAn array of objects representing the options in the dropdown list. Each object should have a label and a value property.
onChange(selectedOption: Option) => voidYesA callback function that is called when an option is selected. The selected option is passed as a parameter to the callback function.
requiredbooleanNoIndicates if the dropdown is required or not. If the property is present and is set to true, the dropdown will have a required class.
requiredMessagestringNoMessage, if the property required is set to true (default 'this field is required')
forceRequiredbooleanNoA flag indicating if the dropdown should always display the requiredMessage, even if an option has been selected.
placeholderstringNoThe placeholder text to display in the input field (default 'Search or select options...')

Contributing

If you find any bugs or have any suggestions for improvements, feel free to open an issue or submit a pull request on the GitHub repository.

License

This component is open-source software licensed under the MIT License.

2.7.0

1 year ago

2.6.0

1 year ago

2.5.0

1 year ago

2.4.0

1 year ago

2.3.0

1 year ago

2.2.0

1 year ago

2.1.0

1 year ago

2.0.0

1 year ago

1.9.0

1 year ago

1.8.0

1 year ago

1.7.0

1 year ago

1.6.0

1 year ago

1.5.0

1 year ago

1.4.0

1 year ago

1.3.0

1 year ago

1.2.0

1 year ago

1.1.1

1 year ago

1.1.0

1 year ago

1.0.34

1 year ago

1.0.33

1 year ago

1.0.32

1 year ago

1.0.31

1 year ago

1.0.30

1 year ago

1.0.29

1 year ago

1.0.28

1 year ago

1.0.27

1 year ago

1.0.26

1 year ago

1.0.25

1 year ago

1.0.24

1 year ago

1.0.23

1 year ago

1.0.22

1 year ago

1.0.21

1 year ago

1.0.20

1 year ago

1.0.19

1 year ago

1.0.18

1 year ago

1.0.17

1 year ago

1.0.16

1 year ago

1.0.15

1 year ago

1.0.14

1 year ago

1.0.13

1 year ago

1.0.12

1 year ago

1.0.11

1 year ago

1.0.10

1 year ago

1.0.9

1 year ago

1.0.8

1 year ago

1.0.7

1 year ago

1.0.6

1 year ago

1.0.5

1 year ago

1.0.4

1 year ago

1.0.3

1 year ago

1.0.2

1 year ago

1.0.1

1 year ago

1.0.0

1 year ago