@veracity/vui 2.20.0-rc.2 → 2.20.0-rc.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@veracity/vui",
3
- "version": "2.20.0-rc.2",
3
+ "version": "2.20.0-rc.3",
4
4
  "description": "Veracity UI is a React component library crafted for use within Veracity applications and pages. Based on Styled Components and @xstyled.",
5
5
  "module": "./dist/esm/index.js",
6
6
  "main": "./dist/cjs/index.js",
@@ -4,7 +4,7 @@ import { Checkbox } from '../checkbox'
4
4
  import { useStyleConfig, vui } from '../core'
5
5
  import { List, ListItem } from '../list'
6
6
  import { usePopoverContext } from '../popover'
7
- import { cs, ellipsisOverflow, MouseEvent, useCallbackRef } from '../utils'
7
+ import { cs, ellipsisOverflow, KeyboardEvent, MouseEvent, useCallbackRef } from '../utils'
8
8
  import { useSelectContext } from './context'
9
9
  import { SelectOptionProps } from './select.types'
10
10
 
@@ -21,22 +21,22 @@ export const SelectOption = vui<'li', SelectOptionProps>((props, ref) => {
21
21
 
22
22
  const isSelected = Array.isArray(value) && valueProp ? value.includes(valueProp) : value === valueProp
23
23
 
24
- const onClick = useCallbackRef((e: MouseEvent<HTMLLIElement>) => {
25
- // Clone original click event
24
+ const onClick = useCallbackRef((e: MouseEvent<HTMLLIElement> | KeyboardEvent<HTMLLIElement>) => {
26
25
  const nativeEvent = e.nativeEvent || e
27
26
  const clonedEvent = new (nativeEvent.constructor as any)(nativeEvent.type, nativeEvent)
28
27
 
29
- // Extend cloned event with 'value' and 'name'
30
28
  Object.defineProperty(clonedEvent, 'target', {
31
29
  writable: true,
32
30
  value: { value: valueProp, name },
33
31
  })
34
32
 
35
- onClickProp?.(e)
33
+ onClickProp?.(e as MouseEvent<HTMLLIElement>)
36
34
  onChange?.(clonedEvent)
37
35
  !isMultiple && instance?.hide()
38
36
  })
39
37
 
38
+ const onKeyDown = useCallbackRef((e: KeyboardEvent<HTMLLIElement>) => e.key === 'Enter' && onClick(e))
39
+
40
40
  return (
41
41
  <ListItem
42
42
  activeBg="skyBlue.active"
@@ -46,8 +46,10 @@ export const SelectOption = vui<'li', SelectOptionProps>((props, ref) => {
46
46
  isInteractive
47
47
  isSelected={isSelected}
48
48
  onClick={onClick}
49
+ onKeyDown={onKeyDown}
49
50
  ref={ref}
50
51
  selectedBg="skyBlue.selected"
52
+ tabIndex={0}
51
53
  title={title}
52
54
  value={valueProp}
53
55
  {...styles.option}