From 137770b7e61c6665f1270dcf5c29f879a83d70ac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Albert=20Juh=C3=A9=20Lluveras?= Date: Mon, 15 May 2023 12:53:01 +0200 Subject: [PATCH] Move focus to the input field also when the body has focus, that fixes the issue in Chrome --- assets/js/base/components/quantity-selector/index.tsx | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/assets/js/base/components/quantity-selector/index.tsx b/assets/js/base/components/quantity-selector/index.tsx index fadc318cba4..af77ab4d339 100644 --- a/assets/js/base/components/quantity-selector/index.tsx +++ b/assets/js/base/components/quantity-selector/index.tsx @@ -84,17 +84,19 @@ const QuantitySelector = ( { ) { return; } + + const currentDocument = inputRef.current.ownerDocument; if ( ! canDecrease && - decreaseButtonRef.current === - decreaseButtonRef.current.ownerDocument.activeElement + ( currentDocument.activeElement === decreaseButtonRef.current || + currentDocument.activeElement === currentDocument.body ) ) { inputRef.current.focus(); } if ( ! canIncrease && - increaseButtonRef.current === - decreaseButtonRef.current.ownerDocument.activeElement + ( currentDocument.activeElement === increaseButtonRef.current || + currentDocument.activeElement === currentDocument.body ) ) { inputRef.current.focus(); }