diff --git a/plugins/woocommerce-blocks/assets/js/base/components/price-slider/index.tsx b/plugins/woocommerce-blocks/assets/js/base/components/price-slider/index.tsx index 372d46927a0..d9f2faa0704 100644 --- a/plugins/woocommerce-blocks/assets/js/base/components/price-slider/index.tsx +++ b/plugins/woocommerce-blocks/assets/js/base/components/price-slider/index.tsx @@ -8,6 +8,7 @@ import { useCallback, useMemo, useRef, + useLayoutEffect, } from '@wordpress/element'; import classnames from 'classnames'; import FormattedMonetaryAmount from '@woocommerce/base-components/formatted-monetary-amount'; @@ -97,6 +98,9 @@ const PriceSlider = ( { const [ minPriceInput, setMinPriceInput ] = useState( minPrice ); const [ maxPriceInput, setMaxPriceInput ] = useState( maxPrice ); + const wrapper = useRef< HTMLInputElement >( null ); + const [ wrapperWidth, setWrapperWidth ] = useState( 0 ); + useEffect( () => { setMinPriceInput( minPrice ); }, [ minPrice ] ); @@ -105,6 +109,12 @@ const PriceSlider = ( { setMaxPriceInput( maxPrice ); }, [ maxPrice ] ); + useLayoutEffect( () => { + if ( inlineInput && wrapper.current ) { + setWrapperWidth( wrapper.current?.offsetWidth ); + } + }, [ inlineInput, setWrapperWidth ] ); + /** * Checks if the min and max constraints are valid. */ @@ -292,7 +302,9 @@ const PriceSlider = ( { showFilterButton && 'wc-block-components-price-slider--has-filter-button', isLoading && 'is-loading', - ! hasValidConstraints && 'is-disabled' + ! hasValidConstraints && 'is-disabled', + ( inlineInput || wrapperWidth <= 300 ) && + 'wc-block-components-price-slider--is-input-inline' ); const activeElement = isObject( minRange.current ) @@ -310,6 +322,8 @@ const PriceSlider = ( { maxPriceInput / 10 ** currency.minorUnit ); + const inlineInputAvailable = inlineInput && wrapperWidth > 300; + const slider = (
- { ( ! inlineInput || ! showInputFields ) && slider } +
+ { ( ! inlineInputAvailable || ! showInputFields ) && slider } { showInputFields && (
- { inlineInput && slider } + { inlineInputAvailable && slider } { await page.keyboard.down( 'Shift' ); await page.keyboard.press( 'Home' ); await page.keyboard.up( 'Shift' ); - await page.keyboard.type( '1.99' ); + await page.keyboard.type( '2' ); await page.keyboard.press( 'Tab' ); };