Custom Dropdown/Select
See original GitHub issueDescription
Create a custom, keyboard compliant dropdown/select component with search capabilities.
Problem Statement/Justification
- Most designs and apps need a more dynamic
select
component, such asreact-select
. - I needed to create a custom
Select
component, while using Chakra-UI’s infra and system utils, hooks. Referencing theMenu
component, I added optional search to filter out the listed options, theDescendantsContext
for keyboard focus management, along with customSelectOptions
for rending labels and optional icons, etc.
Proposed Solution or API
I found the react-select
format much more versatile in terms of controlling and rendering data.
Select
will render and array of OptionTypes
.
export type OptionType = {
icon?: string;
label: string;
value: string;
}
Example usage:
function SelectUsage() {
const [state, setState] = React.useState(null)
const options = [
{ label: 'Green', value: 'green' },
{ label: 'Green-Yellow', value: 'greenyellow' },
{ label: 'Red', value: 'red' },
{ label: 'Violet', value: 'violet' },
{ label: 'Forest', value: 'forest' },
{ label: 'Tangerine', value: 'tangerine' },
{ label: 'Blush', value: 'blush' },
{ label: 'Purple', value: 'purple' },
]
return (
<>
<Select
isSearchable
defaultValue={options[0].value}
value={state}
options={options}
onChange={(value) => setState(value)}
/>
</>
)
}
- container
SelectDescendantsProvider
,SelectProvider
&StylesProvider
Select
consumes four internal components, each with its relative context.
<SelectContainer />
<SelectInputValue />
<SelectList />
<SelectOption />
Alternatives
- Structure: maybe moving the components out of the context, leaving the developers more control of the general structure of the elements? I found this be more difficult in terms of controlling data.
<Select>
<SelectContainer>
<SelectInputValue /> // handles current state, and search state
</SelectContainer>
<SelectList>
<SelectOption label="Green" value="green" />
<SelectOption label="Red" value="red" />
<SelectOption label="Yellow" value="yellow" />
<SelectOption label="Blue" value="blue" />
<SelectOption label="Black" value="black" />
</SelectList>
</Select>
Additional Information
- current component development
Issue Analytics
- State:
- Created 2 years ago
- Reactions:43
- Comments:39 (1 by maintainers)
Top Results From Across the Web
How To Create Custom Select Menus - W3Schools
Learn how to create custom select boxes with CSS and JavaScript. ... Surround the select box within a "custom-select" DIV element.
Read more >How to Create a Custom Select Dropdown using HTML, CSS ...
A post on how to create a custom select dropdown using HTML, CSS and JavaScript. Should you build it from scratch or use...
Read more >Custom Select Styles with Pure CSS
A few properties and techniques our solution will use: clip-path to create the custom dropdown arrow; CSS grid layout to align the native...
Read more >Awesome CSS Select Styles You Can Use Right Now
CSS select styles offer visitors a dropdown selection of options. ... This is a demo showing how to make a cross-browser custom-styled ...
Read more >31 CSS Select Boxes - Free Frontend
Collection of free HTML and CSS custom select box code examples: dropdown, multiple, custom arrow, etc. Update of April 2019 collection.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I made a chakra wrapper for react-select recently, if anyone else is looking for something like this! https://github.com/csandman/chakra-react-select
You could check out choc autocomplete.