@veracity/vui 2.21.0 → 2.21.1
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/dist/cjs/select/select.d.ts.map +1 -1
- package/dist/cjs/select/select.js +3 -6
- package/dist/cjs/select/select.js.map +1 -1
- package/dist/cjs/select/select.types.d.ts +4 -0
- package/dist/cjs/select/select.types.d.ts.map +1 -1
- package/dist/cjs/select/selectOption.d.ts.map +1 -1
- package/dist/cjs/select/selectOption.js +13 -2
- package/dist/cjs/select/selectOption.js.map +1 -1
- package/dist/esm/select/select.d.ts.map +1 -1
- package/dist/esm/select/select.js +3 -5
- package/dist/esm/select/select.js.map +1 -1
- package/dist/esm/select/select.types.d.ts +4 -0
- package/dist/esm/select/select.types.d.ts.map +1 -1
- package/dist/esm/select/selectOption.d.ts.map +1 -1
- package/dist/esm/select/selectOption.js +13 -2
- package/dist/esm/select/selectOption.js.map +1 -1
- package/dist/tsconfig.legacy.tsbuildinfo +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/src/select/select.tsx +5 -4
- package/src/select/select.types.ts +4 -0
- package/src/select/selectOption.tsx +14 -3
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@veracity/vui",
|
|
3
|
-
"version": "2.21.
|
|
3
|
+
"version": "2.21.1",
|
|
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",
|
package/src/select/select.tsx
CHANGED
|
@@ -27,6 +27,7 @@ export function Select(props: SelectProps) {
|
|
|
27
27
|
defaultValue,
|
|
28
28
|
disabled,
|
|
29
29
|
errorText,
|
|
30
|
+
closeOnScroll,
|
|
30
31
|
helpText,
|
|
31
32
|
id: idProp,
|
|
32
33
|
isInvalid,
|
|
@@ -73,9 +74,7 @@ export function Select(props: SelectProps) {
|
|
|
73
74
|
variant,
|
|
74
75
|
...selectProps,
|
|
75
76
|
}
|
|
76
|
-
const onQueryChange = (e: any) =>
|
|
77
|
-
setQuery(e.target.value?.toLowerCase())
|
|
78
|
-
}
|
|
77
|
+
const onQueryChange = (e: any) => setQuery(e.target.value?.toLowerCase())
|
|
79
78
|
|
|
80
79
|
const filterOptions = (i: SelectOptionData) =>
|
|
81
80
|
!showOptionsFilter || !query?.length ? true : i?.text?.toLowerCase()?.includes(query)
|
|
@@ -115,7 +114,9 @@ export function Select(props: SelectProps) {
|
|
|
115
114
|
)}
|
|
116
115
|
<SelectGroup maxH={maxHeight} tabIndex={1000}>
|
|
117
116
|
{children ??
|
|
118
|
-
filteredOptions?.map?.(option =>
|
|
117
|
+
filteredOptions?.map?.(option => (
|
|
118
|
+
<SelectOption closeOnScroll={closeOnScroll} key={option.value} title={option.text} {...option} />
|
|
119
|
+
))}
|
|
119
120
|
</SelectGroup>
|
|
120
121
|
</SelectContent>
|
|
121
122
|
</>
|
|
@@ -24,6 +24,8 @@ export type SelectProps = ThemingProps<'Select'> &
|
|
|
24
24
|
UseSelectProps & {
|
|
25
25
|
/** Select cannot be opened and is styled accordingly. */
|
|
26
26
|
disabled?: boolean
|
|
27
|
+
/** Hiding the options list on scroll event. Recommended for scrollable containers. */
|
|
28
|
+
closeOnScroll?: boolean
|
|
27
29
|
/** Socket displaying error text below an input. */
|
|
28
30
|
errorText?: string | React.ReactNode
|
|
29
31
|
/** Socket displaying help text below an input. */
|
|
@@ -64,6 +66,8 @@ export type SelectOptionData = {
|
|
|
64
66
|
}
|
|
65
67
|
|
|
66
68
|
export type SelectOptionProps = ListItemProps & {
|
|
69
|
+
/** Hiding the options list on scroll event. */
|
|
70
|
+
closeOnScroll?: boolean
|
|
67
71
|
/** Currently selected value. Can be a string/number or array of those when using 'isMultiple'. */
|
|
68
72
|
value?: SelectValue
|
|
69
73
|
/** Hover title text. */
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { useEffect } from 'react'
|
|
2
2
|
|
|
3
3
|
import { Checkbox } from '../checkbox'
|
|
4
4
|
import { useStyleConfig, vui } from '../core'
|
|
@@ -14,13 +14,15 @@ import { SelectOptionProps } from './select.types'
|
|
|
14
14
|
* 'onChange' is triggered with a modified click event, which adds 'value' and 'name' properties.
|
|
15
15
|
*/
|
|
16
16
|
export const SelectOption = vui<'li', SelectOptionProps>((props, ref) => {
|
|
17
|
-
const { children, className, disabled, title, onClick: onClickProp, value: valueProp, ...rest } = props
|
|
17
|
+
const { children, closeOnScroll, className, disabled, title, onClick: onClickProp, value: valueProp, ...rest } = props
|
|
18
18
|
const { instance } = usePopoverContext() ?? {}
|
|
19
19
|
const { isMultiple, name, onChange, value } = useSelectContext() ?? {}
|
|
20
20
|
const styles = useStyleConfig('Select', useSelectContext())
|
|
21
21
|
|
|
22
22
|
const isSelected = Array.isArray(value) && valueProp ? value.includes(valueProp) : value === valueProp
|
|
23
23
|
|
|
24
|
+
const hide = () => instance?.hide()
|
|
25
|
+
|
|
24
26
|
const onClick = useCallbackRef((e: MouseEvent<HTMLLIElement> | KeyboardEvent<HTMLLIElement>) => {
|
|
25
27
|
const nativeEvent = e.nativeEvent || e
|
|
26
28
|
const clonedEvent = new (nativeEvent.constructor as any)(nativeEvent.type, nativeEvent)
|
|
@@ -32,11 +34,20 @@ export const SelectOption = vui<'li', SelectOptionProps>((props, ref) => {
|
|
|
32
34
|
|
|
33
35
|
onClickProp?.(e as MouseEvent<HTMLLIElement>)
|
|
34
36
|
onChange?.(clonedEvent)
|
|
35
|
-
!isMultiple &&
|
|
37
|
+
!isMultiple && hide()
|
|
36
38
|
})
|
|
37
39
|
|
|
38
40
|
const onKeyDown = useCallbackRef((e: KeyboardEvent<HTMLLIElement>) => e.key === 'Enter' && onClick(e))
|
|
39
41
|
|
|
42
|
+
// Hiding the popover on scroll
|
|
43
|
+
useEffect(() => {
|
|
44
|
+
if (closeOnScroll) document.addEventListener('scroll', hide, true)
|
|
45
|
+
|
|
46
|
+
return () => {
|
|
47
|
+
if (closeOnScroll) document.removeEventListener('scroll', hide, true)
|
|
48
|
+
}
|
|
49
|
+
}, [closeOnScroll])
|
|
50
|
+
|
|
40
51
|
return (
|
|
41
52
|
<ListItem
|
|
42
53
|
activeBg="skyBlue.active"
|