Add new delimiter option
Motivation:
Currently, the library only allows a comma as the delimiter. This limitation restricts user flexibility in tag entry. By adding support for customs delimiters, users can customize their input experience and improve usability.
Proposed Solution:
A map of additional characters has been added to be accepted as delimiters. If none are provided, the comma (,) will be used by default. This change facilitates the addition of new characters in the future. A new option has also been created to allow users to customize their delimiter preferences.
Usage:
tagger(document.querySelector('[name="tags"]'), {delimiter: ";"});
in React:
const taggerOptions = {
delimiter: ";",
};
Links:
Close #39
Note: This is one of my first contributions to open source. Please feel free to suggest any changes or improvements.
You don't need to keep a map with keys, there is key property on the event object. The current code don't use it but you can change it.
I made the suggested changes and updated all instances of keyCode to maintain consistency. Does that work for you?
Thanks!
I would add:
var key = event.key.toUpperCase();
to make sure that the name of the key is correct.
Also you need to update this line:
nativeInputValueSetter.call(this._input, this._tags.join(','));
and
this._tags = this._input.value.split(/\s*,\s*/).filter(Boolean);
To use delimiter.
I'm also not sure if you should even update the keydown event, the issue was about the delimiter in <input> element. I'm not sure if it's a good idea to change the key you need to press.
I’m not quite sure I understand your message. The idea behind the delimiter is to create a tag when a specific key is pressed. Isn’t the keydown event responsible for handling key presses? I thought that’s where we would handle the new input tag.
Could you clarify your thoughts on this?
No, delimiter is not when a specific key is pressed, the issue was about input element. Delimiter is something in between, like foo,bar,baz.
Please read the issue you're closing:
Currently the library only allows comma as delimiter. It would be great to have an option to set the delimiter (for instance semi-colon) when initializing.
key word is "initializing"
Closing, since this implements something totally different that it should.