Skip to content

Commit

Permalink
fix: applyOrUnset() consistency.
Browse files Browse the repository at this point in the history
See: #3859
  • Loading branch information
Jason Caldwell authored and youknowriad committed Jan 16, 2018
1 parent 8f0aab9 commit 8e87182
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
6 changes: 5 additions & 1 deletion blocks/alignment-toolbar/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ const ALIGNMENT_CONTROLS = [
];

export default function AlignmentToolbar( { value, onChange } ) {
function applyOrUnset( align ) {
return () => onChange( value === align ? undefined : align );
}

return (
<Toolbar
controls={ ALIGNMENT_CONTROLS.map( ( control ) => {
Expand All @@ -32,7 +36,7 @@ export default function AlignmentToolbar( { value, onChange } ) {
return {
...control,
isActive,
onClick: () => onChange( isActive ? undefined : align ),
onClick: applyOrUnset( align ),
};
} ) }
/>
Expand Down
6 changes: 5 additions & 1 deletion blocks/color-palette/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ import './style.scss';
export function ColorPalette( { defaultColors, colors, value, onChange } ) {
const usedColors = colors || defaultColors;

function applyOrUnset( color ) {
return () => onChange( value === color ? undefined : color );
}

return (
<div className="blocks-color-palette">
{ usedColors.map( ( color ) => {
Expand All @@ -30,7 +34,7 @@ export function ColorPalette( { defaultColors, colors, value, onChange } ) {
type="button"
className={ className }
style={ style }
onClick={ () => onChange( value === color ? undefined : color ) }
onClick={ applyOrUnset( color ) }
aria-label={ sprintf( __( 'Color: %s' ), color ) }
aria-pressed={ value === color }
/>
Expand Down

0 comments on commit 8e87182

Please sign in to comment.