2019-12-05 13:58:44 +00:00
|
|
|
|
/**
|
|
|
|
|
* External dependencies
|
|
|
|
|
*/
|
|
|
|
|
import { __, sprintf } from '@wordpress/i18n';
|
|
|
|
|
import { useEffect, useRef } from '@wordpress/element';
|
|
|
|
|
|
|
|
|
|
const DropdownSelectorSelectedValue = ( { onClick, onRemoveItem, option } ) => {
|
|
|
|
|
const labelRef = useRef( null );
|
|
|
|
|
|
|
|
|
|
useEffect( () => {
|
|
|
|
|
labelRef.current.focus();
|
|
|
|
|
}, [ labelRef ] );
|
|
|
|
|
|
|
|
|
|
return (
|
2020-06-17 09:53:42 +00:00
|
|
|
|
<div className="wc-block-dropdown-selector__selected-value wc-block-components-dropdown-selector__selected-value">
|
2019-12-05 13:58:44 +00:00
|
|
|
|
<button
|
|
|
|
|
ref={ labelRef }
|
2020-06-17 09:53:42 +00:00
|
|
|
|
className="wc-block-dropdown-selector__selected-value__label wc-block-components-dropdown-selector__selected-value__label"
|
2019-12-05 13:58:44 +00:00
|
|
|
|
onClick={ ( e ) => {
|
|
|
|
|
e.stopPropagation();
|
|
|
|
|
onClick( option.value );
|
|
|
|
|
} }
|
|
|
|
|
aria-label={ sprintf(
|
2020-01-30 10:04:39 +00:00
|
|
|
|
/* translators: %s attribute value used in the filter. For example: yellow, green, small, large. */
|
2019-12-05 13:58:44 +00:00
|
|
|
|
__(
|
|
|
|
|
'Replace current %s filter',
|
|
|
|
|
'woo-gutenberg-products-block'
|
|
|
|
|
),
|
|
|
|
|
option.name
|
|
|
|
|
) }
|
|
|
|
|
>
|
|
|
|
|
{ option.label }
|
|
|
|
|
</button>
|
|
|
|
|
<button
|
2020-06-17 09:53:42 +00:00
|
|
|
|
className="wc-block-dropdown-selector__selected-value__remove wc-block-components-dropdown-selector__selected-value__remove"
|
2019-12-05 13:58:44 +00:00
|
|
|
|
onClick={ () => {
|
|
|
|
|
onRemoveItem( option.value );
|
|
|
|
|
} }
|
|
|
|
|
onKeyDown={ ( e ) => {
|
|
|
|
|
if ( e.key === 'Backspace' || e.key === 'Delete' ) {
|
|
|
|
|
onRemoveItem( option.value );
|
|
|
|
|
}
|
|
|
|
|
} }
|
|
|
|
|
aria-label={ sprintf(
|
2020-01-30 10:04:39 +00:00
|
|
|
|
/* translators: %s attribute value used in the filter. For example: yellow, green, small, large. */
|
2019-12-05 13:58:44 +00:00
|
|
|
|
__( 'Remove %s filter', 'woo-gutenberg-products-block' ),
|
|
|
|
|
option.name
|
|
|
|
|
) }
|
|
|
|
|
>
|
|
|
|
|
𝘅
|
|
|
|
|
</button>
|
|
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export default DropdownSelectorSelectedValue;
|