Skip to content

Commit 7ddfb0f

Browse files
(Lookup): introduce onSearchIconClick
1 parent 44a10e3 commit 7ddfb0f

File tree

1 file changed

+25
-10
lines changed

1 file changed

+25
-10
lines changed

src/scripts/Lookup.tsx

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -525,6 +525,7 @@ type LookupSearchInputProps = {
525525
onInputFocus: () => void;
526526
onInputBlur: (e: FocusEvent) => void;
527527
onInputKeyDown: (e: KeyboardEvent) => void;
528+
onSearchIconClick: () => void;
528529
} & Omit<
529530
InputHTMLAttributes<HTMLInputElement>,
530531
'onChange' | 'onBlur' | 'onFocus' | 'onKeyDown' | 'value'
@@ -548,6 +549,7 @@ const LookupSearchInput: FC<LookupSearchInputProps> = ({
548549
onInputFocus,
549550
onInputBlur,
550551
onInputKeyDown,
552+
onSearchIconClick,
551553
...rprops
552554
}) => {
553555
const hasValue = searchText.length > 0;
@@ -565,14 +567,16 @@ const LookupSearchInput: FC<LookupSearchInputProps> = ({
565567
return (
566568
<div className={inputIconClasses} role='none'>
567569
{iconAlign === 'left' && (
568-
<Icon
569-
containerClassName={classnames(
570+
<Button
571+
type='icon'
572+
icon='search'
573+
disabled={disabled}
574+
className={classnames(
570575
'slds-input__icon',
571576
`slds-input__icon_${iconAlign}`
572577
)}
573-
category='utility'
574-
icon='search'
575-
size='x-small'
578+
tabIndex={-1}
579+
onClick={disabled ? undefined : onSearchIconClick}
576580
/>
577581
)}
578582
<input
@@ -599,14 +603,16 @@ const LookupSearchInput: FC<LookupSearchInputProps> = ({
599603
onKeyDown={onInputKeyDown}
600604
/>
601605
{iconAlign === 'right' && (
602-
<Icon
603-
containerClassName={classnames(
606+
<Button
607+
type='icon'
608+
icon='search'
609+
disabled={disabled}
610+
className={classnames(
604611
'slds-input__icon',
605612
`slds-input__icon_${iconAlign}`
606613
)}
607-
category='utility'
608-
icon='search'
609-
size='x-small'
614+
tabIndex={-1}
615+
onClick={disabled ? undefined : onSearchIconClick}
610616
/>
611617
)}
612618
</div>
@@ -1219,6 +1225,13 @@ export const Lookup = createFC<LookupProps, { isFormElement: boolean }>(
12191225
setFocusedValue(value);
12201226
});
12211227

1228+
const onSearchIconClick = useEventCallback(() => {
1229+
inputElRef.current?.focus();
1230+
1231+
setOpened(true);
1232+
onLookupRequest_?.(searchText);
1233+
});
1234+
12221235
const onRemoveSelection = useEventCallback(() => {
12231236
onSelect(null);
12241237
setSearchText('');
@@ -1316,6 +1329,7 @@ export const Lookup = createFC<LookupProps, { isFormElement: boolean }>(
13161329
onInputFocus={onInputFocus}
13171330
onInputBlur={onInputBlur}
13181331
onInputKeyDown={onInputKeyDown}
1332+
onSearchIconClick={onSearchIconClick}
13191333
/>
13201334
</div>
13211335
</div>
@@ -1363,6 +1377,7 @@ export const Lookup = createFC<LookupProps, { isFormElement: boolean }>(
13631377
onInputFocus={onInputFocus}
13641378
onInputBlur={onInputBlur}
13651379
onInputKeyDown={onInputKeyDown}
1380+
onSearchIconClick={onSearchIconClick}
13661381
/>
13671382
</div>
13681383
<LookupDropdown

0 commit comments

Comments
 (0)