@@ -6,7 +6,6 @@ import { speak } from '@wordpress/a11y';
66import classNames from 'classnames' ;
77import { useCallback , useLayoutEffect , useRef } from '@wordpress/element' ;
88import { DOWN , UP } from '@wordpress/keycodes' ;
9- import { usePrevious } from '@woocommerce/base-hooks' ;
109import { useDebouncedCallback } from 'use-debounce' ;
1110
1211/**
@@ -75,45 +74,6 @@ const QuantitySelector = ( {
7574 const canDecrease = ! disabled && quantity - step >= minimum ;
7675 const canIncrease =
7776 ! disabled && ( ! hasMaximum || quantity + step <= maximum ) ;
78- const previousCanDecrease = usePrevious ( canDecrease ) ;
79- const previousCanIncrease = usePrevious ( canIncrease ) ;
80-
81- // When the increase or decrease buttons get disabled, the focus
82- // gets moved to the `<body>` element. This was causing weird
83- // issues in the Mini-Cart block, as the drawer expects focus to be
84- // inside.
85- // To fix this, we move the focus to the text input after the
86- // increase or decrease buttons get disabled. We only do that if
87- // the focus is on the button or the body element.
88- // See https://github.com/woocommerce/woocommerce-blocks/pull/9345
89- useLayoutEffect ( ( ) => {
90- // Refs are not available yet, so abort.
91- if (
92- ! inputRef . current ||
93- ! decreaseButtonRef . current ||
94- ! increaseButtonRef . current
95- ) {
96- return ;
97- }
98-
99- const currentDocument = inputRef . current . ownerDocument ;
100- if (
101- previousCanDecrease &&
102- ! canDecrease &&
103- ( currentDocument . activeElement === decreaseButtonRef . current ||
104- currentDocument . activeElement === currentDocument . body )
105- ) {
106- inputRef . current . focus ( ) ;
107- }
108- if (
109- previousCanIncrease &&
110- ! canIncrease &&
111- ( currentDocument . activeElement === increaseButtonRef . current ||
112- currentDocument . activeElement === currentDocument . body )
113- ) {
114- inputRef . current . focus ( ) ;
115- }
116- } , [ previousCanDecrease , previousCanIncrease , canDecrease , canIncrease ] ) ;
11777
11878 /**
11979 * The goal of this function is to normalize what was inserted,
0 commit comments