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

Add new delimiter option #51

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

rog404
Copy link

@rog404 rog404 commented Oct 3, 2024

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.

@jcubic
Copy link
Owner

jcubic commented Oct 3, 2024

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.

@rog404
Copy link
Author

rog404 commented Oct 4, 2024

I made the suggested changes and updated all instances of keyCode to maintain consistency. Does that work for you?

Thanks!

@jcubic
Copy link
Owner

jcubic commented Oct 4, 2024

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.

@rog404
Copy link
Author

rog404 commented Oct 4, 2024

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?

@jcubic
Copy link
Owner

jcubic commented Oct 5, 2024

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.

@jcubic
Copy link
Owner

jcubic commented Oct 5, 2024

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"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

option to specify the delimiter
2 participants