diff --git a/components/chip/src/chip-group/chip-group.js b/components/chip/src/chip-group/chip-group.js index 859d49fe7a..b2064314b7 100644 --- a/components/chip/src/chip-group/chip-group.js +++ b/components/chip/src/chip-group/chip-group.js @@ -12,8 +12,9 @@ const ChipGroup = ({ className, dataTest, children }) => { const chips = Array.from( chipContainer.current.querySelectorAll('[role="option"]') ) - - chips[0].focus() + if (chips.length > 0) { + chips[0].focus() + } return } @@ -39,6 +40,10 @@ const ChipGroup = ({ className, dataTest, children }) => { const prevIndex = (currentIndex - 1 + chips.length) % chips.length chips[prevIndex].focus() } + if (event.key === 'Backspace' || event.key === 'Delete') { + const nextIndex = (currentIndex + 1) % chips.length + chips[nextIndex].focus() + } } return (