Skip to content

Commit 0db45e9

Browse files
Use state for DeleteButton confirming flag
Replace mutable ref with React state so disabled and aria-busy update correctly during async confirmation. Prevents stale UI and improves accessibility while keeping existing behavior intact.
1 parent 8b4b361 commit 0db45e9

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

src/components/DeleteButton/index.jsx

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ function DeleteButton({ onConfirm, size, text }) {
1313
const { t } = useTranslation()
1414
const [waitConfirm, setWaitConfirm] = useState(false)
1515
const confirmRef = useRef(null)
16-
const confirmingRef = useRef(false)
16+
const [confirming, setConfirming] = useState(false)
1717

1818
useEffect(() => {
1919
if (waitConfirm) confirmRef.current.focus()
@@ -29,20 +29,20 @@ function DeleteButton({ onConfirm, size, text }) {
2929
fontSize: '10px',
3030
...(waitConfirm ? {} : { display: 'none' }),
3131
}}
32-
disabled={confirmingRef.current}
33-
aria-busy={confirmingRef.current ? 'true' : 'false'}
32+
disabled={confirming}
33+
aria-busy={confirming ? 'true' : 'false'}
3434
onMouseDown={(e) => {
3535
e.preventDefault()
3636
e.stopPropagation()
3737
}}
3838
onBlur={() => {
39-
if (!confirmingRef.current) setWaitConfirm(false)
39+
if (!confirming) setWaitConfirm(false)
4040
}}
4141
onClick={async (e) => {
42-
if (confirmingRef.current) return
42+
if (confirming) return
4343
e.preventDefault()
4444
e.stopPropagation()
45-
confirmingRef.current = true
45+
setConfirming(true)
4646
try {
4747
await onConfirm()
4848
setWaitConfirm(false)
@@ -51,7 +51,7 @@ function DeleteButton({ onConfirm, size, text }) {
5151
// eslint-disable-next-line no-console
5252
console.error(err)
5353
} finally {
54-
confirmingRef.current = false
54+
setConfirming(false)
5555
}
5656
}}
5757
>

0 commit comments

Comments
 (0)