Skip to content

Commit

Permalink
fix(pin-input): focus issue (#6689)
Browse files Browse the repository at this point in the history
  • Loading branch information
anubra266 committed Sep 16, 2022
1 parent 59391bb commit f6002e4
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
5 changes: 5 additions & 0 deletions .changeset/afraid-gorillas-give.md
@@ -0,0 +1,5 @@
---
"@chakra-ui/pin-input": patch
---

Fix issue where backspace did not focus prev input
6 changes: 3 additions & 3 deletions packages/components/pin-input/src/use-pin-input.ts
Expand Up @@ -178,7 +178,7 @@ export function usePinInput(props: UsePinInputProps = {}) {
)

const setValue = useCallback(
(value: string, index: number) => {
(value: string, index: number, handleFocus: boolean = true) => {
const nextValues = [...values]
nextValues[index] = value
setValues(nextValues)
Expand All @@ -193,7 +193,7 @@ export function usePinInput(props: UsePinInputProps = {}) {
if (isComplete) {
onComplete?.(nextValues.join(""))
} else {
focusNext(index)
if (handleFocus) focusNext(index)
}
},
[values, setValues, focusNext, onComplete, descendants],
Expand Down Expand Up @@ -267,7 +267,7 @@ export function usePinInput(props: UsePinInputProps = {}) {
if ((event.target as HTMLInputElement).value === "") {
const prevInput = descendants.prev(index, false)
if (prevInput) {
setValue("", index - 1)
setValue("", index - 1, false)
prevInput.node?.focus()
setMoveFocus(true)
}
Expand Down

1 comment on commit f6002e4

@vercel
Copy link

@vercel vercel bot commented on f6002e4 Sep 16, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.