diff --git a/src/list/item/ListItem.tsx b/src/list/item/ListItem.tsx index dc9c787b..afd4f1a4 100644 --- a/src/list/item/ListItem.tsx +++ b/src/list/item/ListItem.tsx @@ -30,27 +30,30 @@ function ListItem({ listItemRef }: ListItemProps) { const containerClassName = classNames("list-item", customClassName); - let listItem = ( -
  • - {children} -
  • - ); + const listItemProps: React.DetailedHTMLProps< + React.LiHTMLAttributes, + HTMLLIElement + > & { + "data-testid": string | undefined; + } = { + ref: listItemRef, + id, + "data-testid": testid, + className: containerClassName, + role, + "aria-selected": ariaSelected + }; + let listItem =
  • {children}
  • ; if (clickableListItemProps) { listItem = ( -
  • +
  • + onKeyDown={handleKeyDown}> {children}
  • @@ -60,11 +63,11 @@ function ListItem({ return listItem; function handleClick(event: React.SyntheticEvent) { - clickableListItemProps!.onClick(event); + clickableListItemProps?.onClick(event); } - function handleKeyPress(event: React.KeyboardEvent) { - if (event.key === KEYBOARD_EVENT_KEY.ENTER) { + function handleKeyDown(event: React.KeyboardEvent) { + if ([KEYBOARD_EVENT_KEY.ENTER, KEYBOARD_EVENT_KEY.SPACE].includes(event.key)) { handleClick(event); } }