Skip to content

Commit

Permalink
fix(chip): move focus to next chip when chip removed
Browse files Browse the repository at this point in the history
  • Loading branch information
alaa-yahia committed Apr 17, 2024
1 parent 8c0c379 commit 51770e1
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions components/chip/src/chip-group/chip-group.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand All @@ -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 (
<div
Expand Down

0 comments on commit 51770e1

Please sign in to comment.