Skip to content

Commit 7fba73a

Browse files
authored
Global Styles: use color slug as key in the Palette component color indicator (#44344)
* use slug as color indicator key in gs palette In the global styles panel's palette component, the color's hex code is used as a `key` for the ColorIndicatorWrapper, but the hex is not necessarily a unique identifier, unlike the `slug` attribute, which could be expected to be unique, at least by usage; discussion around improving handling of duplicate color in the palette [here](#43197). Composing the color + index of the element in the array, using it as an index, keeps these error messages away: > Warning: Encountered two children with the same key, `.$#040DE1`. Keys should be unique so that components maintain their identity across updates. Non-unique keys may cause children to be duplicated and/or omitted — the behavior is unsupported and could change in a future version. with a palette that looks lilke this: ```json [ { "color": "#040DE1", "name": "Primary", "slug": "primary" }, { "color": "#040DE1", "name": "Foreground", "slug": "foreground" }, ] ``` * compose color, index as color indicator key
1 parent 9580611 commit 7fba73a

File tree

1 file changed

+9
-5
lines changed
  • packages/edit-site/src/components/global-styles

1 file changed

+9
-5
lines changed

packages/edit-site/src/components/global-styles/palette.js

+9-5
Original file line numberDiff line numberDiff line change
@@ -68,11 +68,15 @@ function Palette( { name } ) {
6868
}
6969
>
7070
<ZStack isLayered={ false } offset={ -8 }>
71-
{ colors.slice( 0, 5 ).map( ( { color } ) => (
72-
<ColorIndicatorWrapper key={ color }>
73-
<ColorIndicator colorValue={ color } />
74-
</ColorIndicatorWrapper>
75-
) ) }
71+
{ colors
72+
.slice( 0, 5 )
73+
.map( ( { color }, index ) => (
74+
<ColorIndicatorWrapper
75+
key={ `${ color }-${ index }` }
76+
>
77+
<ColorIndicator colorValue={ color } />
78+
</ColorIndicatorWrapper>
79+
) ) }
7680
</ZStack>
7781
<FlexItem>{ paletteButtonText }</FlexItem>
7882
</HStack>

0 commit comments

Comments
 (0)