-
-
Notifications
You must be signed in to change notification settings - Fork 3.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Custom Dropdown/Select #4311
Comments
You could check out choc autocomplete. |
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 |
Hi :) |
@acarolinafbarros Are you asking for the full code for my wrapper? |
yes |
@acarolinafbarros So I originally made this package as a public Gist that people could just copy into their projects and tweak as needed. You can find that here: Since making it into a package I have added a few new features and converted it to TypeScript. You can find the main component with my customizations here:
EDIT: There is now a full style customization system that functions similarly to the original package's |
Thanks @csandman 🙇♀️ |
Is there a plan to add this to Chakra UI React components, any roadmap? That would be just awesome! |
There have been some major improvements in version 2 and version 3 of my |
@csandman Thanks a lot for this package!! Would it be possible to allow to use React nodes as labels? I opened an issue: csandman/chakra-react-select#41 |
@csandman this package is awesome! Thank you so much for creating it and for the great docs. I created a chakra-ui |
@CaitlinSweeney Thanks for the feedback, I'm glad you like it! |
@csandman can you please export out SelectType interface in your library? |
Sure I can do that some time tomorrow. However I'm probably going to rename it SelectComponent |
Thanks! I'm looking forward to it. |
@csandman there is one issue when using your package, It seems your package default theme is overriding my Chakra default theme is there any solution and cause ordering issues? |
Could you elaborate on that? Like it's overriding the theme from other unrelated components? Or changes to you theme aren't propegating to the select? Can you give me an example of a specific component/style? |
@fransiscushermanto The component types are now being exported in |
Hi! |
Doesn't make sense to close it. Problem is still here |
Hello - I'd be interested in creating a simpler implementation of this request by using the existing Menu components. But this component would implement WAI listbox properties, so it could be used as a form element. Is that something that would be a good addition to the chakra library? |
Hi! |
Don't close |
That is doable. I created a I ended up using |
@CaitlinSweeney The Just concluded Chakrathon was based on Custom Select, so it's available already, they're just working on implementing it into the Chakra Codebase. |
@anubra266 was the whole Chakrathon based on a custom select, or was that just what the winners made? |
@csandman the whole chakrathon was based on it. |
@anubra266 oh I see it now. so it was based on making a single select component, no multi-select capabilities (unless the team decided to add them). |
@csandman I don't expect that multi select will take too much effort once single select is settled. |
I'd tend to disagree, making selected options in a multi-select component composable in a similar way to how the rest of the chakra components are is a pretty big step from making a single-select component. I'd be happy to be proven wrong, but it's a whole different challenge. |
@csandman, chakra ui has a |
I more meant composability for the end user, as in how you'd store them and display them as their own list of a built in chakra component. The list of options to select is relatively straightforward (similar to the menu), but I'm finding it very difficult to imagine how you could use the list of selected options to display those components in a way that aligns with any of the patterns other Chakra components use. |
I'm not sure I understand what you mean here @csadman, perhaps you could explain in terms of |
@anubra266 sure, // The container for the selected option components
const MultiValueContainer = (props: MultiValueGenericProps<ColourOption>) => {
return (
<Tooltip content={'Customise your multi-value container!'}>
<components.MultiValueContainer {...props} />
</Tooltip>
);
};
export default () => (
<Select
isMulti
components={{ MultiValueContainer }}
/>
); Where as, if we take the Chakra UI <Menu>
<MenuButton as={Button} rightIcon={<ChevronDownIcon />}>
Actions
</MenuButton>
<MenuList>
{/* Or map a list of options */}
<MenuItem>Download</MenuItem>
<MenuItem>Create a Copy</MenuItem>
<MenuItem>Mark as Draft</MenuItem>
<MenuItem>Delete</MenuItem>
<MenuItem>Attend a Workshop</MenuItem>
</MenuList>
</Menu> The big benefit of this pattern is that it allows you to customize each of the sub-components on their own, as you're manually placing them in the DOM. For the most part, this pattern works fine for a single select, as it essentially follows the same pattern as the
const [selectedOptions, setSelectedOptions] = useState([]);
return (
<Select clearable isDisabled={isDisabled || isLoading} onChange={setSelectedOptions}>
<SelectedOptions>
{selectedOptions.map((option) => (
<SelectedOption option={option} />
))}
</SelectedOptions>
<SelectSelector />
<SelectMenu>
<SelectOption isDisabled>Option 1</SelectOption>
<SelectOption value="option-value-1">Option 2</SelectOption>
<SelectOption value="option-value-3">Option 3</SelectOption>
</SelectMenu>
</Select>
); This goes against Chakra's patterns as none of the other Chakra components require you to manage state outside of the rendered components in order to render them properly.
<Select clearable isDisabled={isDisabled || isLoading}>
<SelectedOptions option={<SelectedOption fontSize="lg" />} />
<SelectSelector />
<SelectMenu>
<SelectOption isDisabled>Option 1</SelectOption>
<SelectOption value="option-value-1">Option 2</SelectOption>
<SelectOption value="option-value-3">Option 3</SelectOption>
</SelectMenu>
</Select> This, like I mention above, does not follow a pattern that any of the other Chakra components use, and makes it a little more complicated to customize each
<Select placeholder="Select option" value={value} onChange={onChange}>
{({ selectedOptions }) => (
<>
<SelectedOptions>
{selectedOptions.map((option) => (
<SelectedOption option={option}>{option.label}</SelectedOption>
))}
</SelectedOptions>
<SelectButton>{option?.label ?? "Placeholder"}</SelectButton>
<SelectMenu>
<SelectOption value="option-value-1">Option 1</SelectOption>
<SelectOption value="option-value-2">Option 2</SelectOption>
</SelectMenu>
</>
)}
</Select> This is just something no other Chakra components do, and render props as a pattern have generally fallen out of favor with the introduction of hooks. I doubt they'll go this route, for either their new single select or multi select components. So these are the reasons I think it'll get complicated to implement a multi select without breaking away from some of the patterns which make up Chakra's design system. I've put a lot of thought in to how you might accomplish this in a way that strictly follows the component composition pattern that other Chakra components use, but I've had no luck. But hey, I could always be missing another implementation pattern, and I wouldn't be upset if they come up with a way to make it possible. This is just my thought process after thinking about it for some time. Honestly, I'm glad to be able to put it into words haha. |
Oh I see @csandman you're talking of tags. The way I was thinking of it, is selected items, have a checkmark or whatever way the developer chooses. |
@anubra266 Sure, so if they decide not to include any implementation for displaying the list of selected options other than marking them in the list itself, then my point is moot. But that get's tricky if people want to do anything like react-select where the options are displayed inside the select. Can you link me to an example of what you're talking about with React Aria? I've seen the package before but not the multi-select. |
@csandman they don't have an official implementation in the docs, but a maintainer kinda showed an implementation, can't find it now. |
Hi! |
Not stale |
This has been created in Zag.js and will land in Chakra UI pretty soon: |
Hey @segunadebayo. Any ETA on this? |
@segunadebayo any ETA? |
Description
Create a custom, keyboard compliant dropdown/select component with search capabilities.
Problem Statement/Justification
select
component, such asreact-select
.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 ofOptionTypes
.Example usage:
SelectDescendantsProvider
,SelectProvider
&StylesProvider
Select
consumes four internal components, each with its relative context.Alternatives
Additional Information
Screen.Recording.2021-06-30.at.6.12.44.PM.mov
The text was updated successfully, but these errors were encountered: