@dhis2-ui/select 10.16.3-alpha.1 → 10.16.4
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/build/cjs/locales/index.js +94 -57
- package/build/cjs/multi-select/features/menu_width_matches_input/index.js +2 -4
- package/build/cjs/multi-select/features/position/index.js +6 -12
- package/build/cjs/multi-select/filterable-menu.js +22 -25
- package/build/cjs/multi-select/input.js +14 -15
- package/build/cjs/multi-select/menu.js +24 -28
- package/build/cjs/multi-select/multi-select.e2e.stories.js +21 -32
- package/build/cjs/multi-select/multi-select.js +30 -31
- package/build/cjs/multi-select/multi-select.prod.stories.js +13 -21
- package/build/cjs/multi-select/selection-list.js +51 -57
- package/build/cjs/multi-select-option/multi-select-option.js +27 -30
- package/build/cjs/select/debounce/debounce.js +2 -6
- package/build/cjs/select/empty.js +11 -14
- package/build/cjs/select/filter-input.js +21 -24
- package/build/cjs/select/filterable-menu.js +6 -8
- package/build/cjs/select/input-clear-button.js +28 -31
- package/build/cjs/select/input-placeholder.js +5 -6
- package/build/cjs/select/input-prefix.js +5 -6
- package/build/cjs/select/input-wrapper.js +13 -14
- package/build/cjs/select/loading.js +15 -18
- package/build/cjs/select/menu-wrapper.js +8 -9
- package/build/cjs/select/no-match.js +9 -12
- package/build/cjs/select/select.js +3 -4
- package/build/cjs/simple-single-select/__stories__/DefaultPosition.js +1 -2
- package/build/cjs/simple-single-select/__stories__/Dense.js +1 -2
- package/build/cjs/simple-single-select/__stories__/Empty.js +1 -2
- package/build/cjs/simple-single-select/__stories__/EmptyWithEmptyNode.js +1 -2
- package/build/cjs/simple-single-select/__stories__/EmptyWithEmptyText.js +1 -2
- package/build/cjs/simple-single-select/__stories__/FlippedPosition.js +1 -2
- package/build/cjs/simple-single-select/__stories__/InfiniteLoading.js +1 -2
- package/build/cjs/simple-single-select/__stories__/ShiftedIntoView.js +1 -2
- package/build/cjs/simple-single-select/__stories__/WithClearButton.js +1 -2
- package/build/cjs/simple-single-select/__stories__/WithCustomLowMaxHeight.js +1 -2
- package/build/cjs/simple-single-select/__stories__/WithCustomOptions.js +17 -21
- package/build/cjs/simple-single-select/__stories__/WithDisabledOption.js +1 -2
- package/build/cjs/simple-single-select/__stories__/WithFilterField.js +5 -9
- package/build/cjs/simple-single-select/__stories__/WithInitialFocus.js +1 -2
- package/build/cjs/simple-single-select/__stories__/WithManyOptions.js +1 -2
- package/build/cjs/simple-single-select/__stories__/WithMultipleSelectsAndScrollableParent.js +1 -2
- package/build/cjs/simple-single-select/__stories__/WithNoMatchText.js +1 -2
- package/build/cjs/simple-single-select/__stories__/WithOnBlur.js +1 -2
- package/build/cjs/simple-single-select/__stories__/WithOnFocus.js +1 -2
- package/build/cjs/simple-single-select/__stories__/WithOptionsAndDisabled.js +1 -2
- package/build/cjs/simple-single-select/__stories__/WithOptionsAndLoading.js +1 -2
- package/build/cjs/simple-single-select/__stories__/WithOptionsAndLoadingText.js +1 -2
- package/build/cjs/simple-single-select/__stories__/WithPlaceholder.js +1 -2
- package/build/cjs/simple-single-select/__stories__/WithPlaceholderAndSelection.js +1 -2
- package/build/cjs/simple-single-select/__stories__/WithPrefix.js +1 -2
- package/build/cjs/simple-single-select/__stories__/WithPrefixAndSelection.js +1 -2
- package/build/cjs/simple-single-select/__stories__/WithRTL.js +1 -2
- package/build/cjs/simple-single-select/__stories__/WithScrollingParent.js +1 -2
- package/build/cjs/simple-single-select/__stories__/WithSelection.js +1 -2
- package/build/cjs/simple-single-select/__stories__/WithSelectionAndDisabled.js +1 -2
- package/build/cjs/simple-single-select/__stories__/WithServerSideFilteringDemo.js +25 -36
- package/build/cjs/simple-single-select/__stories__/WithSimpleFilteringDemo.js +4 -6
- package/build/cjs/simple-single-select/__stories__/WithoutOptionsAndLoading.js +1 -2
- package/build/cjs/simple-single-select/__stories__/WithoutSelection.js +1 -2
- package/build/cjs/simple-single-select/__stories__/simple-single-select-server-side-filtering/CustomDataProvider.js +19 -26
- package/build/cjs/simple-single-select/features/keyboard-interactions.test.e2e.js +9 -18
- package/build/cjs/simple-single-select/features/menu-positioning.test.e2e.js +8 -16
- package/build/cjs/simple-single-select/menu/empty.js +8 -11
- package/build/cjs/simple-single-select/menu/filter.js +11 -12
- package/build/cjs/simple-single-select/menu/loading.js +3 -4
- package/build/cjs/simple-single-select/menu/menu.js +26 -28
- package/build/cjs/simple-single-select/menu/no-match.js +9 -12
- package/build/cjs/simple-single-select/menu/option.js +20 -23
- package/build/cjs/simple-single-select/menu/options-list.js +23 -26
- package/build/cjs/simple-single-select/selected-value/clear-button.js +5 -6
- package/build/cjs/simple-single-select/selected-value/container.js +23 -25
- package/build/cjs/simple-single-select/selected-value/placeholder.js +5 -6
- package/build/cjs/simple-single-select/selected-value/prefix.js +5 -6
- package/build/cjs/simple-single-select/selected-value/selected-value.js +34 -35
- package/build/cjs/simple-single-select/simple-single-select.e2e.stories.js +1 -2
- package/build/cjs/simple-single-select/simple-single-select.js +47 -50
- package/build/cjs/simple-single-select/simple-single-select.test.js +14 -24
- package/build/cjs/simple-single-select/use-handle-key-press/use-focus-option.js +5 -6
- package/build/cjs/simple-single-select/use-handle-key-press/use-handle-key-press-on-combobox.js +31 -34
- package/build/cjs/simple-single-select/use-handle-key-press/use-handle-key-press-on-filter-input.js +11 -12
- package/build/cjs/simple-single-select/use-handle-key-press/use-handle-typing.js +10 -14
- package/build/cjs/simple-single-select/use-handle-key-press/use-highlight-first-option-on-previous-page.js +6 -7
- package/build/cjs/simple-single-select/use-handle-key-press/use-highlight-first-visible-option.js +5 -6
- package/build/cjs/simple-single-select/use-handle-key-press/use-highlight-last-option-on-next-page.js +6 -7
- package/build/cjs/simple-single-select/use-handle-key-press/use-highlight-last-visible-option.js +5 -6
- package/build/cjs/simple-single-select/use-handle-key-press/use-page-down.js +6 -7
- package/build/cjs/simple-single-select/use-handle-key-press/use-page-up.js +6 -7
- package/build/cjs/simple-single-select/use-handle-key-press/utils.js +17 -22
- package/build/cjs/simple-single-select-field/simple-single-select-field.js +3 -6
- package/build/cjs/simple-single-select-field/simple-single-select-field.prod.stories.js +1 -2
- package/build/cjs/simple-single-select-field/simple-single-select-field.test.js +3 -6
- package/build/cjs/single-select/features/menu_width_matches_input/index.js +2 -4
- package/build/cjs/single-select/features/position/index.js +4 -8
- package/build/cjs/single-select/filterable-menu.js +22 -25
- package/build/cjs/single-select/input.js +13 -14
- package/build/cjs/single-select/menu.js +9 -10
- package/build/cjs/single-select/selection.js +5 -6
- package/build/cjs/single-select/single-select.e2e.stories.js +18 -28
- package/build/cjs/single-select/single-select.js +29 -30
- package/build/cjs/single-select/single-select.prod.stories.js +7 -11
- package/build/cjs/single-select-option/single-select-option.js +25 -28
- package/build/es/locales/index.js +70 -33
- package/build/es/multi-select/features/menu_width_matches_input/index.js +2 -4
- package/build/es/multi-select/features/position/index.js +6 -12
- package/build/es/multi-select/filterable-menu.js +22 -25
- package/build/es/multi-select/input.js +14 -15
- package/build/es/multi-select/menu.js +24 -28
- package/build/es/multi-select/multi-select.e2e.stories.js +20 -30
- package/build/es/multi-select/multi-select.js +30 -31
- package/build/es/multi-select/multi-select.prod.stories.js +12 -19
- package/build/es/multi-select/selection-list.js +51 -57
- package/build/es/multi-select-option/multi-select-option.js +27 -30
- package/build/es/select/debounce/debounce.js +2 -6
- package/build/es/select/empty.js +11 -14
- package/build/es/select/filter-input.js +21 -24
- package/build/es/select/filterable-menu.js +5 -6
- package/build/es/select/input-clear-button.js +28 -31
- package/build/es/select/input-placeholder.js +5 -6
- package/build/es/select/input-prefix.js +5 -6
- package/build/es/select/input-wrapper.js +13 -14
- package/build/es/select/loading.js +15 -18
- package/build/es/select/menu-wrapper.js +8 -9
- package/build/es/select/no-match.js +9 -12
- package/build/es/select/select.js +2 -2
- package/build/es/simple-single-select/__stories__/WithCustomOptions.js +16 -19
- package/build/es/simple-single-select/__stories__/WithFilterField.js +4 -7
- package/build/es/simple-single-select/__stories__/WithServerSideFilteringDemo.js +24 -34
- package/build/es/simple-single-select/__stories__/WithSimpleFilteringDemo.js +3 -4
- package/build/es/simple-single-select/__stories__/simple-single-select-server-side-filtering/CustomDataProvider.js +19 -26
- package/build/es/simple-single-select/features/keyboard-interactions.test.e2e.js +9 -18
- package/build/es/simple-single-select/features/menu-positioning.test.e2e.js +8 -16
- package/build/es/simple-single-select/menu/empty.js +8 -11
- package/build/es/simple-single-select/menu/filter.js +11 -12
- package/build/es/simple-single-select/menu/loading.js +3 -4
- package/build/es/simple-single-select/menu/menu.js +25 -26
- package/build/es/simple-single-select/menu/no-match.js +9 -12
- package/build/es/simple-single-select/menu/option.js +19 -21
- package/build/es/simple-single-select/menu/options-list.js +22 -24
- package/build/es/simple-single-select/selected-value/clear-button.js +5 -6
- package/build/es/simple-single-select/selected-value/container.js +22 -23
- package/build/es/simple-single-select/selected-value/placeholder.js +5 -6
- package/build/es/simple-single-select/selected-value/prefix.js +5 -6
- package/build/es/simple-single-select/selected-value/selected-value.js +34 -35
- package/build/es/simple-single-select/simple-single-select.js +46 -48
- package/build/es/simple-single-select/simple-single-select.test.js +13 -22
- package/build/es/simple-single-select/use-handle-key-press/use-focus-option.js +5 -6
- package/build/es/simple-single-select/use-handle-key-press/use-handle-key-press-on-combobox.js +31 -34
- package/build/es/simple-single-select/use-handle-key-press/use-handle-key-press-on-filter-input.js +11 -12
- package/build/es/simple-single-select/use-handle-key-press/use-handle-typing.js +10 -14
- package/build/es/simple-single-select/use-handle-key-press/use-highlight-first-option-on-previous-page.js +6 -7
- package/build/es/simple-single-select/use-handle-key-press/use-highlight-first-visible-option.js +5 -6
- package/build/es/simple-single-select/use-handle-key-press/use-highlight-last-option-on-next-page.js +6 -7
- package/build/es/simple-single-select/use-handle-key-press/use-highlight-last-visible-option.js +5 -6
- package/build/es/simple-single-select/use-handle-key-press/use-page-down.js +6 -7
- package/build/es/simple-single-select/use-handle-key-press/use-page-up.js +6 -7
- package/build/es/simple-single-select/use-handle-key-press/utils.js +17 -22
- package/build/es/simple-single-select-field/simple-single-select-field.js +3 -6
- package/build/es/simple-single-select-field/simple-single-select-field.test.js +3 -6
- package/build/es/single-select/features/menu_width_matches_input/index.js +2 -4
- package/build/es/single-select/features/position/index.js +4 -8
- package/build/es/single-select/filterable-menu.js +22 -25
- package/build/es/single-select/input.js +13 -14
- package/build/es/single-select/menu.js +9 -10
- package/build/es/single-select/selection.js +5 -6
- package/build/es/single-select/single-select.e2e.stories.js +17 -26
- package/build/es/single-select/single-select.js +29 -30
- package/build/es/single-select/single-select.prod.stories.js +6 -9
- package/build/es/single-select-option/single-select-option.js +25 -28
- package/package.json +15 -15
- package/src/locales/index.js +102 -33
|
@@ -3,27 +3,26 @@ import { colors, theme } from '@dhis2/ui-constants';
|
|
|
3
3
|
import cx from 'classnames';
|
|
4
4
|
import PropTypes from 'prop-types';
|
|
5
5
|
import React, { forwardRef, useCallback, useEffect } from 'react';
|
|
6
|
-
export const Container = /*#__PURE__*/forwardRef(function Container(
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
} = _ref;
|
|
6
|
+
export const Container = /*#__PURE__*/forwardRef(function Container({
|
|
7
|
+
children,
|
|
8
|
+
comboBoxId,
|
|
9
|
+
autoFocus,
|
|
10
|
+
dataTest,
|
|
11
|
+
dense,
|
|
12
|
+
disabled,
|
|
13
|
+
error,
|
|
14
|
+
expanded,
|
|
15
|
+
labelledBy,
|
|
16
|
+
name,
|
|
17
|
+
placeholder,
|
|
18
|
+
tabIndex,
|
|
19
|
+
valid,
|
|
20
|
+
warning,
|
|
21
|
+
onBlur,
|
|
22
|
+
onClick: _onClick,
|
|
23
|
+
onFocus,
|
|
24
|
+
onKeyDown
|
|
25
|
+
}, ref) {
|
|
27
26
|
// Using useEffect so we have access to the ref, which will be set before
|
|
28
27
|
// the first call to the useEffect's callback
|
|
29
28
|
useEffect(() => {
|
|
@@ -34,9 +33,9 @@ export const Container = /*#__PURE__*/forwardRef(function Container(_ref, ref) {
|
|
|
34
33
|
// We want to run this only once:
|
|
35
34
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
36
35
|
[]);
|
|
37
|
-
const onClick = useCallback(
|
|
36
|
+
const onClick = useCallback((...args) => {
|
|
38
37
|
if (!disabled) {
|
|
39
|
-
_onClick(...
|
|
38
|
+
_onClick(...args);
|
|
40
39
|
}
|
|
41
40
|
}, [disabled, _onClick]);
|
|
42
41
|
return /*#__PURE__*/React.createElement("div", {
|
|
@@ -2,12 +2,11 @@ import _JSXStyle from "styled-jsx/style";
|
|
|
2
2
|
import { colors } from '@dhis2/ui-constants';
|
|
3
3
|
import PropTypes from 'prop-types';
|
|
4
4
|
import React from 'react';
|
|
5
|
-
export function Placeholder(
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
} = _ref;
|
|
5
|
+
export function Placeholder({
|
|
6
|
+
placeholder,
|
|
7
|
+
className,
|
|
8
|
+
dataTest
|
|
9
|
+
}) {
|
|
11
10
|
return /*#__PURE__*/React.createElement("div", {
|
|
12
11
|
"data-test": dataTest,
|
|
13
12
|
className: _JSXStyle.dynamic([["1027033961", [colors.grey600]]]) + " " + (className || "")
|
|
@@ -2,12 +2,11 @@ import _JSXStyle from "styled-jsx/style";
|
|
|
2
2
|
import { colors, spacers } from '@dhis2/ui-constants';
|
|
3
3
|
import PropTypes from 'prop-types';
|
|
4
4
|
import React from 'react';
|
|
5
|
-
export function Prefix(
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
} = _ref;
|
|
5
|
+
export function Prefix({
|
|
6
|
+
prefix,
|
|
7
|
+
className,
|
|
8
|
+
dataTest
|
|
9
|
+
}) {
|
|
11
10
|
return /*#__PURE__*/React.createElement("div", {
|
|
12
11
|
"data-test": dataTest,
|
|
13
12
|
className: _JSXStyle.dynamic([["1343055987", [colors.grey600, spacers.dp12]]]) + " " + (className || "")
|
|
@@ -7,41 +7,40 @@ import { ClearButton } from './clear-button.js';
|
|
|
7
7
|
import { Container } from './container.js';
|
|
8
8
|
import { Placeholder } from './placeholder.js';
|
|
9
9
|
import { Prefix } from './prefix.js';
|
|
10
|
-
export function SelectedValue(
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
} = _ref;
|
|
10
|
+
export function SelectedValue({
|
|
11
|
+
clearText,
|
|
12
|
+
comboBoxId,
|
|
13
|
+
name,
|
|
14
|
+
selectedLabel,
|
|
15
|
+
onKeyDown,
|
|
16
|
+
autoFocus,
|
|
17
|
+
clearable,
|
|
18
|
+
comboBoxRef,
|
|
19
|
+
dataTest,
|
|
20
|
+
dense,
|
|
21
|
+
disabled,
|
|
22
|
+
error,
|
|
23
|
+
expanded,
|
|
24
|
+
filterLabel,
|
|
25
|
+
filterPlaceholder,
|
|
26
|
+
filterRef,
|
|
27
|
+
filterable,
|
|
28
|
+
filterValue,
|
|
29
|
+
hasSelection,
|
|
30
|
+
inputMaxHeight,
|
|
31
|
+
labelledBy,
|
|
32
|
+
placeholder,
|
|
33
|
+
prefix,
|
|
34
|
+
tabIndex,
|
|
35
|
+
valid,
|
|
36
|
+
warning,
|
|
37
|
+
onBlur,
|
|
38
|
+
onClear,
|
|
39
|
+
onClick,
|
|
40
|
+
onFilterChange,
|
|
41
|
+
onFilterInputKeyDown,
|
|
42
|
+
onFocus
|
|
43
|
+
}) {
|
|
45
44
|
const dataTestPrefix = `${dataTest}-selectedvalue`;
|
|
46
45
|
const showFilter = filterable && expanded;
|
|
47
46
|
return /*#__PURE__*/React.createElement(Container, {
|
|
@@ -8,12 +8,11 @@ import { Menu } from './menu/index.js';
|
|
|
8
8
|
import { SelectedValue } from './selected-value/index.js';
|
|
9
9
|
import { optionProp } from './shared-prop-types.js';
|
|
10
10
|
import { useHandleKeyPressOnCombobox, useHandleKeyPressOnFilterInput } from './use-handle-key-press/index.js';
|
|
11
|
-
function useFocussedOptionIndex(
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
} = _ref;
|
|
11
|
+
function useFocussedOptionIndex({
|
|
12
|
+
filterable,
|
|
13
|
+
filterValue,
|
|
14
|
+
options
|
|
15
|
+
}) {
|
|
17
16
|
const [defaultFocussedOptionIndex, setDefaultFocussedOptionIndex] = useState(0);
|
|
18
17
|
const [searchFocussedOptionIndex, setSearchFocussedOptionIndex] = useState(0);
|
|
19
18
|
|
|
@@ -43,47 +42,46 @@ function useFocussedOptionIndex(_ref) {
|
|
|
43
42
|
}, [filterValue]);
|
|
44
43
|
return [focussedOptionIndex, setFocussedOptionIndex];
|
|
45
44
|
}
|
|
46
|
-
export function SimpleSingleSelect(
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
} = _ref2;
|
|
45
|
+
export function SimpleSingleSelect({
|
|
46
|
+
name,
|
|
47
|
+
options,
|
|
48
|
+
onChange,
|
|
49
|
+
autoFocus = false,
|
|
50
|
+
className = '',
|
|
51
|
+
clearText: _clearText = '',
|
|
52
|
+
clearable = false,
|
|
53
|
+
optionComponent = undefined,
|
|
54
|
+
dataTest = 'dhis2-simplesingleselect',
|
|
55
|
+
dense = false,
|
|
56
|
+
disabled = false,
|
|
57
|
+
empty: _empty = false,
|
|
58
|
+
error = false,
|
|
59
|
+
filterLabel = '',
|
|
60
|
+
filterPlaceholder: _filterPlaceholder = '',
|
|
61
|
+
filterValue = '',
|
|
62
|
+
filterable = false,
|
|
63
|
+
inputMaxHeight = '',
|
|
64
|
+
labelledBy = '',
|
|
65
|
+
loading = false,
|
|
66
|
+
menuLoadingText: _menuLoadingText = '',
|
|
67
|
+
menuMaxHeight = '288px',
|
|
68
|
+
noMatchText: _noMatchText = '',
|
|
69
|
+
optionUpdateStrategy = 'polite',
|
|
70
|
+
placeholder = '',
|
|
71
|
+
prefix = '',
|
|
72
|
+
selected = {
|
|
73
|
+
label: '',
|
|
74
|
+
value: ''
|
|
75
|
+
},
|
|
76
|
+
tabIndex = '0',
|
|
77
|
+
valid = false,
|
|
78
|
+
warning = false,
|
|
79
|
+
onBlur = () => undefined,
|
|
80
|
+
onClear = () => undefined,
|
|
81
|
+
onEndReached = () => undefined,
|
|
82
|
+
onFilterChange = () => undefined,
|
|
83
|
+
onFocus = () => undefined
|
|
84
|
+
}) {
|
|
87
85
|
// We can't translate with default props as the translation function would
|
|
88
86
|
// be called before we get any translations from the consuming app/lib
|
|
89
87
|
const clearText = _clearText || i18n.t('Clear');
|
|
@@ -106,7 +104,7 @@ export function SimpleSingleSelect(_ref2) {
|
|
|
106
104
|
if (expanded && filterable) {
|
|
107
105
|
requestAnimationFrame(() => {
|
|
108
106
|
var _filterInputRef$curre;
|
|
109
|
-
(_filterInputRef$curre = filterInputRef.current) === null || _filterInputRef$curre === void 0
|
|
107
|
+
(_filterInputRef$curre = filterInputRef.current) === null || _filterInputRef$curre === void 0 || _filterInputRef$curre.focus();
|
|
110
108
|
});
|
|
111
109
|
}
|
|
112
110
|
}, [expanded, filterable]);
|
|
@@ -5,10 +5,7 @@ import { SimpleSingleSelect } from './simple-single-select.js';
|
|
|
5
5
|
describe('<SimpleSingleSelect />', () => {
|
|
6
6
|
beforeAll(() => {
|
|
7
7
|
const consoleError = console.error;
|
|
8
|
-
jest.spyOn(console, 'error').mockImplementation(
|
|
9
|
-
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
10
|
-
args[_key] = arguments[_key];
|
|
11
|
-
}
|
|
8
|
+
jest.spyOn(console, 'error').mockImplementation((...args) => {
|
|
12
9
|
const [message, dynamicContent] = args;
|
|
13
10
|
if (message.startsWith('Warning: An update to %s inside a test was not wrapped in act(...)') && dynamicContent === 'Popper') {
|
|
14
11
|
return;
|
|
@@ -209,15 +206,12 @@ describe('<SimpleSingleSelect />', () => {
|
|
|
209
206
|
const onChange = jest.fn();
|
|
210
207
|
|
|
211
208
|
// eslint-disable-next-line react/prop-types
|
|
212
|
-
const CustomOption =
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
}
|
|
217
|
-
|
|
218
|
-
"data-test": `custom-option-${value}`
|
|
219
|
-
}, label);
|
|
220
|
-
};
|
|
209
|
+
const CustomOption = ({
|
|
210
|
+
value,
|
|
211
|
+
label
|
|
212
|
+
}) => /*#__PURE__*/React.createElement("span", {
|
|
213
|
+
"data-test": `custom-option-${value}`
|
|
214
|
+
}, label);
|
|
221
215
|
render(/*#__PURE__*/React.createElement(SimpleSingleSelect, {
|
|
222
216
|
name: "simple",
|
|
223
217
|
selected: null,
|
|
@@ -247,15 +241,12 @@ describe('<SimpleSingleSelect />', () => {
|
|
|
247
241
|
const onChange = jest.fn();
|
|
248
242
|
|
|
249
243
|
// eslint-disable-next-line react/prop-types
|
|
250
|
-
const CustomOption =
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
}
|
|
255
|
-
|
|
256
|
-
"data-test": `custom-option-${value}`
|
|
257
|
-
}, label);
|
|
258
|
-
};
|
|
244
|
+
const CustomOption = ({
|
|
245
|
+
value,
|
|
246
|
+
label
|
|
247
|
+
}) => /*#__PURE__*/React.createElement("span", {
|
|
248
|
+
"data-test": `custom-option-${value}`
|
|
249
|
+
}, label);
|
|
259
250
|
render(/*#__PURE__*/React.createElement(SimpleSingleSelect, {
|
|
260
251
|
name: "simple",
|
|
261
252
|
selected: null,
|
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
import { useCallback } from 'react';
|
|
2
|
-
export function useFocusOption(findIndexCallback,
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
} = _ref;
|
|
2
|
+
export function useFocusOption(findIndexCallback, {
|
|
3
|
+
options,
|
|
4
|
+
focussedOptionIndex,
|
|
5
|
+
setFocussedOptionIndex
|
|
6
|
+
}) {
|
|
8
7
|
return useCallback(() => {
|
|
9
8
|
const nextFocussedIndex = findIndexCallback({
|
|
10
9
|
options,
|
package/build/es/simple-single-select/use-handle-key-press/use-handle-key-press-on-combobox.js
CHANGED
|
@@ -4,21 +4,19 @@ import { useHandleTyping } from './use-handle-typing.js';
|
|
|
4
4
|
import { usePageDown } from './use-page-down.js';
|
|
5
5
|
import { usePageUp } from './use-page-up.js';
|
|
6
6
|
import { findNextOptionIndex, findPrevOptionIndex, findFirstOptionIndex, findLastOptionIndex } from './utils.js';
|
|
7
|
-
function isUnmodifiedCharacterKey(
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
} = _ref;
|
|
7
|
+
function isUnmodifiedCharacterKey({
|
|
8
|
+
key,
|
|
9
|
+
altKey,
|
|
10
|
+
ctrlKey,
|
|
11
|
+
metaKey
|
|
12
|
+
}) {
|
|
14
13
|
return key.length === 1 && key !== ' ' && !altKey && !ctrlKey && !metaKey;
|
|
15
14
|
}
|
|
16
|
-
function useSelectOption(findIndexCallback,
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
} = _ref2;
|
|
15
|
+
function useSelectOption(findIndexCallback, {
|
|
16
|
+
options,
|
|
17
|
+
onChange,
|
|
18
|
+
value
|
|
19
|
+
}) {
|
|
22
20
|
return useCallback(() => {
|
|
23
21
|
const currentOptionIndex = options.findIndex(option => option.value === value);
|
|
24
22
|
const nextSelectedOptionIndex = findIndexCallback({
|
|
@@ -35,25 +33,24 @@ function useSelectOption(findIndexCallback, _ref2) {
|
|
|
35
33
|
});
|
|
36
34
|
}, [findIndexCallback, options, onChange, value]);
|
|
37
35
|
}
|
|
38
|
-
export function useHandleKeyPressOnCombobox(
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
} = _ref3;
|
|
36
|
+
export function useHandleKeyPressOnCombobox({
|
|
37
|
+
value,
|
|
38
|
+
disabled,
|
|
39
|
+
expanded,
|
|
40
|
+
loading,
|
|
41
|
+
options,
|
|
42
|
+
openMenu,
|
|
43
|
+
closeMenu,
|
|
44
|
+
listBoxRef,
|
|
45
|
+
focussedOptionIndex,
|
|
46
|
+
setFocussedOptionIndex,
|
|
47
|
+
selectFocussedOption,
|
|
48
|
+
onChange,
|
|
49
|
+
clearable,
|
|
50
|
+
onClear,
|
|
51
|
+
filterable,
|
|
52
|
+
onFilterChange
|
|
53
|
+
}) {
|
|
57
54
|
const {
|
|
58
55
|
onTyping,
|
|
59
56
|
typing
|
|
@@ -142,7 +139,7 @@ export function useHandleKeyPressOnCombobox(_ref3) {
|
|
|
142
139
|
return;
|
|
143
140
|
}
|
|
144
141
|
if (!expanded && clearable && key === 'Escape') {
|
|
145
|
-
onClear === null || onClear === void 0
|
|
142
|
+
onClear === null || onClear === void 0 || onClear();
|
|
146
143
|
return;
|
|
147
144
|
}
|
|
148
145
|
if (!expanded && (key === ' ' && !typing || key === 'Enter' || key === 'ArrowUp' && altKey || key === 'ArrowDown' && altKey)) {
|
|
@@ -175,7 +172,7 @@ export function useHandleKeyPressOnCombobox(_ref3) {
|
|
|
175
172
|
}
|
|
176
173
|
if (filterable && !expanded && isUnmodifiedCharacterKey(event)) {
|
|
177
174
|
openMenu();
|
|
178
|
-
onFilterChange === null || onFilterChange === void 0
|
|
175
|
+
onFilterChange === null || onFilterChange === void 0 || onFilterChange(key);
|
|
179
176
|
return;
|
|
180
177
|
}
|
|
181
178
|
if (key === 'Backspace' || key === 'Clear' || isUnmodifiedCharacterKey(event) || key === ' ' && typing) {
|
package/build/es/simple-single-select/use-handle-key-press/use-handle-key-press-on-filter-input.js
CHANGED
|
@@ -3,18 +3,17 @@ import { useFocusOption } from './use-focus-option.js';
|
|
|
3
3
|
import { usePageDown } from './use-page-down.js';
|
|
4
4
|
import { usePageUp } from './use-page-up.js';
|
|
5
5
|
import { findNextOptionIndex, findPrevOptionIndex, findFirstOptionIndex, findLastOptionIndex } from './utils.js';
|
|
6
|
-
export function useHandleKeyPressOnFilterInput(
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
} = _ref;
|
|
6
|
+
export function useHandleKeyPressOnFilterInput({
|
|
7
|
+
value,
|
|
8
|
+
options,
|
|
9
|
+
loading,
|
|
10
|
+
closeMenu,
|
|
11
|
+
listBoxRef,
|
|
12
|
+
focusComboBox,
|
|
13
|
+
focussedOptionIndex,
|
|
14
|
+
setFocussedOptionIndex,
|
|
15
|
+
selectFocussedOption
|
|
16
|
+
}) {
|
|
18
17
|
const pageDown = usePageDown({
|
|
19
18
|
options,
|
|
20
19
|
focussedOptionIndex,
|
|
@@ -1,13 +1,12 @@
|
|
|
1
1
|
import { useCallback, useEffect, useRef, useState } from 'react';
|
|
2
2
|
const TYPING_DEBOUNCE_TIME = 300; // ms
|
|
3
3
|
|
|
4
|
-
export function useHandleTyping(
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
} = _ref;
|
|
4
|
+
export function useHandleTyping({
|
|
5
|
+
expanded,
|
|
6
|
+
options,
|
|
7
|
+
setFocussedOptionIndex,
|
|
8
|
+
onChange
|
|
9
|
+
}) {
|
|
11
10
|
const [value, setValue] = useState('');
|
|
12
11
|
const [typing, setTyping] = useState(false);
|
|
13
12
|
|
|
@@ -36,13 +35,10 @@ export function useHandleTyping(_ref) {
|
|
|
36
35
|
if (value && value !== prevValueRef.current) {
|
|
37
36
|
// We only want to do this when the value changed
|
|
38
37
|
prevValueRef.current = value;
|
|
39
|
-
const optionIndex = options.findIndex(
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
} = _ref2;
|
|
44
|
-
return !disabled && label.toLowerCase().startsWith(value.toLowerCase());
|
|
45
|
-
});
|
|
38
|
+
const optionIndex = options.findIndex(({
|
|
39
|
+
disabled,
|
|
40
|
+
label
|
|
41
|
+
}) => !disabled && label.toLowerCase().startsWith(value.toLowerCase()));
|
|
46
42
|
if (optionIndex !== -1) {
|
|
47
43
|
if (expanded) {
|
|
48
44
|
setFocussedOptionIndex(optionIndex);
|
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
import { useCallback } from 'react';
|
|
2
|
-
export function useHighlightFirstOptionOnPreviousPage(
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
} = _ref;
|
|
2
|
+
export function useHighlightFirstOptionOnPreviousPage({
|
|
3
|
+
options,
|
|
4
|
+
focussedOptionIndex,
|
|
5
|
+
setFocussedOptionIndex,
|
|
6
|
+
listBoxRef
|
|
7
|
+
}) {
|
|
9
8
|
return useCallback(() => {
|
|
10
9
|
const listBoxParent = listBoxRef.current.parentNode;
|
|
11
10
|
const optionElements = Array.from(listBoxRef.current.childNodes);
|
package/build/es/simple-single-select/use-handle-key-press/use-highlight-first-visible-option.js
CHANGED
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
import { useCallback } from 'react';
|
|
2
|
-
export function useHighlightFirstVisibleOption(
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
} = _ref;
|
|
2
|
+
export function useHighlightFirstVisibleOption({
|
|
3
|
+
options,
|
|
4
|
+
focussedOptionIndex,
|
|
5
|
+
setFocussedOptionIndex
|
|
6
|
+
}) {
|
|
8
7
|
return useCallback(lowestVisibleIndex => {
|
|
9
8
|
if (!options[lowestVisibleIndex].disabled) {
|
|
10
9
|
setFocussedOptionIndex(lowestVisibleIndex);
|
package/build/es/simple-single-select/use-handle-key-press/use-highlight-last-option-on-next-page.js
CHANGED
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
import { useCallback } from 'react';
|
|
2
|
-
export function useHighlightLastOptionOnNextPage(
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
} = _ref;
|
|
2
|
+
export function useHighlightLastOptionOnNextPage({
|
|
3
|
+
options,
|
|
4
|
+
focussedOptionIndex,
|
|
5
|
+
setFocussedOptionIndex,
|
|
6
|
+
listBoxRef
|
|
7
|
+
}) {
|
|
9
8
|
return useCallback(() => {
|
|
10
9
|
const listBoxParent = listBoxRef.current.parentNode;
|
|
11
10
|
const optionElements = Array.from(listBoxRef.current.childNodes);
|
package/build/es/simple-single-select/use-handle-key-press/use-highlight-last-visible-option.js
CHANGED
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
import { useCallback } from 'react';
|
|
2
|
-
export function useHighlightLastVisibleOption(
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
} = _ref;
|
|
2
|
+
export function useHighlightLastVisibleOption({
|
|
3
|
+
options,
|
|
4
|
+
focussedOptionIndex,
|
|
5
|
+
setFocussedOptionIndex
|
|
6
|
+
}) {
|
|
8
7
|
return useCallback(highestVisibleIndex => {
|
|
9
8
|
if (!options[highestVisibleIndex].disabled) {
|
|
10
9
|
setFocussedOptionIndex(highestVisibleIndex);
|
|
@@ -2,13 +2,12 @@ import { useCallback } from 'react';
|
|
|
2
2
|
import { isOptionHidden } from '../is-option-hidden.js';
|
|
3
3
|
import { useHighlightLastOptionOnNextPage } from './use-highlight-last-option-on-next-page.js';
|
|
4
4
|
import { useHighlightLastVisibleOption } from './use-highlight-last-visible-option.js';
|
|
5
|
-
export function usePageDown(
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
} = _ref;
|
|
5
|
+
export function usePageDown({
|
|
6
|
+
options,
|
|
7
|
+
focussedOptionIndex,
|
|
8
|
+
setFocussedOptionIndex,
|
|
9
|
+
listBoxRef
|
|
10
|
+
}) {
|
|
12
11
|
const highlightLastVisibleOption = useHighlightLastVisibleOption({
|
|
13
12
|
options,
|
|
14
13
|
focussedOptionIndex,
|
|
@@ -2,13 +2,12 @@ import { useCallback } from 'react';
|
|
|
2
2
|
import { isOptionHidden } from '../is-option-hidden.js';
|
|
3
3
|
import { useHighlightFirstOptionOnPreviousPage } from './use-highlight-first-option-on-previous-page.js';
|
|
4
4
|
import { useHighlightFirstVisibleOption } from './use-highlight-first-visible-option.js';
|
|
5
|
-
export function usePageUp(
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
} = _ref;
|
|
5
|
+
export function usePageUp({
|
|
6
|
+
options,
|
|
7
|
+
listBoxRef,
|
|
8
|
+
focussedOptionIndex,
|
|
9
|
+
setFocussedOptionIndex
|
|
10
|
+
}) {
|
|
12
11
|
const highlightFirstVisibleOption = useHighlightFirstVisibleOption({
|
|
13
12
|
options,
|
|
14
13
|
focussedOptionIndex,
|