1- import React , { ReactNode , Ref , SyntheticEvent , useMemo } from 'react' ;
1+ import React , { ReactNode , Ref , SyntheticEvent } from 'react' ;
22
33import classNames from 'classnames' ;
44import isEmpty from 'lodash/isEmpty' ;
55
66import { ListProps , Size } from '@lumx/react' ;
77import { GenericProps } from '@lumx/react/utils/type' ;
8- import { onEnterPressed , onButtonPressed } from '@lumx/core/js/utils' ;
98import { getRootClassName , handleBasicClasses } from '@lumx/core/js/utils/className' ;
10- import { renderLink } from '@lumx/react/utils/react/renderLink' ;
119import { forwardRef } from '@lumx/react/utils/react/forwardRef' ;
1210import { useDisableStateProps } from '@lumx/react/utils/disabled/useDisableStateProps' ;
1311import { HasAriaDisabled } from '@lumx/react/utils/type/HasAriaDisabled' ;
12+ import { RawClickable } from '@lumx/react/utils/react/RawClickable' ;
1413
1514export type ListItemSize = Extract < Size , 'tiny' | 'regular' | 'big' | 'huge' > ;
1615
@@ -94,13 +93,6 @@ export const ListItem = forwardRef<ListItemProps, HTMLLIElement>((props, ref) =>
9493 ...forwardedProps
9594 } = otherProps ;
9695
97- const role = linkAs || linkProps . href ? 'link' : 'button' ;
98- const onKeyDown = useMemo ( ( ) => {
99- if ( onItemSelected && role === 'link' ) return onEnterPressed ( onItemSelected as any ) ;
100- if ( onItemSelected && role === 'button' ) return onButtonPressed ( onItemSelected as any ) ;
101- return undefined ;
102- } , [ role , onItemSelected ] ) ;
103-
10496 const content = (
10597 < >
10698 { before && < div className = { `${ CLASSNAME } __before` } > { before } </ div > }
@@ -123,28 +115,23 @@ export const ListItem = forwardRef<ListItemProps, HTMLLIElement>((props, ref) =>
123115 >
124116 { isClickable ( { linkProps, onItemSelected } ) ? (
125117 /* Clickable list item */
126- renderLink (
127- {
128- linkAs,
129- tabIndex : ! disabledStateProps . disabled ? 0 : undefined ,
130- role,
131- 'aria-disabled' : isAnyDisabled ,
132- ...linkProps ,
133- href : isAnyDisabled ? undefined : linkProps . href ,
134- className : classNames (
135- handleBasicClasses ( {
136- prefix : `${ CLASSNAME } __link` ,
137- isHighlighted,
138- isSelected,
139- isDisabled : isAnyDisabled ,
140- } ) ,
141- ) ,
142- onClick : isAnyDisabled ? undefined : onItemSelected ,
143- onKeyDown : isAnyDisabled ? undefined : onKeyDown ,
144- ref : linkRef ,
145- } ,
146- content ,
147- )
118+ < RawClickable
119+ as = { linkAs || ( linkProps . href ? 'a' : 'button' ) }
120+ { ...linkProps }
121+ { ...disabledStateProps }
122+ className = { classNames (
123+ handleBasicClasses ( {
124+ prefix : `${ CLASSNAME } __link` ,
125+ isHighlighted,
126+ isSelected,
127+ isDisabled : isAnyDisabled ,
128+ } ) ,
129+ ) }
130+ onClick = { onItemSelected }
131+ ref = { linkRef }
132+ >
133+ { content }
134+ </ RawClickable >
148135 ) : (
149136 /* Non clickable list item */
150137 < div className = { `${ CLASSNAME } __wrapper` } > { content } </ div >
0 commit comments