Skip to content
This repository has been archived by the owner on Feb 23, 2024. It is now read-only.

Commit

Permalink
Remove unnecessary fix in QuantitySelector
Browse files Browse the repository at this point in the history
  • Loading branch information
Aljullu committed Jun 28, 2023
1 parent 3c12f69 commit 689acc6
Showing 1 changed file with 0 additions and 40 deletions.
40 changes: 0 additions & 40 deletions assets/js/base/components/quantity-selector/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import { speak } from '@wordpress/a11y';
import classNames from 'classnames';
import { useCallback, useLayoutEffect, useRef } from '@wordpress/element';
import { DOWN, UP } from '@wordpress/keycodes';
import { usePrevious } from '@woocommerce/base-hooks';
import { useDebouncedCallback } from 'use-debounce';

/**
Expand Down Expand Up @@ -75,45 +74,6 @@ const QuantitySelector = ( {
const canDecrease = ! disabled && quantity - step >= minimum;
const canIncrease =
! disabled && ( ! hasMaximum || quantity + step <= maximum );
const previousCanDecrease = usePrevious( canDecrease );
const previousCanIncrease = usePrevious( canIncrease );

// When the increase or decrease buttons get disabled, the focus
// gets moved to the `<body>` element. This was causing weird
// issues in the Mini-Cart block, as the drawer expects focus to be
// inside.
// To fix this, we move the focus to the text input after the
// increase or decrease buttons get disabled. We only do that if
// the focus is on the button or the body element.
// See https://github.com/woocommerce/woocommerce-blocks/pull/9345
useLayoutEffect( () => {
// Refs are not available yet, so abort.
if (
! inputRef.current ||
! decreaseButtonRef.current ||
! increaseButtonRef.current
) {
return;
}

const currentDocument = inputRef.current.ownerDocument;
if (
previousCanDecrease &&
! canDecrease &&
( currentDocument.activeElement === decreaseButtonRef.current ||
currentDocument.activeElement === currentDocument.body )
) {
inputRef.current.focus();
}
if (
previousCanIncrease &&
! canIncrease &&
( currentDocument.activeElement === increaseButtonRef.current ||
currentDocument.activeElement === currentDocument.body )
) {
inputRef.current.focus();
}
}, [ previousCanDecrease, previousCanIncrease, canDecrease, canIncrease ] );

/**
* The goal of this function is to normalize what was inserted,
Expand Down

0 comments on commit 689acc6

Please sign in to comment.