mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-09-04 08:47:23 +08:00
Merge pull request #3014 from woocommerce/PCP-4013-checkboxes-should-toggle-when-clicking-anywhere-inside-the-box
Toggle the checkboxes when clicking anywhere inside the box
This commit is contained in:
commit
a6911bb5ee
1 changed files with 25 additions and 6 deletions
|
@ -12,8 +12,31 @@ const SelectBox = ( props ) => {
|
|||
boxClassName += ' selected';
|
||||
}
|
||||
|
||||
const handleClick = () => {
|
||||
if ( props.type === 'checkbox' ) {
|
||||
let newValue;
|
||||
|
||||
if ( Array.isArray( props.currentValue ) ) {
|
||||
if ( props.currentValue.includes( props.value ) ) {
|
||||
newValue = props.currentValue.filter(
|
||||
( optionValue ) => optionValue !== props.value
|
||||
);
|
||||
} else {
|
||||
newValue = [ ...props.currentValue, props.value ];
|
||||
}
|
||||
} else {
|
||||
newValue = ! props.currentValue;
|
||||
}
|
||||
|
||||
props.changeCallback( newValue );
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<div className={ boxClassName }>
|
||||
<div
|
||||
className={ boxClassName }
|
||||
onClick={ props.type === 'checkbox' ? handleClick : undefined }
|
||||
>
|
||||
{ props.type === 'radio' && (
|
||||
<PayPalRdb
|
||||
{ ...{
|
||||
|
@ -22,11 +45,7 @@ const SelectBox = ( props ) => {
|
|||
} }
|
||||
/>
|
||||
) }
|
||||
{ props.type === 'checkbox' && (
|
||||
<PayPalCheckbox
|
||||
{ ...props }
|
||||
/>
|
||||
) }
|
||||
{ props.type === 'checkbox' && <PayPalCheckbox { ...props } /> }
|
||||
<div className="ppcp-r-select-box__content">
|
||||
<div className="ppcp-r-select-box__content-inner">
|
||||
<span className="ppcp-r-select-box__title">
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue