feat: Add chipCount prop to limit the amount of chips shown - #4805
Conversation
302563f to
d999768
Compare
|
@claude review |
|
Claude finished @pomfrida's task in 1m 39s —— View job Code Review
The feature is well-scoped and the core slicing logic ( Bug: Focus management breaks with keyboard navigation
Before this PR, Suggested fix: after removing a visible chip, fall back to const handleChipRemove = (item: unknown, index: number, isKeyboardEvent: boolean) => {
if (isKeyboardEvent && selectedItems.length > 1) {
const isLastChip = index === selectedItems.length - 1
const nextItem = selectedItems[isLastChip ? index - 1 : index + 1]
const nextRef = chipRefs.current.get(getLabel(nextItem))
// Fall back to input when next chip is hidden (beyond chipCount)
if (nextRef) nextRef.focus()
else inputRef.current?.focus()
} else if (!isKeyboardEvent) {
inputRef.current?.focus()
}
removeSelectedItem(item)
}Wrong
|
|
Nice work @yusijs please check Claude review - I'll review it tomorrow myself as well |
d999768 to
f5edfa4
Compare
|
Fixed the comments from Claude @pomfrida. I didn't split the style on the chips into a variable, because I don't think they would necessarily need to be kept in sync (and it's only 2 lines). |
f5edfa4 to
bcafe66
Compare
pomfrida
left a comment
There was a problem hiding this comment.
Looks good! The core logic is solid and the focus fallback handles the edge cases. A couple of minor notes:
-
isLastChipchecks against the fullselectedItemsarray, so whenchipCountis set it'll never betruefor the last visible chip — meaning keyboard-deleting the last visible chip always falls back to focusing the input instead of the previous chip. Not a bug (focus doesn't get lost), but slightly different UX compared to the no-chipCount case. Something to be aware of if you want to polish it later. -
The test is inside the "Scroll position and navigation memory" describe block — would read better in a chip-related block, but no big deal.
As discussed on slack
This PR adds a new prop to the Autocomplete-component (chipCount), which allows limiting the amount of chips dynamically, while retaining the existing behaviour if left unspecified.