question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

@segunadebayo @tioluwani94 Really great work on everything so far!

I notice in the roadmap that you are planning to build a custom select component in Chakra and I wanted to start a discussion about how that would look.

In my experience for real-world projects, select boxes often need features that are not provided by the native HTML select such as search, multi-select, and dynamic option loading. I frequently turn to the react-select package because I feel it has the best API and available features. How do you see Chakra handling this problem, if at all? I see a few options:

  • Chakra provides a simplistic select that doesn’t have these “fancy” features and it is the responsibility of the end-developer to use a third party library if necessary
  • Chakra writes its own select that does implement these features
  • Chakra wraps an existing library like react-select

I am in favor of options 1 and/or 3 and would like to hear the community’s opinions about the pros/cons of each.

Side note: This issue is also going to apply to other “complex” components such as date pickers

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:24
  • Comments:23 (12 by maintainers)

github_iconTop GitHub Comments

46reactions
csandmancommented, Sep 22, 2021

I’m not sure what the progress on this is but I wanted to share my wrapper for react-select’s multi component. I needed something like this to use with Chakra and wanted it to look the same so I spent a decent amount of time making it match visually. If you want to use it, here’s the source. Feel free to use/modify it as needed until an official Chakra version comes out.

I’m also curious if anyone has any recommendations to change this, I’m still very new to the inner workings of Chakra and I’m sure I didn’t do everything in the best way.

EDIT

I’ve noticed that this has gotten a positive reception so I figured I’d post an update. The wrapper I posted is now updated to more accurately work with the react-select controls, and also now has a size prop! it can accept sm, md, and lg and it reflects the sizes of the normal chakra text input.

EDIT 2

I made it into an NPM package! https://www.npmjs.com/package/chakra-react-select

11reactions
segunadebayocommented, Sep 7, 2019

Hi @Vynlar .

I’m currently trying to figure out the API for Chakra’s Custom Select. I’d prefer we wrap an existing library and make the final API really simple and composable.

I also use react-select as well but I’m a bit reluctant to use it in Chakra due to its size. I’m currently testing use-downshift, a hook based library built for downshift and it’s quite interesting and should give us the composition and functionality we need.

Here’s how I envision the API for Chakra’s Simple Select (pretty similar to native):

// Simple Select
<Select isSearchable={true} value="..." defaultValue="...">
   <Option value="...">Option 1</Option>
   <Option value="...">Option 2</Option>
</Select>
// Grouped Select
<Select isSearchable={true} value="..." defaultValue="...">
  <OptionGroup label="Option Group">
     <Option value="...">Option 1</Option>
    <Option value="...">Option 2</Option>
  </OptionGroup>
</Select>

The advantage of using use-downshift is that we can compose Autocomplete, Typeahead, and Multiselect out of it. Check out the docs: https://use-downshift.now.sh/docs-dropdown

Let me know what you think @Vynlar .

PS: I’m currently playing with it in CodeSandbox: https://codesandbox.io/s/chakra-playground-3tbl9

Read more comments on GitHub >

github_iconTop Results From Across the Web

<select>: The HTML Select element - HTML - MDN Web Docs
The <select> element has some unique attributes you can use to control it, such as multiple to specify whether multiple options can be...
Read more >
Select - Ant Design
Select component to select value from options. When To Use. A dropdown menu for displaying choices - an elegant alternative to the native...
Read more >
Components - React Select
React-Select allows you to augment layout and functionality by replacing the default components with your own, using the components property.
Read more >
Select component — Vuetify
In this example we also use the return-object prop which will return the entire object of the selected item on selection.
Read more >
Select | Angular Material
<mat-select> is a form control for selecting a value from a set of options, similar to the native <select> element. You can read...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found