Skip to content

Commit 44a10e3

Browse files
(Lookup): use scope value instead of its label
1 parent 1c78f20 commit 44a10e3

File tree

1 file changed

+24
-26
lines changed

1 file changed

+24
-26
lines changed

src/scripts/Lookup.tsx

Lines changed: 24 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@ export type LookupEntry = {
4040
*/
4141
export type LookupScope = {
4242
label: string;
43-
value?: string;
44-
icon?: string;
43+
value: string;
44+
icon: string;
4545
category?: IconCategory;
4646
};
4747

@@ -235,7 +235,7 @@ const LookupScopeSelector: FC<LookupScopeSelectorProps> = ({
235235
const [scopeFocusedIndex, setScopeFocusedIndex] = useState<number>(-1);
236236

237237
const currentScope =
238-
scopes.find((scope) => scope.label === targetScope) ?? scopes[0];
238+
scopes.find((scope) => scope.value === targetScope) ?? scopes[0];
239239

240240
// Scroll focused scope element into view
241241
const scrollFocusedScopeIntoView = useEventCallback(
@@ -300,7 +300,7 @@ const LookupScopeSelector: FC<LookupScopeSelectorProps> = ({
300300
if (scopeOpened && scopeFocusedIndex >= 0) {
301301
const selectedScope = scopes[scopeFocusedIndex];
302302
if (selectedScope) {
303-
onScopeSelect(selectedScope.label);
303+
onScopeSelect(selectedScope.value);
304304
setScopeOpened(false);
305305
setScopeFocusedIndex(-1);
306306
}
@@ -386,24 +386,22 @@ const LookupScopeSelector: FC<LookupScopeSelectorProps> = ({
386386
className='slds-combobox__form-element slds-input-has-icon slds-input-has-icon_left-right'
387387
role='none'
388388
>
389-
{currentScope?.icon && (
390-
<div
391-
className='slds-is-absolute'
392-
style={{
393-
top: '50%',
394-
transform: 'translateY(-50%)',
395-
left: '0.5rem',
396-
pointerEvents: 'none',
397-
zIndex: SCOPE_INPUT_ZINDEX + 1,
398-
}}
399-
>
400-
<Icon
401-
category={currentScope.category}
402-
icon={currentScope.icon}
403-
size='small'
404-
/>
405-
</div>
406-
)}
389+
<div
390+
className='slds-is-absolute'
391+
style={{
392+
top: '50%',
393+
transform: 'translateY(-50%)',
394+
left: '0.5rem',
395+
pointerEvents: 'none',
396+
zIndex: SCOPE_INPUT_ZINDEX + 1,
397+
}}
398+
>
399+
<Icon
400+
category={currentScope.category}
401+
icon={currentScope.icon}
402+
size='small'
403+
/>
404+
</div>
407405
<input
408406
type='text'
409407
className='slds-input slds-combobox__input slds-combobox__input-value'
@@ -460,7 +458,7 @@ const LookupScopeSelector: FC<LookupScopeSelectorProps> = ({
460458
>
461459
{scopes.map((scope, index) => (
462460
<li
463-
key={scope.label}
461+
key={scope.value}
464462
role='presentation'
465463
className='slds-listbox__item'
466464
>
@@ -473,9 +471,9 @@ const LookupScopeSelector: FC<LookupScopeSelectorProps> = ({
473471
}
474472
)}
475473
role='option'
476-
aria-selected={scope.label === targetScope}
474+
aria-selected={scope.value === targetScope}
477475
tabIndex={0}
478-
onClick={() => onScopeSelect(scope.label)}
476+
onClick={() => onScopeSelect(scope.value)}
479477
>
480478
<span className='slds-media__figure slds-listbox__option-icon'>
481479
{scope.icon && (
@@ -982,7 +980,7 @@ export const Lookup = createFC<LookupProps, { isFormElement: boolean }>(
982980
const [targetScope, setTargetScope] = useControlledValue(
983981
targetScope_,
984982
defaultTargetScope ??
985-
(scopes && scopes.length > 0 ? scopes[0].label : undefined)
983+
(scopes && scopes.length > 0 ? scopes[0].value : undefined)
986984
);
987985
const [focusedValue, setFocusedValue] = useState<string | undefined>();
988986

0 commit comments

Comments
 (0)