Skip to content

Commit

Permalink
Set internal SLA only when not calling onChange to reduce visual glit…
Browse files Browse the repository at this point in the history
…ches
  • Loading branch information
ciampo committed Jan 10, 2024
1 parent 3c6a860 commit cb3303d
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions packages/components/src/color-picker/hsl-input.tsx
Expand Up @@ -41,21 +41,21 @@ export const HslInput = ( { color, onChange, enableAlpha }: HslInputProps ) => {
const updateHSLAValue = (
partialNewValue: Partial< typeof colorPropHSLA >
) => {
// Update internal HSLA color.
setInternalHSLA( ( prevValue ) => ( {
...prevValue,
...partialNewValue,
} ) );

const nextOnChangeValue = colord( {
...colorValue,
...partialNewValue,
} );

// Fire `onChange` only if the resulting color is different from the
// current one.
// Otherwise, update the internal HSLA color to cause a re-render.
if ( ! color.isEqual( nextOnChangeValue ) ) {
onChange( nextOnChangeValue );
} else {
setInternalHSLA( ( prevHSLA ) => ( {
...prevHSLA,
...partialNewValue,
} ) );
}
};

Expand Down

0 comments on commit cb3303d

Please sign in to comment.