ng-bootstrap
ng-bootstrap copied to clipboard
[ngbTypeahead] selectOnExact results length condition
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
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:
@Input() selectOnExact: boolean | 'prefix';→ I don't think naming is great though- new
@Input() selectOnMatch: 'prefix' | 'full';→ might need a breaking change deprecation ofselectOnExactlater to avoid having both
Any suggestions from your side, maybe?
We could fix this by allowing you to choose the strategy, like the
Routerdoes withpathMatch?: 'prefix' | 'full'→ https://angular.dev/api/router/RouteSomething like:
@Input() selectOnExact: boolean | 'prefix';→ I don't think naming is great though- new
@Input() selectOnMatch: 'prefix' | 'full';→ might need a breaking change deprecation ofselectOnExactlater to avoid having bothAny 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.
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)
Sounds good ! let's have first-match... i'll open the PR asap