Skip to content

Commit

Permalink
NavigationMenu: set attributes rightly (#18150)
Browse files Browse the repository at this point in the history
* navigation-menu: set attributes once

* navigation-menu: add CSS class as hook dependencies

* Update packages/block-library/src/navigation-menu/edit.js

Co-Authored-By: Enrique Piqueras <epiqueras@users.noreply.github.com>
  • Loading branch information
2 people authored and hypest committed Nov 4, 2019
1 parent 57197b6 commit f558ed7
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions packages/block-library/src/navigation-menu/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import classnames from 'classnames';
import {
Fragment,
useMemo,
useEffect,
} from '@wordpress/element';
import {
InnerBlocks,
Expand Down Expand Up @@ -79,7 +80,7 @@ function NavigationMenu( {
* Set the color type according to the given values.
* It propagate the color values into the attributes object.
* Both `backgroundColorValue` and `textColorValue` are
* using the apply inline styles.
* using the inline styles.
*
* @param {Object} colorsData Arguments passed by BlockColorsStyleSelector onColorChange.
* @param {string} colorsData.attr Color attribute.
Expand All @@ -99,11 +100,13 @@ function NavigationMenu( {
}
};

// Set/Unset colors CSS classes.
setAttributes( {
backgroundColorCSSClass: backgroundColor.class ? backgroundColor.class : null,
textColorCSSClass: textColor.class ? textColor.class : null,
} );
useEffect( () => {
// Set/Unset colors CSS classes.
setAttributes( {
backgroundColorCSSClass: backgroundColor.class ? backgroundColor.class : null,
textColorCSSClass: textColor.class ? textColor.class : null,
} );
}, [ backgroundColor.class, textColor.class ] );

return (
<Fragment>
Expand Down

0 comments on commit f558ed7

Please sign in to comment.