Skip to content

Commit

Permalink
Fix primefaces#6995: Key should be reference on element and not spread
Browse files Browse the repository at this point in the history
  • Loading branch information
melloware committed Aug 6, 2024
1 parent 72bc4d4 commit 91da3b2
Show file tree
Hide file tree
Showing 12 changed files with 58 additions and 45 deletions.
7 changes: 5 additions & 2 deletions components/lib/autocomplete/AutoCompletePanel.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,15 +64,18 @@ export const AutoCompletePanel = React.memo(
const itemGroupProps = mergeProps(
{
index,
key: key ? key : null,
className: cx('itemGroup'),
'data-p-highlight': false,
...labelItemProps
},
_ptm('itemGroup')
);

return <li {...itemGroupProps}>{content}</li>;
return (
<li {...itemGroupProps} key={key ? key : null}>
{content}
</li>
);
};

const createListItem = (item, key, index, listItemProps) => {
Expand Down
21 changes: 15 additions & 6 deletions components/lib/breadcrumb/BreadCrumb.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,14 +106,17 @@ export const BreadCrumb = React.memo(
const menuitemProps = mergeProps(
{
id: key,
key,
className: cx('home', { _className, disabled }),
style
},
ptm('home')
);

return <li {...menuitemProps}>{content}</li>;
return (
<li {...menuitemProps} key={key}>
{content}
</li>
);
}

return null;
Expand All @@ -133,14 +136,17 @@ export const BreadCrumb = React.memo(
const separatorProps = mergeProps(
{
id: key,
key,
className: cx('separator'),
role: 'separator'
},
ptm('separator')
);

return <li {...separatorProps}>{separatorIcon}</li>;
return (
<li {...separatorProps} key={key}>
{separatorIcon}
</li>
);
};

const createMenuitem = (item, index) => {
Expand Down Expand Up @@ -184,14 +190,17 @@ export const BreadCrumb = React.memo(
const menuitemProps = mergeProps(
{
id: key,
key,
className: cx('menuitem', { item }),
style: item.style
},
ptm('menuitem')
);

return <li {...menuitemProps}>{content}</li>;
return (
<li {...menuitemProps} key={key}>
{content}
</li>
);
};

const createMenuitems = () => {
Expand Down
10 changes: 4 additions & 6 deletions components/lib/calendar/Calendar.js
Original file line number Diff line number Diff line change
Expand Up @@ -3587,8 +3587,7 @@ export const Calendar = React.memo(
const dates = createDates(monthMetaData, groupIndex);
const containerProps = mergeProps(
{
className: cx('container'),
key: UniqueComponentId('calendar_container_')
className: cx('container')
},
ptm('container')
);
Expand All @@ -3605,7 +3604,7 @@ export const Calendar = React.memo(

return (
currentView === 'date' && (
<div {...containerProps}>
<div {...containerProps} key={UniqueComponentId('calendar_container_')}>
<table {...tableProps}>
<thead {...tableHeaderProps}>
<tr {...tableHeaderRowProps}>{dayNames}</tr>
Expand Down Expand Up @@ -3635,15 +3634,14 @@ export const Calendar = React.memo(

const headerProps = mergeProps(
{
className: cx('header'),
key: index
className: cx('header')
},
ptm('header')
);

return (
<div {...groupProps} key={monthKey}>
<div {...headerProps}>
<div {...headerProps} key={index}>
{header}
{backwardNavigator}
{title}
Expand Down
10 changes: 5 additions & 5 deletions components/lib/chip/Chip.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ export const Chip = React.memo(

const removeIconProps = mergeProps(
{
key: 'removeIcon',
role: 'button',
tabIndex: 0,
className: cx('removeIcon'),
Expand All @@ -56,7 +55,6 @@ export const Chip = React.memo(
if (props.image) {
const imageProps = mergeProps(
{
key: 'image',
src: props.image,
onError: props.onImageError
},
Expand All @@ -67,7 +65,6 @@ export const Chip = React.memo(
} else if (props.icon) {
const chipIconProps = mergeProps(
{
key: 'icon',
className: cx('icon')
},
ptm('icon')
Expand All @@ -79,13 +76,16 @@ export const Chip = React.memo(
if (props.label) {
const labelProps = mergeProps(
{
key: 'label',
className: cx('label')
},
ptm('label')
);

content.push(<span {...labelProps}>{props.label}</span>);
content.push(
<span {...labelProps} key="label">
{props.label}
</span>
);
}

if (props.removable) {
Expand Down
3 changes: 1 addition & 2 deletions components/lib/chips/Chips.js
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,6 @@ export const Chips = React.memo(
const icon = createRemoveIcon(value, index);
const tokenProps = mergeProps(
{
key: `${index}_${value}`,
id: props.inputId + '_chips_item_' + index,
role: 'option',
'aria-label': value,
Expand All @@ -364,7 +363,7 @@ export const Chips = React.memo(
);

return (
<li {...tokenProps}>
<li {...tokenProps} key={`${index}_${value}`}>
{label}
{icon}
</li>
Expand Down
3 changes: 1 addition & 2 deletions components/lib/dock/Dock.js
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,6 @@ export const Dock = React.memo(
{
id: key,
role: 'menuitem',
key,
'aria-label': label,
'aria-disabled': disabled,
'data-p-focused': active,
Expand All @@ -250,7 +249,7 @@ export const Dock = React.memo(
);

return (
<li {...menuitemProps}>
<li {...menuitemProps} key={key}>
<div {...contentProps}>{content}</div>
</li>
);
Expand Down
15 changes: 9 additions & 6 deletions components/lib/menu/Menu.js
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,6 @@ export const Menu = React.memo(
const submenuHeaderProps = mergeProps(
{
id: key,
key,
role: 'none',
className: classNames(submenu.className, cx('submenuHeader', { submenu })),
style: sx('submenuHeader', { submenu }),
Expand All @@ -313,7 +312,9 @@ export const Menu = React.memo(

return (
<React.Fragment key={key}>
<li {...submenuHeaderProps}>{submenu.label}</li>
<li {...submenuHeaderProps} key={key}>
{submenu.label}
</li>
{items}
</React.Fragment>
);
Expand All @@ -324,14 +325,13 @@ export const Menu = React.memo(
const separatorProps = mergeProps(
{
id: key,
key,
className: classNames(item.className, cx('separator')),
role: 'separator'
},
ptm('separator')
);

return <li {...separatorProps} />;
return <li {...separatorProps} key={key} />;
};

const createMenuItem = (item, index, parentId = null) => {
Expand Down Expand Up @@ -408,7 +408,6 @@ export const Menu = React.memo(
const menuitemProps = mergeProps(
{
id: key,
key,
className: classNames(item.className, cx('menuitem', { focused: focusedOptionIndex === key })),
style: sx('menuitem', { item }),
role: 'menuitem',
Expand All @@ -420,7 +419,11 @@ export const Menu = React.memo(
getMenuItemPTOptions('menuitem', menuContext)
);

return <li {...menuitemProps}>{content}</li>;
return (
<li {...menuitemProps} key={key}>
{content}
</li>
);
};

const createItem = (item, index) => {
Expand Down
11 changes: 5 additions & 6 deletions components/lib/menubar/MenubarSub.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,19 +103,18 @@ export const MenubarSub = React.memo(
return index - props.model.slice(0, index).filter((processedItem) => isItemVisible(processedItem) && getItemProp(processedItem, 'separator')).length + 1;
};

const createSeparator = (index) => {
const key = props.id + '_separator_' + index;
const createSeparator = (processedItem, index) => {
const key = props.id + '_separator_' + index + '_' + processedItem.key;
const separatorProps = mergeProps(
{
key,
'data-id': key,
className: cx('separator'),
role: 'separator'
},
ptm('separator', { hostName: props.hostName })
);

return <li {...separatorProps} />;
return <li {...separatorProps} key={key} />;
};

const createSubmenu = (processedItem) => {
Expand Down Expand Up @@ -258,15 +257,15 @@ export const MenubarSub = React.memo(
);

return (
<li {...menuitemProps} key={dataId}>
<li {...menuitemProps} key={`${dataId}`}>
<div {...contentProps}>{content}</div>
{submenu}
</li>
);
};

const createItem = (processedItem, index) => {
return getItemProp(processedItem, 'separator') ? createSeparator(index) : createMenuitem(processedItem, index);
return getItemProp(processedItem, 'separator') ? createSeparator(processedItem, index) : createMenuitem(processedItem, index);
};

const createMenu = () => {
Expand Down
3 changes: 1 addition & 2 deletions components/lib/panelmenu/PanelMenu.js
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,6 @@ export const PanelMenu = React.memo(

const panelProps = mergeProps(
{
key: key,
id: item?.id || generatePanelId(index),
className: cx('panel', { item }),
style: item.style
Expand Down Expand Up @@ -394,7 +393,7 @@ export const PanelMenu = React.memo(
);

return (
<div {...panelProps}>
<div {...panelProps} key={key}>
<div {...headerProps}>
<div {...headerContentProps}>{content}</div>
</div>
Expand Down
6 changes: 2 additions & 4 deletions components/lib/panelmenu/PanelMenuSub.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,14 +94,13 @@ export const PanelMenuSub = React.memo(
const separatorProps = mergeProps(
{
id: key,
key,
className: cx('separator'),
role: 'separator'
},
_ptm('separator')
);

return <li {...separatorProps} />;
return <li {...separatorProps} key={key} />;
};

const createSubmenu = (processedItem, active) => {
Expand Down Expand Up @@ -232,7 +231,6 @@ export const PanelMenuSub = React.memo(

const menuitemProps = mergeProps(
{
key,
id: key,
className: cx('menuitem', { item, focused: itemFocused, disabled: disabled }),
style: item.style,
Expand All @@ -249,7 +247,7 @@ export const PanelMenuSub = React.memo(
);

return (
<li {...menuitemProps}>
<li {...menuitemProps} key={key}>
<div {...contentProps}>{content}</div>
{submenu}
</li>
Expand Down
7 changes: 5 additions & 2 deletions components/lib/steps/Steps.js
Original file line number Diff line number Diff line change
Expand Up @@ -232,15 +232,18 @@ export const Steps = React.memo(

const menuItemProps = mergeProps(
{
key,
id: key,
className: cx('menuitem', { active, disabled, item }),
style: item.style
},
ptm('menuitem')
);

return <li {...menuItemProps}>{content}</li>;
return (
<li {...menuItemProps} key={key}>
{content}
</li>
);
};

const createItems = () => {
Expand Down
7 changes: 5 additions & 2 deletions components/lib/tabmenu/TabMenu.js
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,6 @@ export const TabMenu = React.memo(
{
ref: tabsRef.current[`tab_${index}`],
id: key,
key,
onKeyDown: (event) => onKeyDownItem(event, item, index),
className: cx('menuitem', { _className, active, disabled }),
style: style,
Expand All @@ -296,7 +295,11 @@ export const TabMenu = React.memo(
getPTOptions('menuitem', item, index)
);

return <li {...menuItemProps}>{content}</li>;
return (
<li {...menuItemProps} key={key}>
{content}
</li>
);
};

const createItems = () => {
Expand Down

0 comments on commit 91da3b2

Please sign in to comment.