Skip to content

Commit

Permalink
Merge pull request #152 from PrashantkumarWebDeveloper/patch-1
Browse files Browse the repository at this point in the history
Make item icons optional
  • Loading branch information
pozil committed Feb 1, 2024
2 parents 5958c7d + df6b8a2 commit 83084ac
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/main/default/classes/LookupSearchResult.cls
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public virtual class LookupSearchResult implements Comparable {
/**
* @param id the lookup entry identifier (generally a record ID)
* @param sObjectType Optional - The sObject type of the selected record. This value is not used for lookup rendering. It's passed back to the selection handler in case you search on multiple object types.
* @param icon Optional - A qualified SLDS icon name taken from https://www.lightningdesignsystem.com/icons. It defaults to standard:default.
* @param icon Optional - A qualified SLDS icon name taken from https://www.lightningdesignsystem.com/icons. No icon is displayed by default.
* @param title Required - The label of the lookup entry
* @param subtitle Optional - A subtitle that is displayed under the lookup entry label
*/
Expand Down
8 changes: 6 additions & 2 deletions src/main/default/lwc/lookup/lookup.html
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
<div class={getComboboxClass} role="none">
<template lwc:if={isSingleEntry}>
<lightning-icon
lwc:if={getSelectIconName}
icon-name={getSelectIconName}
size="small"
alternative-text="Selected item icon"
Expand Down Expand Up @@ -106,7 +107,10 @@
onclick={handleResultClick}
data-recordid={item.result.id}
>
<span class="slds-media__figure slds-listbox__option-icon">
<span
class="slds-media__figure slds-listbox__option-icon"
lwc:if={item.result.icon}
>
<lightning-icon
icon-name={item.result.icon}
size="small"
Expand Down Expand Up @@ -193,7 +197,7 @@
onremove={handleRemoveSelectedItem}
name={item.id}
>
<lightning-icon icon-name={item.icon}></lightning-icon>
<lightning-icon icon-name={item.icon} lwc:if={item.icon}></lightning-icon>
</lightning-pill>
</li>
</template>
Expand Down
9 changes: 4 additions & 5 deletions src/main/default/lwc/lookup/lookup.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,10 +104,6 @@ export default class Lookup extends NavigationMixin(LightningElement) {
result.titleFormatted = result.title;
result.subtitleFormatted = result.subtitle;
}
// Add icon if missing
if (typeof result.icon === 'undefined') {
result.icon = 'standard:default';
}
return result;
});
// Add local state and dynamic class to search results
Expand Down Expand Up @@ -414,7 +410,10 @@ export default class Lookup extends NavigationMixin(LightningElement) {
if (this.isMultiEntry) {
css += 'slds-input-has-icon_right';
} else {
css += this.hasSelection() ? 'slds-input-has-icon_left-right' : 'slds-input-has-icon_right';
css +=
this.hasSelection() && this._curSelection[0].icon
? 'slds-input-has-icon_left-right'
: 'slds-input-has-icon_right';
}
return css;
}
Expand Down

0 comments on commit 83084ac

Please sign in to comment.