Skip to content

Commit

Permalink
Disable units when mixed units are used
Browse files Browse the repository at this point in the history
  • Loading branch information
youknowriad committed Dec 9, 2024
1 parent 27c4540 commit f15066c
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion packages/components/src/box-control/input-control.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -131,16 +131,22 @@ export default function BoxInputControl( {
hasValues &&
defaultValuesToModify.length > 1 &&
isValueMixed( values, defaultValuesToModify );
const mixedPlaceholder = isMixed ? __( 'Mixed' ) : undefined;
const [ parsedQuantity, parsedUnit ] =
parseQuantityAndUnitFromRawValue( mergedValue );
const computedUnit = hasValues
? parsedUnit
: selectedUnits[ defaultValuesToModify[ 0 ] ];
const generatedId = useInstanceId( BoxInputControl, 'box-control-input' );
const inputId = [ generatedId, side ].join( '-' );
const isMixedUnit =
defaultValuesToModify.length > 1 &&
mergedValue === undefined &&
defaultValuesToModify.some(
( s ) => selectedUnits[ s ] !== computedUnit
);
const usedValue =
mergedValue === undefined && computedUnit ? computedUnit : mergedValue;
const mixedPlaceholder = isMixed || isMixedUnit ? __( 'Mixed' ) : undefined;

return (
<InputWrapper key={ `box-control-${ side }` } expanded>
Expand All @@ -153,6 +159,7 @@ export default function BoxInputControl( {
className="component-box-control__unit-control"
id={ inputId }
isPressEnterToChange
disableUnits={ isMixed || isMixedUnit }
value={ usedValue }
onChange={ handleOnValueChange }
onUnitChange={ handleOnUnitChange }
Expand Down

0 comments on commit f15066c

Please sign in to comment.