55 lines
1.2 KiB
JavaScript
55 lines
1.2 KiB
JavaScript
/**
|
||
* 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 (
|
||
<div className="wc-block-dropdown-selector__selected-value">
|
||
<button
|
||
ref={ labelRef }
|
||
className="wc-block-dropdown-selector__selected-value__label"
|
||
onClick={ ( e ) => {
|
||
e.stopPropagation();
|
||
onClick( option.value );
|
||
} }
|
||
aria-label={ sprintf(
|
||
__(
|
||
'Replace current %s filter',
|
||
'woo-gutenberg-products-block'
|
||
),
|
||
option.name
|
||
) }
|
||
>
|
||
{ option.label }
|
||
</button>
|
||
<button
|
||
className="wc-block-dropdown-selector__selected-value__remove"
|
||
onClick={ () => {
|
||
onRemoveItem( option.value );
|
||
} }
|
||
onKeyDown={ ( e ) => {
|
||
if ( e.key === 'Backspace' || e.key === 'Delete' ) {
|
||
onRemoveItem( option.value );
|
||
}
|
||
} }
|
||
aria-label={ sprintf(
|
||
__( 'Remove %s filter', 'woo-gutenberg-products-block' ),
|
||
option.name
|
||
) }
|
||
>
|
||
𝘅
|
||
</button>
|
||
</div>
|
||
);
|
||
};
|
||
|
||
export default DropdownSelectorSelectedValue;
|