ng-bootstrap icon indicating copy to clipboard operation
ng-bootstrap copied to clipboard

[ngbTypeahead] selectOnExact results length condition

Open billyLumberjack opened this issue 1 year ago • 4 comments

Hello, I recently faced an issue using this useful attribute "selectOnExact": the problem is that even if one of the result is exaclty the value typed from the user and there are some others which in my case have just a suffix, the first and exact match is not taken because this condition regarding the number of results is not match.

Here's the code line in typeahead.ts : https://github.com/ng-bootstrap/ng-bootstrap/blob/2fcf9e94c738664c885cf292b0753fde666f1f82/src/typeahead/typeahead.ts#L417

Thanks in advance for any discussion and/or further implementation regarding the topic :) Cheers

Originally posted by @billyLumberjack in https://github.com/ng-bootstrap/ng-bootstrap/discussions/4610

billyLumberjack avatar Nov 13 '23 10:11 billyLumberjack

We could fix this by allowing you to choose the strategy, like the Router does with pathMatch?: 'prefix' | 'full' → https://angular.dev/api/router/Route

Something like:

  1. @Input() selectOnExact: boolean | 'prefix'; → I don't think naming is great though
  2. new @Input() selectOnMatch: 'prefix' | 'full'; → might need a breaking change deprecation of selectOnExact later to avoid having both

Any suggestions from your side, maybe?

maxokorokov avatar Nov 13 '23 10:11 maxokorokov

We could fix this by allowing you to choose the strategy, like the Router does with pathMatch?: 'prefix' | 'full' → https://angular.dev/api/router/Route

Something like:

  1. @Input() selectOnExact: boolean | 'prefix'; → I don't think naming is great though
  2. new @Input() selectOnMatch: 'prefix' | 'full'; → might need a breaking change deprecation of selectOnExact later to avoid having both

Any suggestions from your side, maybe?

Hi @maxokorokov, thanks for your feedback. I like the first solution you propose, probably using 'first_match' instead of 'prefix'... we'll end up having :

@Input() selectOnExact: boolean | 'first_match';

which is retrocompatible and idiomatic as well.

billyLumberjack avatar Nov 13 '23 10:11 billyLumberjack

Sure, works for me (apart from first-match, not first_match) :) Shouldn't be hard to do either and non-breaking change.

You could open a PR if you're up for it (can inspire from the original https://github.com/ng-bootstrap/ng-bootstrap/pull/4421 for the selectOnExact)

maxokorokov avatar Nov 13 '23 12:11 maxokorokov

Sounds good ! let's have first-match... i'll open the PR asap

billyLumberjack avatar Nov 13 '23 12:11 billyLumberjack