@@ -10,6 +10,7 @@ import React, {
1010 useContext ,
1111 useState ,
1212 useEffect ,
13+ EventHandler ,
1314} from 'react' ;
1415import classnames from 'classnames' ;
1516import { AutoAlign , AutoAlignInjectedProps , AutoAlignProps } from './AutoAlign' ;
@@ -30,11 +31,12 @@ import {
3031 useMergeRefs ,
3132} from './hooks' ;
3233import { createFC } from './common' ;
34+ import { Bivariant } from './typeUtils' ;
3335
3436/**
3537 *
3638 */
37- type Entry = {
39+ export type LookupEntry = {
3840 label : string ;
3941 value : string ;
4042 icon ?: string ;
@@ -43,9 +45,7 @@ type Entry = {
4345 meta ?: string ;
4446} ;
4547
46- export type LookupEntry = Entry ;
47-
48- export type LookupSelectionProps < LookupEntry extends Entry > = {
48+ export type LookupSelectionProps = {
4949 id ?: string ;
5050 selected ?: LookupEntry ;
5151 hidden ?: boolean ;
@@ -56,9 +56,7 @@ export type LookupSelectionProps<LookupEntry extends Entry> = {
5656/**
5757 *
5858 */
59- export const LookupSelection = < LookupEntry extends Entry > (
60- props : LookupSelectionProps < LookupEntry >
61- ) => {
59+ export const LookupSelection : FC < LookupSelectionProps > = ( props ) => {
6260 const { id, hidden, selected, lookupSelectionRef, onResetSelection } = props ;
6361 const pillRef = useRef < HTMLElement | null > ( null ) ;
6462
@@ -130,7 +128,7 @@ export type LookupSearchProps = Omit<
130128 disabled ?: boolean ;
131129 onBlur ?: ( ) => void ;
132130 onSearchTextChange ?: ( searchText : string ) => void ;
133- onScopeMenuClick ?: ( e : SyntheticEvent < HTMLButtonElement > ) => void ;
131+ onScopeMenuClick ?: EventHandler < SyntheticEvent < HTMLButtonElement > > ;
134132 onScopeSelect ?: ( value : string ) => void ;
135133 onPressDown ?: ( ) => void ;
136134 onSubmit ?: ( ) => void ;
@@ -351,7 +349,7 @@ export const LookupSearch: FC<LookupSearchProps> = (props) => {
351349/**
352350 *
353351 */
354- type LookupCandidateListProps < LookupEntry extends Entry > = {
352+ type LookupCandidateListProps = {
355353 data ?: LookupEntry [ ] ;
356354 focus ?: boolean ;
357355 loading ?: boolean ;
@@ -370,9 +368,9 @@ function trueFilter() {
370368/**
371369 *
372370 */
373- const LookupCandidateListInner = < LookupEntry extends Entry > (
374- props : LookupCandidateListProps < LookupEntry > & AutoAlignInjectedProps
375- ) => {
371+ const LookupCandidateListInner : FC <
372+ LookupCandidateListProps & AutoAlignInjectedProps
373+ > = ( props ) => {
376374 const {
377375 data = [ ] ,
378376 loading,
@@ -528,13 +526,10 @@ const LookupCandidateListInner = <LookupEntry extends Entry>(
528526/**
529527 *
530528 */
531- const LookupCandidateList = < LookupEntry extends Entry > ( {
532- align,
533- portalClassName,
534- portalStyle,
535- ...props
536- } : LookupCandidateListProps < LookupEntry > &
537- Pick < AutoAlignProps , 'align' | 'portalClassName' | 'portalStyle' > ) => (
529+ const LookupCandidateList : FC <
530+ LookupCandidateListProps &
531+ Pick < AutoAlignProps , 'align' | 'portalClassName' | 'portalStyle' >
532+ > = ( { align, portalClassName, portalStyle, ...props } ) => (
538533 < AutoAlign
539534 triggerSelector = '.slds-lookup'
540535 alignmentStyle = 'menu'
@@ -551,10 +546,7 @@ const LookupCandidateList = <LookupEntry extends Entry>({
551546/**
552547 *
553548 */
554- export type LookupProps <
555- LookupEntry extends Entry ,
556- SelectedEntry extends LookupEntry
557- > = {
549+ export type LookupProps = {
558550 label ?: string ;
559551 disabled ?: boolean ;
560552 required ?: boolean ;
@@ -564,8 +556,8 @@ export type LookupProps<
564556 value ?: string | null ;
565557 defaultValue ?: string | null ;
566558
567- selected ?: SelectedEntry | null ;
568- defaultSelected ?: SelectedEntry | null ;
559+ selected ?: LookupEntry | null ;
560+ defaultSelected ?: LookupEntry | null ;
569561
570562 opened ?: boolean ;
571563 defaultOpened ?: boolean ;
@@ -575,11 +567,9 @@ export type LookupProps<
575567
576568 loading ?: boolean ;
577569 data ?: LookupEntry [ ] ;
578- lookupFilter ?: (
579- entry : LookupEntry ,
580- searchText ?: string ,
581- targetScope ?: string
582- ) => boolean ;
570+ lookupFilter ?: Bivariant <
571+ ( entry : LookupEntry , searchText ?: string , targetScope ?: string ) => boolean
572+ > ;
583573 listHeader ?: JSX . Element ;
584574 listFooter ?: JSX . Element ;
585575 scopes ?: LookupScope [ ] ;
@@ -593,12 +583,12 @@ export type LookupProps<
593583 selectionRef ?: Ref < HTMLDivElement > ;
594584
595585 onSearchTextChange ?: ( searchText : string ) => void ;
596- onScopeMenuClick ?: ( e : SyntheticEvent < HTMLButtonElement > ) => void ;
586+ onScopeMenuClick ?: EventHandler < SyntheticEvent < HTMLButtonElement > > ;
597587 onScopeSelect ?: ( targetScope : string ) => void ;
598588 onLookupRequest ?: ( searchText : string ) => void ;
599589 onBlur ?: ( ) => void ;
600590 onFocus ?: ( ) => void ;
601- onSelect ?: ( entry : LookupEntry | null ) => void ;
591+ onSelect ?: Bivariant < ( entry : LookupEntry | null ) => void > ;
602592 onValueChange ?: ( value : string | null , prevValue ?: string | null ) => void ;
603593 onComplete ?: ( cancel ?: boolean ) => void ;
604594} & Omit <
@@ -609,10 +599,8 @@ export type LookupProps<
609599/**
610600 *
611601 */
612- export const Lookup = createFC (
613- < LookupEntry extends Entry , SelectedEntry extends LookupEntry > (
614- props : LookupProps < LookupEntry , SelectedEntry >
615- ) => {
602+ export const Lookup = createFC < LookupProps , { isFormElement : boolean } > (
603+ ( props ) => {
616604 const {
617605 id : id_ ,
618606 value : value_ ,
@@ -685,7 +673,7 @@ export const Lookup = createFC(
685673 const dropdownRef = useMergeRefs ( [ dropdownElRef , dropdownRef_ ] ) ;
686674
687675 const onScopeMenuClick = useEventCallback (
688- ( e : SyntheticEvent < HTMLButtonElement > ) => {
676+ ( e : MouseEvent < HTMLButtonElement > ) => {
689677 setOpened ( false ) ;
690678 onScopeMenuClick_ ?.( e ) ;
691679 }
0 commit comments