Skip to content

Commit 5dc9138

Browse files
authored
fix: colors of page icons not being shown/applied (#3665)
* fix icon colors not being shown/applied * add cleanup for icon color type
1 parent f4015a7 commit 5dc9138

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

src/block-components/icon/index.js

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,8 @@ export const Icon = props => {
184184

185185
const ShapeComp = useMemo( () => getShapeSVG( getAttribute( 'backgroundShape' ) || 'blob1' ), [ getAttribute( 'backgroundShape' ) ] )
186186

187+
const iconColorType = getAttribute( 'iconColorType' )
188+
187189
const _icon = value || getAttribute( 'icon' )
188190
const currentIconRef = useRef( _icon )
189191
const processedIconRef = useRef( null )
@@ -202,6 +204,19 @@ export const Icon = props => {
202204
return
203205
}
204206

207+
// Don't use page icons for multicolor icons
208+
// because we target svg elements with the :nth-of-type() selector to apply the multicolor styles.
209+
if ( iconColorType === 'multicolor' ) {
210+
// Clean up if this icon was previously in the page-icons store
211+
if ( processedIconRef.current === _icon && _icon ) {
212+
dispatch( 'stackable/page-icons' ).removePageIcon( _icon )
213+
processedIconRef.current = null
214+
setIcon( _icon ) // Use the original icon directly
215+
lastIconValueRef.current = _icon
216+
}
217+
return
218+
}
219+
205220
// Check if icon exists in pageIcons Map
206221
// The Map structure is: [SVG string (key), { id: iconId, count: number } (value)]
207222
if ( _icon ) {
@@ -282,7 +297,7 @@ export const Icon = props => {
282297
lastIconValueRef.current = null
283298
}
284299
}
285-
}, [ _icon ] )
300+
}, [ _icon, iconColorType ] )
286301

287302
useEffect( () => {
288303
return () => {

src/plugins/page-icons/index.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@ pageIconsWrapper?.setAttribute( 'id', 'stk-page-icons' )
2828
domReady( () => {
2929
if ( pageIconsWrapper ) {
3030
pageIconsWrapper.setAttribute( 'id', 'stk-page-icons' )
31-
pageIconsWrapper.setAttribute( 'style', 'display: none;' )
31+
// Don't use `display: none` to hide the page icons because it prevents gradients from being applied.
32+
pageIconsWrapper.setAttribute( 'style', 'position: absolute; top: 0; left: -9999px; width: 0; height: 0; visibility: hidden;' )
3233
createRoot( pageIconsWrapper ).render( <PageIcons /> )
3334
}
3435
} )

0 commit comments

Comments
 (0)