Skip to content
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

Create Multiselect Component #28

Closed
4 tasks
coreymcollins opened this issue Mar 16, 2018 · 5 comments
Closed
4 tasks

Create Multiselect Component #28

coreymcollins opened this issue Mar 16, 2018 · 5 comments
Assignees
Labels
R4R Issue or PR ready for review

Comments

@coreymcollins
Copy link
Contributor

What We Need

We should be able to select multiple terms (categories, tags, custom taxonomy) for use specifically in the Recent Posts block, but also to be utilized wherever necessary since it will be built as a component. The way ACF currently does this works well for us:

Component should, ideally, allow for:

  • Customization of taxonomy to search
  • Allow for setting of max number of terms to be selected
  • Allow for click-to-add and click-to-remove
  • Allow for typing to search for a term

I don't think it necessarily needs to look exactly like the ACF example, but all of that functionality is pretty 💯 IMO.

I did do some initial research into React-based multi-select tools here: #9 (comment)

I found this one which seemed to fill the needs we have, but was not able to get it to work fully: https://github.com/JedWatson/react-select

I'm not tied to that React Select component specifically, it was just one of the nicer ones I came across in my search.

Why do we need it?

Gutenberg does not feel it important to build a multiselect out of the box: WordPress/gutenberg#1044

Per the last comment there:

Going to close as we don't have any immediate need for such a component, so it's unlikely to be built unless someone else wants to contribute it.

This could be a cool win for us to build something useful that we need, then also get it into core Gutenberg!

@coreymcollins
Copy link
Contributor Author

Started digging at this again, but then I had a realization that we could probably use what @jomurgel is doing here (once it's complete) as a base for this: #10 (comment)

His component (if updated to his latest CodePen at the end of the thread) fits the criteria above in that it:

  • Is searchable
  • Allows for adding/removing multiple items

It would just need to also be able to:

  • Set min/max numbers of selected items
  • Allow for customization in what is being queried
  • Allow for manual drag & drop ordering

I don't think it's a 1:1 comparison, but I think once complete his work could get us like 80% of the way toward a general Multi Select component for taxonomies.

Thoughts @gregrickaby @kellenmace @jomurgel?

@jomurgel jomurgel mentioned this issue Mar 25, 2018
5 tasks
@jomurgel jomurgel self-assigned this Mar 30, 2018
@jomurgel
Copy link
Contributor

jomurgel commented Apr 9, 2018

Did some work on this, this weekend, as a proof of concept. This doesn't have any search functionality, but takes in a simple array, outputs to list and allows for adding/removing from top bar.

Branch: feature/#28-multiselect-component

Usage

import MultiSelect from '../../components/multiselect';

<MultiSelect value={ [ 'apples', 'oranges', 'peach', 'pears', 'plums' ] } />

The value prop takes in a simple array of strings at the moment.

Output
kapture 2018-04-09 at 8 04 33

There is a function of the component called toggleDropdown() which is intended to show/hide the dropdown on "input focus", but there was a problem. There is no input. I had a basic input working <input placeholder="Select Items..." type="text" value={ this.state.selectedItems } onChange="" /> which would output the selected items into the input value, but this doesn't allow the styling of the values.

Other considerations will be accessibility. I think we'll need to build out something with inputs or as a select field that functions as a form element rather than divs, but since this is a proof of concept I'm not too worried about it at this moment.

POC Pen:
https://codepen.io/jomurgel/pen/WzLYNG?editors=0100

Something like https://semantic-ui.com/modules/dropdown.html or http://jedwatson.github.io/react-select/ might also be worth looking into. Both have the functionality we're looking for and the later is already built in react. Though not really WP core ready, certainly worth looking into for our uses.

@efuller efuller self-assigned this Apr 17, 2018
@efuller
Copy link
Contributor

efuller commented Apr 17, 2018

Made some progress on this today.

I'm not 💯 on how the API for this component is going to work/look yet, but I'm just working to get some basic functionality in place.

I refactored a few functions and got tags and categories being pulled in from the API.

@efuller
Copy link
Contributor

efuller commented Apr 18, 2018

Update:

Made more progress here today.

I worked on turning everything into components.

At this point, both categories and tags are being displayed. Both can selected/deselected.

@paaljoachim
Copy link

paaljoachim commented Apr 30, 2021

What about adding some thoughts on this issue?
Query Block - more advanced / multi select query options
WordPress/gutenberg#30706

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
R4R Issue or PR ready for review
Projects
None yet
Development

No branches or pull requests

4 participants