Comments (29)
@leMaik Material UI is going to change AutoComplete API soon mui/material-ui#5062
btw Great Job!
from material-ui-chip-input.
@leMaik Would love to test out this feature if its ready.
from material-ui-chip-input.
@leMaik Works as expected. Thanks for a very useful component.
from material-ui-chip-input.
This would be possible, even without introducing breaking changes! Thanks for the suggestion, I'll add it soon.
from material-ui-chip-input.
After re-reading this issue, I found that this is already possible using dataSource
and dataSourceConfig
to specify which attributes should be used for the labels and the values. See the Auto Complete doc for more information.
At the moment, this component would use the labels as values, though. I don't really know how to handle this, because the user might create new values that don't distinguish between label and value (but only have a value).
Should I add an option to block users from creating custom chips (with values that aren't present in the data source) and treat custom chips (entered by the user) as values?
from material-ui-chip-input.
@umidbekkarimov They are changing everything soon with the next
branch and we actually already started contributing to it. Thanks for the hint! 👍
I'll update this component when the new AutoComplete
arrives.
from material-ui-chip-input.
I was able to use chipRenderer to define a function that processes an object to create the chip (using a value from a prop within that object) BUT: when I try to use handleAddChip or handleDeleteChip (which the documentation claims receive "chips" as arguments) I only receive the string value.
To elaborate. here's my code within the chipRenderer function ( where value is { text: , value: } ):
let displayText = value;
if (displayText !== null && typeof displayText === 'object') {
displayText = value.value;
key = value.text;
}
let chip = (
<Chip
key={key}
style={{ margin: '8px 8px 0 0', float: 'left', pointerEvents: isDisabled ? 'none' : undefined }}
backgroundColor={isFocused ? blue300 : null}
onTouchTap={handleClick}
onRequestDelete={handleRequestDelete}>
{displayText}
</Chip>
);
console.log(chip.key);
return chip;
I'm using the unique ID as the "key" for the element -- which I would be able to access if "chips" were actually passed to the handler functions. Any ideas for the right way to make this work? Besides creating a reverse lookup dict from displayed name back to ID?
from material-ui-chip-input.
@takealuke It's cool that you can already achieve this by using a custom chipRenderer
, that's the way I'd like this feature to be implemented. 👍 The documentation only says that onRequestAdd
and onRequestDelete
receive string values (the value of the chip to be added or deleted) though, so this is not a bug.
The problem right now is that there is no way to get onRequestAdd
to be called with a custom object, it's always the string the user entered. This is exactly what blocks this issue. I'll look into this soon.
from material-ui-chip-input.
I've been trying to use @takealuke's approach, the only way my custom chipRenderer gets called is if the dataSource fields contains strings, that creates other problems,
If I supply a dataSourceConfig={{text:'label', value: 'value'}},
then I get the Invalid prop dataSource[0]
of type object
supplied to ChipInput
, expected string
.
error...
I'd really love to have that dataSource as array of object working !
from material-ui-chip-input.
@max-l I totally get that you'd love to have this working. At the moment, this feature isn't implemented, I'm afraid. 😞 That's why it doesn't work for you. I'll try to implement this this weekend. 👍
from material-ui-chip-input.
@chaitanya0bhagvan I finally started adding this. 🎉 Please take a look at the key-value-chips branch and let me know what you think and if it works!
It still has some bugs and isn't finished.
from material-ui-chip-input.
Thanks! I tried but it's not working for me. It still works with standard flat array as dataSource, but not with a custom dataSourceConfig :
const dataSourceConfig = {
text: 'text',
value: 'value',
}
The dropdown options do show, but selecting an option from the dropdown doesn't add it as a chip.
I am using MaterialUI 0.16.0
from material-ui-chip-input.
@voxbox-io Are you sure? That worked for me, in the story I added.
from material-ui-chip-input.
Quite sure, this simple example is not working for me:
<ChipInput
dataSource={[{ text: 'Chip 1', value: 'one' }, { text: 'Chip 2', value: 'two' }]}
dataSourceConfig={{ text: 'text', value: 'value' }}
defaultValue={[{ text: 'Chip 1', value: 'one' }]}
/>
It shows default values OK, but clicking on any value from dropdown throws error 'Cannot read property 'refs' of null' at line 212
if (!this.autoComplete.refs.menu)
from material-ui-chip-input.
@leMaik Yes I got the same error as @voxbox-io . I cloned your repo and ran your storybook example even that is not working. I am not able to add or delete chips. I tried this code in my project and found that the call backs are not getting called at all.
from material-ui-chip-input.
Okay, okay. 😉 I'll fix it this weekend, I promise!
from material-ui-chip-input.
@chaitanya0bhagvan @voxbox-io I think I fixed this. :) Could you please try again if it works for you now?
from material-ui-chip-input.
Just tried this branch : a6e266d
and I confirm that it works when using a dataSource of objects and setting the proper
dataSourceConfig
Thanks !
from material-ui-chip-input.
Works like a charm now, thanks! 👍
from material-ui-chip-input.
Great! I'll merge the changes into master, then.
A new issue that came to my mind is that it's currently not possible to disallow adding custom chips (with values that are not available in dataSource
) in uncontrolled mode. I'm not sure if this is something that this component should handle or if this should be left for the reducer to decide in controlled mode. I'd prefer the later approach, but I'd appreciate your feedback.
from material-ui-chip-input.
@leMaik I am getting a error when I press 'Key Down' to open the autocomplete options.
from material-ui-chip-input.
@chaitanya0bhagvan Please open a new issue, the error doesn't seem to be related to this issue. 😉
from material-ui-chip-input.
@chaitanya0bhagvan I can't reproduce the error, but I'm not sure if I did the same steps. Could you please provide a minimal example that produces the error?
from material-ui-chip-input.
@leMaik You can reproduce this error in your story book. Select with autocomplete or objects as chips, uncontrolled or objects as chips, controlled click on the input and press down arrow twice. As the autocomplete options is displayed an error is thrown in the console.
from material-ui-chip-input.
@chaitanya0bhagvan Thank you! 👍 Moved this to #32.
from material-ui-chip-input.
@leMaik I can't get it working when trying @voxbox-io example with custom chip renderer. The autocomplete is showing the results but when I click on the item, chip is not created. Do you have an idea what could be wrong? Thanks!
P.S. chip is created fine when it's a custom chip - not selected from autocomplete
from material-ui-chip-input.
@calic39 That might be a bug, I'll check that tomorrow. Maybe your chipRenderer
is not implemented correctly, though. Could you please provide some code?
PS: Would you mind opening a new issue for your question?
from material-ui-chip-input.
@leMaik Sorry man, you were right, I implemented chipRenderer the wrong way. Thanks for the great work!
from material-ui-chip-input.
@calic39 Glad that I could help! 😊
from material-ui-chip-input.
Related Issues (20)
- On Android Mobile: newChipKeys not working HOT 1
- dataSource is not working HOT 1
- Update storybook examples
- How to add date/datetime values as chips?
- Can I add icon to input field like in TextField by using Input Adornments?
- Label positioning on "outlined" variant is incorrect.
- Dependency version mismatch error: Unable to install this module HOT 12
- Dependency error with material-ui/core v5 HOT 3
- Make chips editable in the same place HOT 1
- "future" compatibility issue HOT 1
- Module not found HOT 1
- Make ChipInput a required field in a form HOT 1
- Chip note adding using space bar HOT 1
- MUI v5 HOT 1
- Please add React 17 support HOT 7
- Is there a way to change OnBlur so that focusing and then clicking on a chip doesn't trigger it?
- Submit button not working after update the Android system WebView in android device.
- Performance issue with pasting 100+ items in chip input. Cannot add more chips and DOM freezes
- Should ChipInput component be wrapped by Form tag ?
- unable to install in react 18v HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from material-ui-chip-input.