unovue / radix-vue

Vue port of Radix UI Primitives. An open-source UI component library for building high-quality, accessible design systems and web apps.
https://radix-vue.com
MIT License
3.71k stars 231 forks source link

[Feature]: Tags Input. Support multiple delimiters #1400

Closed romansp closed 3 weeks ago

romansp commented 3 weeks ago

Describe the feature

Improve TagsInputInput to allow multiple delimiters so that multiple formats of pasted data can be supported.

For example I use TagsInput component to collect and submit list of email. Occasionally this list will be pasted from other sources for example it may be comma-separated list or tabular data like google sheets.

Data example

jane.doe@example.com, john.smith@example.com, alex.jones@example.com, taylor.lee@example.com, casey.miller@example.com

Proposed usage

const delimiters = ["\t", "\n\r", "\n", " ", ","]

<TagsInputInput :delimiter="delimiters" />

Additionally it would need to strip out empty entries after string split for modelValue to be accurate.

Originally for my use-case I was thinking to avoid default addOnPaste and implement custom @paste handler, but wondering if there's interest to have this functionality built in.

Additional information

zernonia commented 3 weeks ago

HAHAHAHA I was about to add this feature request too! 😂

zernonia commented 3 weeks ago

Instead of passing as an array of delimiter, maybe we allow string | RegExp as prop?

romansp commented 3 weeks ago

Instead of passing as an array of delimiter, maybe we allow string | RegExp as prop?

I agree string | RegExp would be the best since it already fits String.prototype.split and String.prototype.replaceAll so this feature just comes pretty much for free.

But string[] just seems more ergonomic to use than RegExp to be honest. We would also need to validate passed RegExp to have global flag set as it's required for replaceAll. Or print warning when it isn't global.

So maybe string | string[] | RegExp as prop?