Skip to content
This repository has been archived by the owner on Dec 23, 2022. It is now read-only.

How to forbit the use of a character in a chip label ? #211

Closed
nicolas-saubi opened this issue May 16, 2018 · 5 comments
Closed

How to forbit the use of a character in a chip label ? #211

nicolas-saubi opened this issue May 16, 2018 · 5 comments

Comments

@nicolas-saubi
Copy link

nicolas-saubi commented May 16, 2018

Hi,

I would like the "space" to be my chip creator, BUT, I don't want to create empty chips (done with "handleBeforeAdd") and I don't want the input to contains the typed "space" (which "handleBeforeAdd" can't do).

How can I achieve that ? I bet I would need to set the state of the embedded input through some "onInputChange", but it doesn't seems to be possible. Any idea ?

Thanks

@leMaik
Copy link
Member

leMaik commented May 16, 2018

You can achieve that by adding the keycode for space (32) to the newChipKeyCodes prop. E.g. newChipKeyCodes={[13, 32 ]} for enter and space.

@leMaik leMaik changed the title Q.v1. How to forbid the use of a character in a chip ? How to add chips with space bar? May 16, 2018
@leMaik leMaik added the v1 label May 16, 2018
@nicolas-saubi
Copy link
Author

Sorry my question was uncomplete, but my previous title was better I think...

Of course I did the newChipKeyCodes thing, but let's imagine you want at least 3 characters long chips...
So I have the space bar listened for creation with newChipKeyCodes, I have handleBeforeAdd to return false if trim(string).length < 3, BUT this way, the input is fulled with spaces I don't want. I want space bar to be removed from the input when the handleBeforeAdd returns false...

Clearly, I want to forbid the use of a character in chip label, while being able to use this character to create a chip (which newChipKeyCodes achieves).

@nicolas-saubi nicolas-saubi changed the title How to add chips with space bar? How to forbit the use of a character in a chip label ? May 17, 2018
@nicolas-saubi
Copy link
Author

Any news ?

@JonathasRodrigues
Copy link
Contributor

I did a pull request that can help you, but we have to wait the merge.

See here
#251

@leMaik
Copy link
Member

leMaik commented Dec 29, 2018

@nsaubi @JonathasRodrigues It's been a while (I was pretty busy the last 6 months), but this is finally possible by using controlled mode for the text input with inputValue and onUpdateInput. I added an example here.

A new release will be out in a few minutes. 🚀

@leMaik leMaik closed this as completed Dec 29, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants