Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: #7330, AutoComplete: Selected item is not getting highlighted when visited again unlike Dropdown component #7331

Merged
merged 3 commits into from
Oct 14, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion components/lib/autocomplete/AutoCompleteBase.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ const classes = {
listWrapper: 'p-autocomplete-items-wrapper',
list: ({ virtualScrollerOptions, options }) => (virtualScrollerOptions ? classNames('p-autocomplete-items', options.className) : 'p-autocomplete-items'),
emptyMessage: 'p-autocomplete-item',
item: ({ suggestion, optionGroupLabel }) => (optionGroupLabel ? classNames('p-autocomplete-item', { 'p-disabled': suggestion.disabled }) : classNames('p-autocomplete-item', { 'p-disabled': suggestion.disabled })),
item: ({ suggestion, optionGroupLabel, selected }) =>
optionGroupLabel ? classNames('p-autocomplete-item', { 'p-disabled': suggestion.disabled }, { selected: selected }) : classNames('p-autocomplete-item', { 'p-disabled': suggestion.disabled }, { selected: selected }),
itemGroup: 'p-autocomplete-item-group',
footer: 'p-autocomplete-footer',
transition: 'p-connected-overlay'
Expand Down Expand Up @@ -84,6 +85,10 @@ const styles = `
padding: 0;
list-style-type: none;
}

.selected {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Selected is weird should it be p-selected or is this what the other component does?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can change it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed to p-highlight similar to dropdown component.

background-color: rgba(6, 182, 212, 0.24) !important;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should it be !important ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed the style added for p-highlight as a default style was already applied for autocomplete p-highlight class, and its working as expected.

}

.p-autocomplete-item {
cursor: pointer;
Expand Down
12 changes: 10 additions & 2 deletions components/lib/autocomplete/AutoCompletePanel.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,14 +78,22 @@ export const AutoCompletePanel = React.memo(
);
};

const isOptionSelected = (item) => {
if (props.selectedItem && props.selectedItem.current && Array.isArray(props.selectedItem.current)) {
return props.selectedItem.current.some((selectedItem) => ObjectUtils.deepEquals(selectedItem, item));
} else {
return ObjectUtils.deepEquals(props.selectedItem.current, item);
}
};

const createListItem = (item, key, index, listItemProps) => {
const selected = ObjectUtils.deepEquals(props.selectedItem, item);
const selected = isOptionSelected(item);
const content = props.itemTemplate ? ObjectUtils.getJSXElement(props.itemTemplate, item, index) : props.field ? ObjectUtils.resolveFieldData(item, props.field) : item;
const itemProps = mergeProps(
{
index: index,
role: 'option',
className: cx('item', { optionGroupLabel: props.optionGroupLabel, suggestion: item }),
className: cx('item', { optionGroupLabel: props.optionGroupLabel, suggestion: item, selected: selected }),
onClick: (e) => props.onItemClick(e, item),
'aria-selected': selected,
...listItemProps
Expand Down
Loading