contigen / custom-select-component

custom select component with multiple modes for selections, built in React

Home Page:https://custom-select-component.pages.dev/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Custom Select Component

The component features an HTML details element as the main element

custom_video.mp4

The Select component has three props: autoselect (boolean) multiple (boolean) && defaultArr (required array), typed with React's PropTypes library.

The autoselect prop when added, activates automatic selections when using the tab key or ArrowUp && ArrowDown to focus; multiple prop when added, enables multiple selections or a single selection when omitted. The defaultArr prop contains the default options of the Select component.

Keyboard functionality

esc closes the component when open

PageUp moves the focus to the first item, while PageDown moves the focus to the last item

ArrowUp && ArrowDown keys control the focus of the items; the tab key does that by default, apparently.

Gotcha - using the Arrow keys to move focus once or twice after initial focus of the items has an awkward behaviour.

Code Structure

components folder contains only the select component; this project might be extended to a bigger project for building custom components.

utils folder contains simple helper functions used for the component

hooks folder contains a custom array hook used in the component

The Why

Something like a challenge, after seeing a random video about building a custom select component, I decided to do it, and be creative with it by avoiding unnecessary stuff - using the details HTML element as the main of the project, semantic by default.

Contributing

If you think there's a feature that needs to be implemented or anything, open a PR.

Usage

Feel free to use it, give credits.

This project was bootstrapped with Create React App.

Available Scripts

In the project directory, you can run:

npm start

Runs the app in the development mode.
Open http://localhost:3000 to view it in your browser.

The page will reload when you make changes.
You may also see any lint errors in the console.

npm run build

Builds the app for production to the build folder.
It correctly bundles React in production mode and optimizes the build for the best performance.

The build is minified and the filenames include the hashes.
Your app is ready to be deployed!

See the section about deployment for more information.

About

custom select component with multiple modes for selections, built in React

https://custom-select-component.pages.dev/


Languages

Language:JavaScript 69.0%Language:CSS 15.8%Language:HTML 15.2%