primefaces / primevue

Next Generation Vue UI Component Library
https://primevue.org
MIT License
10.28k stars 1.21k forks source link

AutoComplete: V4 Chips Component was Deprecated, AutoComplete with the multiple param does not allow the very convenient addOnBlur or separator params #6611

Open duganbrianj opened 2 days ago

duganbrianj commented 2 days ago

Describe the bug

AutoComplete with the multiple param does not currently have two very convenient features of the Chips component. The chips component worked much better for allowing users to add their own inputs because of the addOnBlur and separator params.

Would be awesome to have that functionality added to the AutoComplete component, since I don't think people can consistently rely on users pressing enter after typing freeform text. I think that works if there are pre-determined options with the dropdown, but does not work when it's just trying to get users to enter array items.

Reproducer

https://stackblitz.com/edit/primevue-4-vite-issue-template-888z42?file=README.md,src%2FApp.vue

PrimeVue version

4.1.0

Vue version

4.x

Language

TypeScript

Build / Runtime

Vue CLI App

Browser(s)

No response

Steps to reproduce the behavior

  1. Within the AutoComplete component, there's no ability to use addOnBlur or separator params that existed with the Chips component. There's no convenient way for a user to write "tag1" and click off the component for "tag1" to become an item if there isn't a predetermined list that includes "tag1" as an option. Same with using a comma to separate tag values, pressing enter is a work around, but removes the ability for a user to paste in a comma separated list.

Expected behavior

Ideally, if a user has anything typed in the component and clicks off the component, that text would become a chip when addOnBlur is a param. And when separator is a param, having separator="," would allow the user to paste a comma separated list with each item properly getting added as a chip. These features existed in the now deprecated Chips component, and without these features I don't think AutoComplete replaces the functionality offered by the Chips component

CCodam commented 2 days ago

You're not alone https://github.com/primefaces/primevue/issues/5909

The AutoComplete component uses the InputChips component behind the scenes. While this component is not documented, it's virtually identical of the v3 Chips component, and you should be able to use the v3 Chips documentation to accomplish your goals with it. You will however get a Deprecated since v4 notice in your console.

I guess they don't want InputChips as a separate documented component in v4, as they feel the AutoComplete should encompass the same functionality.

To that end, functionality needs to be added back into the AutoComplete component. I haven't looked too deep into the code, maybe there's a smart way to utilize the logic already present in the underlying InputChips component, otherwise modification of the existing AutoComplete logic is needed

I've modified the onChange and onInput methods of the AutoComplete component, and added an onPaste method and separator value. I've decided to always add chip onChange (essentially onBlur), if all other conditions are met, typeahead (false), forceSelection (false), multiple (true). However addOnBlur could of course be added. The InputChips component works out of the box, without modifications. https://stackblitz.com/edit/primevue-4-vite-issue-template-muvzf2?file=src%2FApp.vue

This is just a rough implementation, that hopefully can inspire a pull request, that'll add the functionality "back" into the AutoComplete component.