diff --git a/plugins/woocommerce-admin/packages/components/src/filters/advanced/number-filter.js b/plugins/woocommerce-admin/packages/components/src/filters/advanced/number-filter.js index d96c2343548..05bbb412294 100644 --- a/plugins/woocommerce-admin/packages/components/src/filters/advanced/number-filter.js +++ b/plugins/woocommerce-admin/packages/components/src/filters/advanced/number-filter.js @@ -3,7 +3,7 @@ * External dependencies */ import { Component, Fragment } from '@wordpress/element'; -import { withSpokenMessages, SelectControl, TextControl } from '@wordpress/components'; +import { SelectControl, TextControl } from '@wordpress/components'; import { get, find, partial } from 'lodash'; import interpolateComponents from 'interpolate-components'; import classnames from 'classnames'; @@ -14,24 +14,9 @@ import { sprintf, __, _x } from '@wordpress/i18n'; */ import TextControlWithAffixes from '../../text-control-with-affixes'; import { formatCurrency } from '@woocommerce/currency'; -import { ariaHideStrings, textContent } from './utils'; +import { textContent } from './utils'; class NumberFilter extends Component { - componentDidUpdate() { - const { config, debouncedSpeak, filter } = this.props; - const [ rangeStart, rangeEnd ] = ( filter.value || '' ).split( ',' ); - - if ( 'between' === filter.rule && ( ! rangeStart || ! rangeEnd ) ) { - return; - } - - if ( ! rangeStart ) { - return; - } - - debouncedSpeak( this.getScreenReaderText( filter, config ) ); - } - getBetweenString() { return _x( '{{rangeStart /}}{{span}} and {{/span}}{{rangeEnd /}}', @@ -45,7 +30,7 @@ class NumberFilter extends Component { const rule = find( config.rules, { value: filter.rule } ) || {}; let [ rangeStart, rangeEnd ] = ( filter.value || '' ).split( ',' ); - // Return the filter label if we're missing input(s) + // Return nothing if we're missing input(s) if ( ! rangeStart || ( 'between' === rule.value && ! rangeEnd ) @@ -192,7 +177,7 @@ class NumberFilter extends Component { ), onChange: rangeEndOnChange, } ), - span: , + span: , }, } ); } @@ -202,7 +187,7 @@ class NumberFilter extends Component { const { key, rule } = filter; const { labels, rules } = config; - const children = ariaHideStrings( interpolateComponents( { + const children = interpolateComponents( { mixedString: labels.title, components: { rule: ( @@ -224,7 +209,10 @@ class NumberFilter extends Component { ), }, - } ) ); + } ); + + const screenReaderText = this.getScreenReaderText( filter, config ); + /*eslint-disable jsx-a11y/no-noninteractive-tabindex*/ return (
@@ -238,10 +226,15 @@ class NumberFilter extends Component { > { children } + { screenReaderText && ( + + { screenReaderText } + + ) }
); /*eslint-enable jsx-a11y/no-noninteractive-tabindex*/ } } -export default withSpokenMessages( NumberFilter ); +export default NumberFilter; diff --git a/plugins/woocommerce-admin/packages/components/src/filters/advanced/utils.js b/plugins/woocommerce-admin/packages/components/src/filters/advanced/utils.js index 15d78de764c..3bb5b7a149f 100644 --- a/plugins/woocommerce-admin/packages/components/src/filters/advanced/utils.js +++ b/plugins/woocommerce-admin/packages/components/src/filters/advanced/utils.js @@ -3,26 +3,6 @@ */ import { isArray, isNumber, isString } from 'lodash'; -/** - * Hide all bare strings from the accessibility tree. - * Intended to process the result of interpolateComponents(). - * - * @param {Array} components array of components - * - * @returns {Array} array of processed components - */ -export function ariaHideStrings( components ) { - if ( ! isArray( components ) ) { - return components; - } - - return components.map( component => ( - isString( component ) && component.trim() - ? { component } - : component - ) ); -} - /** * DOM Node.textContent for React components * See: https://github.com/rwu823/react-addons-text-content/blob/master/src/index.js @@ -32,25 +12,25 @@ export function ariaHideStrings( components ) { * @returns {string} concatenated text content of all nodes */ export function textContent( components ) { - let text = ''; + let text = ''; - const toText = ( component ) => { - if ( isString( component ) || isNumber( component ) ) { - text += component; - } else if ( isArray( component ) ) { - component.forEach( toText ); - } else if ( component && component.props ) { - const { children } = component.props; + const toText = ( component ) => { + if ( isString( component ) || isNumber( component ) ) { + text += component; + } else if ( isArray( component ) ) { + component.forEach( toText ); + } else if ( component && component.props ) { + const { children } = component.props; - if ( isArray( children ) ) { - children.forEach( toText ); - } else { - toText( children ); - } - } - }; + if ( isArray( children ) ) { + children.forEach( toText ); + } else { + toText( children ); + } + } + }; - toText( components ); + toText( components ); - return text; + return text; }