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 7, 2024
1 parent 72bc4d4 commit b754773
Show file tree
Hide file tree
Showing 28 changed files with 105 additions and 83 deletions.
14 changes: 7 additions & 7 deletions components/doc/slider/filterdoc.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export function FilterDoc(props) {

const code = {
basic: `
<img alt="user header" class="w-full md:w-20rem border-round mb-4" src="https://primefaces.org/cdn/primevue/images/card-vue.jpg" style={filterStyle()} />
<img alt="user header" className="w-full md:w-20rem border-round mb-4" src="https://primefaces.org/cdn/primevue/images/card-vue.jpg" style={filterStyle()} />
<SelectButton value={filter} onChange={(e) => setFilter(e.value)} options={filterOptions} className="mb-3" />
<Slider
value={filterValues[filter]}
Expand All @@ -46,8 +46,8 @@ export default function FilterDemo() {
return (
<div className="card flex justify-content-center">
<div class="flex flex-column align-items-center">
<img alt="user header" class="w-full md:w-20rem border-round mb-4" src="https://primefaces.org/cdn/primevue/images/card-vue.jpg" style={filterStyle()} />
<div className="flex flex-column align-items-center">
<img alt="user header" className="w-full md:w-20rem border-round mb-4" src="https://primefaces.org/cdn/primevue/images/card-vue.jpg" style={filterStyle()} />
<SelectButton value={filter} onChange={(e) => setFilter(e.value)} options={filterOptions} className="mb-3" />
<Slider
value={filterValues[filter]}
Expand Down Expand Up @@ -75,8 +75,8 @@ export default function FilterDemo() {
return (
<div className="card flex justify-content-center">
<div class="flex flex-column align-items-center">
<img alt="user header" class="w-full md:w-20rem border-round mb-4" src="https://primefaces.org/cdn/primevue/images/card-vue.jpg" style={filterStyle()} />
<div className="flex flex-column align-items-center">
<img alt="user header" className="w-full md:w-20rem border-round mb-4" src="https://primefaces.org/cdn/primevue/images/card-vue.jpg" style={filterStyle()} />
<SelectButton value={filter} onChange={(e) => setFilter(e.value)} options={filterOptions} className="mb-3" />
<Slider
value={filterValues[filter]}
Expand Down Expand Up @@ -104,8 +104,8 @@ export default function FilterDemo() {
</p>
</DocSectionText>
<div className="card flex justify-content-center">
<div class="flex flex-column align-items-center">
<img alt="user header" class="w-full md:w-20rem border-round mb-4" src="https://primefaces.org/cdn/primevue/images/card-vue.jpg" style={filterStyle()} />
<div className="flex flex-column align-items-center">
<img alt="user header" className="w-full md:w-20rem border-round mb-4" src="https://primefaces.org/cdn/primevue/images/card-vue.jpg" style={filterStyle()} />
<SelectButton value={filter} onChange={(e) => setFilter(e.value)} options={filterOptions} className="mb-3" />
<Slider
value={filterValues[filter]}
Expand Down
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
3 changes: 1 addition & 2 deletions components/lib/carousel/Carousel.js
Original file line number Diff line number Diff line change
Expand Up @@ -741,7 +741,6 @@ export const Carousel = React.memo(
const key = 'carousel-indicator-' + index;
const indicatorProps = mergeProps(
{
key,
className: cx('indicator', { isActive }),
'data-p-highlight': isActive
},
Expand All @@ -760,7 +759,7 @@ export const Carousel = React.memo(
);

return (
<li {...indicatorProps}>
<li {...indicatorProps} key={key}>
<button {...indicatorButtonProps}>
<Ripple />
</button>
Expand Down
1 change: 1 addition & 0 deletions components/lib/cascadeselect/CascadeSelectBase.js
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ export const CascadeSelectBase = ComponentBase.extend({
disabled: false,
loadingIcon: null,
dropdownIcon: null,
loading: false,
id: null,
inputId: null,
inputRef: null,
Expand Down
14 changes: 7 additions & 7 deletions components/lib/chip/Chip.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { PrimeReactContext } from '../api/Api';
import { useHandleStyle } from '../componentbase/ComponentBase';
import { useMergeProps } from '../hooks/Hooks';
import { TimesCircleIcon } from '../icons/timescircle';
import { classNames, IconUtils, ObjectUtils } from '../utils/Utils';
import { classNames, IconUtils, ObjectUtils, UniqueComponentId } from '../utils/Utils';
import { ChipBase } from './ChipBase';

export const Chip = React.memo(
Expand Down 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 @@ -51,12 +50,11 @@ export const Chip = React.memo(
ptm('removeIcon')
);

const icon = props.removeIcon || <TimesCircleIcon {...removeIconProps} />;
const icon = props.removeIcon || <TimesCircleIcon {...removeIconProps} key={UniqueComponentId('removeIcon')} />;

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
13 changes: 6 additions & 7 deletions components/lib/datascroller/DataScroller.js
Original file line number Diff line number Diff line change
Expand Up @@ -190,15 +190,14 @@ export const DataScroller = React.memo(
};

const createItem = (_value, index) => {
const itemProps = mergeProps(
{
key: index + '_datascrollitem'
},
ptm('item')
);
const itemProps = ptm('item');
const content = props.itemTemplate ? props.itemTemplate(_value) : _value;

return <li {...itemProps}>{content}</li>;
return (
<li {...itemProps} key={index + '_datascrollitem'}>
{content}
</li>
);
};

const createEmptyMessage = () => {
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
7 changes: 5 additions & 2 deletions components/lib/galleria/GalleriaItem.js
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,6 @@ export const GalleriaItem = React.memo(
const indicatorProps = mergeProps(
{
className: cx('indicator', { isActive }),
key: key,
tabIndex: 0,
'aria-label': ariaPageLabel(index + 1),
'aria-selected': props.activeIndex === index,
Expand All @@ -308,7 +307,11 @@ export const GalleriaItem = React.memo(
);
}

return <li {...indicatorProps}>{indicator}</li>;
return (
<li {...indicatorProps} key={key}>
{indicator}
</li>
);
};

const createIndicators = () => {
Expand Down
3 changes: 1 addition & 2 deletions components/lib/galleria/GalleriaThumbnails.js
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,6 @@ const GalleriaThumbnailItem = React.memo((props) => {
const thumbnailItemProps = mergeProps(
{
className: classNames(props.className, cx('thumbnailItem', { subProps: props })),
key: 'p-galleria-thumbnail-item-' + props.index,
role: 'tab',
'data-p-active': props.current,
'aria-selected': props.current,
Expand All @@ -157,7 +156,7 @@ const GalleriaThumbnailItem = React.memo((props) => {
);

return (
<div {...thumbnailItemProps}>
<div {...thumbnailItemProps} key={props.index + '_galleriathumbnailitem'}>
<div {...thumbnailItemContentProps}>{content}</div>
</div>
);
Expand Down
3 changes: 1 addition & 2 deletions components/lib/inputotp/InputOtp.js
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,6 @@ export const InputOtp = React.memo(
};
const inputElementProps = {
id: inputElementIndex,
key: inputElementIndex,
value: tokens[inputElementIndex] || '',
inputMode: props?.integerOnly ? 'numeric' : 'text',
type: props?.mask ? 'password' : 'text',
Expand All @@ -221,7 +220,7 @@ export const InputOtp = React.memo(
props: inputElementProps
})
) : (
<InputText {...inputElementProps} {...inputElementEvents} />
<InputText {...inputElementProps} {...inputElementEvents} key={inputElementIndex} />
);
const inputElements = [inputElement, ...createInputElements(remainingInputs - 1)];

Expand Down
2 changes: 1 addition & 1 deletion components/lib/listbox/ListBox.js
Original file line number Diff line number Diff line change
Expand Up @@ -749,7 +749,7 @@ export const ListBox = React.memo(
);

return (
<li key={key} {...itemGroupProps}>
<li {...itemGroupProps} key={key}>
{groupContent}
</li>
);
Expand Down
3 changes: 1 addition & 2 deletions components/lib/listbox/ListBoxItem.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ export const ListBoxItem = React.memo((props) => {
onMouseDown: (event) => props.onOptionMouseDown(event, props.index),
onMouseMove: (event) => props.onOptionMouseMove(event, props.index),
'aria-label': props.label,
key: props.optionKey,
role: 'option',
'aria-selected': props.selected,
'aria-disabled': props.disabled,
Expand All @@ -76,7 +75,7 @@ export const ListBoxItem = React.memo((props) => {
);

return (
<li {...itemProps}>
<li {...itemProps} key={props.optionKey}>
{content}
<Ripple />
</li>
Expand Down
1 change: 1 addition & 0 deletions components/lib/mention/MentionBase.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ export const MentionBase = ComponentBase.extend({
defaultProps: {
__TYPE: 'Mention',
autoHighlight: true,
autoResize: false,
className: null,
delay: 0,
field: null,
Expand Down
Loading

0 comments on commit b754773

Please sign in to comment.