@dhis2-ui/select 10.16.1 → 10.16.3-alpha.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/build/cjs/select/select.js +5 -2
- package/build/cjs/simple-single-select/use-handle-key-press/use-handle-key-press-on-filter-input.js +2 -2
- package/build/es/select/select.js +5 -2
- package/build/es/simple-single-select/use-handle-key-press/use-handle-key-press-on-filter-input.js +2 -2
- package/package.json +17 -16
- package/src/index.js +9 -0
- package/src/locales/ar/translations.json +7 -0
- package/src/locales/ar_IQ/translations.json +7 -0
- package/src/locales/ckb/translations.json +7 -0
- package/src/locales/cs/translations.json +7 -0
- package/src/locales/da/translations.json +7 -0
- package/src/locales/en/translations.json +11 -0
- package/src/locales/en_US/translations.json +9 -0
- package/src/locales/es/translations.json +7 -0
- package/src/locales/es_419/translations.json +7 -0
- package/src/locales/fr/translations.json +7 -0
- package/src/locales/hi_IN/translations.json +7 -0
- package/src/locales/id/translations.json +7 -0
- package/src/locales/index.js +80 -0
- package/src/locales/km/translations.json +7 -0
- package/src/locales/lo/translations.json +7 -0
- package/src/locales/my/translations.json +7 -0
- package/src/locales/nb/translations.json +7 -0
- package/src/locales/nl/translations.json +7 -0
- package/src/locales/prs/translations.json +7 -0
- package/src/locales/ps/translations.json +7 -0
- package/src/locales/pt/translations.json +7 -0
- package/src/locales/pt_BR/translations.json +7 -0
- package/src/locales/ru/translations.json +7 -0
- package/src/locales/sv/translations.json +7 -0
- package/src/locales/tet/translations.json +7 -0
- package/src/locales/tg/translations.json +7 -0
- package/src/locales/uk/translations.json +7 -0
- package/src/locales/ur/translations.json +7 -0
- package/src/locales/uz_Latn/translations.json +7 -0
- package/src/locales/uz_UZ_Cyrl/translations.json +7 -0
- package/src/locales/uz_UZ_Latn/translations.json +7 -0
- package/src/locales/vi/translations.json +7 -0
- package/src/locales/zh/translations.json +9 -0
- package/src/locales/zh_CN/translations.json +7 -0
- package/src/multi-select/__tests__/multi-select.test.js +23 -0
- package/src/multi-select/__tests__/selection-list.test.js +102 -0
- package/src/multi-select/features/accepts_blur_cb/index.js +14 -0
- package/src/multi-select/features/accepts_blur_cb.feature +8 -0
- package/src/multi-select/features/accepts_focus_cb/index.js +14 -0
- package/src/multi-select/features/accepts_focus_cb.feature +6 -0
- package/src/multi-select/features/accepts_initial_focus/index.js +5 -0
- package/src/multi-select/features/accepts_initial_focus.feature +5 -0
- package/src/multi-select/features/accepts_loading/index.js +22 -0
- package/src/multi-select/features/accepts_loading.feature +14 -0
- package/src/multi-select/features/accepts_max_height/index.js +31 -0
- package/src/multi-select/features/accepts_max_height.feature +11 -0
- package/src/multi-select/features/accepts_placeholder/index.js +25 -0
- package/src/multi-select/features/accepts_placeholder.feature +10 -0
- package/src/multi-select/features/accepts_prefix/index.js +19 -0
- package/src/multi-select/features/accepts_prefix.feature +10 -0
- package/src/multi-select/features/allows_invalid_options/index.js +27 -0
- package/src/multi-select/features/allows_invalid_options.feature +12 -0
- package/src/multi-select/features/allows_selecting/index.js +81 -0
- package/src/multi-select/features/allows_selecting.feature +44 -0
- package/src/multi-select/features/can_be_cleared/index.js +22 -0
- package/src/multi-select/features/can_be_cleared.feature +6 -0
- package/src/multi-select/features/can_be_disabled/index.js +36 -0
- package/src/multi-select/features/can_be_disabled.feature +32 -0
- package/src/multi-select/features/can_be_empty/index.js +28 -0
- package/src/multi-select/features/can_be_empty.feature +16 -0
- package/src/multi-select/features/can_be_filtered/index.js +23 -0
- package/src/multi-select/features/can_be_filtered.feature +14 -0
- package/src/multi-select/features/can_be_opened_and_closed/index.js +32 -0
- package/src/multi-select/features/can_be_opened_and_closed.feature +41 -0
- package/src/multi-select/features/common/index.js +49 -0
- package/src/multi-select/features/duplicate_option_values/index.js +21 -0
- package/src/multi-select/features/duplicate_option_values.feature +7 -0
- package/src/multi-select/features/menu_width_matches_input/index.js +53 -0
- package/src/multi-select/features/menu_width_matches_input.feature +11 -0
- package/src/multi-select/features/position/index.js +160 -0
- package/src/multi-select/features/position.feature +46 -0
- package/src/multi-select/features/shows_selections/index.js +18 -0
- package/src/multi-select/features/shows_selections.feature +9 -0
- package/src/multi-select/filterable-menu.js +43 -0
- package/src/multi-select/index.js +1 -0
- package/src/multi-select/input.js +129 -0
- package/src/multi-select/menu.js +91 -0
- package/src/multi-select/multi-select.e2e.stories.js +407 -0
- package/src/multi-select/multi-select.js +148 -0
- package/src/multi-select/multi-select.prod.stories.js +408 -0
- package/src/multi-select/selection-list.js +79 -0
- package/src/multi-select-field/__tests__/multi-select-field.test.js +29 -0
- package/src/multi-select-field/features/accepts_help_text/index.js +9 -0
- package/src/multi-select-field/features/accepts_help_text.feature +5 -0
- package/src/multi-select-field/features/accepts_label/index.js +9 -0
- package/src/multi-select-field/features/accepts_label.feature +5 -0
- package/src/multi-select-field/features/accepts_validation_text/index.js +9 -0
- package/src/multi-select-field/features/accepts_validation_text.feature +5 -0
- package/src/multi-select-field/features/can_be_required/index.js +11 -0
- package/src/multi-select-field/features/can_be_required.feature +5 -0
- package/src/multi-select-field/features/has_default_clear_text/index.js +16 -0
- package/src/multi-select-field/features/has_default_clear_text.feature +6 -0
- package/src/multi-select-field/features/has_default_empty_text/index.js +13 -0
- package/src/multi-select-field/features/has_default_empty_text.feature +6 -0
- package/src/multi-select-field/features/has_default_filter_nomatch_text/index.js +17 -0
- package/src/multi-select-field/features/has_default_filter_nomatch_text.feature +7 -0
- package/src/multi-select-field/features/has_default_filter_placeholder/index.js +15 -0
- package/src/multi-select-field/features/has_default_filter_placeholder.feature +6 -0
- package/src/multi-select-field/features/has_default_loading_text/index.js +13 -0
- package/src/multi-select-field/features/has_default_loading_text.feature +6 -0
- package/src/multi-select-field/index.js +1 -0
- package/src/multi-select-field/multi-select-field.e2e.stories.js +45 -0
- package/src/multi-select-field/multi-select-field.js +178 -0
- package/src/multi-select-field/multi-select-field.prod.stories.js +137 -0
- package/src/multi-select-option/index.js +1 -0
- package/src/multi-select-option/multi-select-option.js +70 -0
- package/src/select/__tests__/select.test.js +31 -0
- package/src/select/debounce/debounce.js +30 -0
- package/src/select/debounce/debounce.spec.js +35 -0
- package/src/select/empty.js +28 -0
- package/src/select/filter-input.js +42 -0
- package/src/select/filterable-menu.js +106 -0
- package/src/select/index.js +14 -0
- package/src/select/input-clear-button.js +66 -0
- package/src/select/input-placeholder.js +30 -0
- package/src/select/input-prefix.js +32 -0
- package/src/select/input-wrapper.js +114 -0
- package/src/select/loading.js +33 -0
- package/src/select/menu-wrapper.js +52 -0
- package/src/select/no-match.js +28 -0
- package/src/select/option-helpers.js +34 -0
- package/src/select/select.js +256 -0
- package/src/simple-single-select/__stories__/DefaultPosition.js +37 -0
- package/src/simple-single-select/__stories__/Dense.js +17 -0
- package/src/simple-single-select/__stories__/Empty.js +15 -0
- package/src/simple-single-select/__stories__/EmptyWithEmptyNode.js +27 -0
- package/src/simple-single-select/__stories__/EmptyWithEmptyText.js +16 -0
- package/src/simple-single-select/__stories__/FlippedPosition.js +36 -0
- package/src/simple-single-select/__stories__/InfiniteLoading.js +65 -0
- package/src/simple-single-select/__stories__/Loading.js +15 -0
- package/src/simple-single-select/__stories__/ShiftedIntoView.js +35 -0
- package/src/simple-single-select/__stories__/WithClearButton.js +26 -0
- package/src/simple-single-select/__stories__/WithCustomLowMaxHeight.js +17 -0
- package/src/simple-single-select/__stories__/WithCustomOptions.js +78 -0
- package/src/simple-single-select/__stories__/WithDisabledOption.js +25 -0
- package/src/simple-single-select/__stories__/WithFilterField.js +30 -0
- package/src/simple-single-select/__stories__/WithInitialFocus.js +29 -0
- package/src/simple-single-select/__stories__/WithManyOptions.js +19 -0
- package/src/simple-single-select/__stories__/WithMultipleSelectsAndScrollableParent.js +65 -0
- package/src/simple-single-select/__stories__/WithNoMatchText.js +25 -0
- package/src/simple-single-select/__stories__/WithOnBlur.js +22 -0
- package/src/simple-single-select/__stories__/WithOnFocus.js +22 -0
- package/src/simple-single-select/__stories__/WithOptionsAndDisabled.js +17 -0
- package/src/simple-single-select/__stories__/WithOptionsAndLoading.js +23 -0
- package/src/simple-single-select/__stories__/WithOptionsAndLoadingText.js +24 -0
- package/src/simple-single-select/__stories__/WithPlaceholder.js +18 -0
- package/src/simple-single-select/__stories__/WithPlaceholderAndSelection.js +20 -0
- package/src/simple-single-select/__stories__/WithPrefix.js +17 -0
- package/src/simple-single-select/__stories__/WithPrefixAndSelection.js +20 -0
- package/src/simple-single-select/__stories__/WithRTL.js +29 -0
- package/src/simple-single-select/__stories__/WithScrollingParent.js +51 -0
- package/src/simple-single-select/__stories__/WithSelection.js +19 -0
- package/src/simple-single-select/__stories__/WithSelectionAndDisabled.js +20 -0
- package/src/simple-single-select/__stories__/WithServerSideFilteringDemo.js +245 -0
- package/src/simple-single-select/__stories__/WithSimpleFilteringDemo.js +50 -0
- package/src/simple-single-select/__stories__/WithoutOptionsAndLoading.js +16 -0
- package/src/simple-single-select/__stories__/WithoutSelection.js +17 -0
- package/src/simple-single-select/__stories__/options.js +96 -0
- package/src/simple-single-select/__stories__/simple-single-select-server-side-filtering/CustomDataProvider.js +70 -0
- package/src/simple-single-select/__stories__/simple-single-select-server-side-filtering/dataElements.js +4271 -0
- package/src/simple-single-select/__stories__/simple-single-select-server-side-filtering/index.js +1 -0
- package/src/simple-single-select/features/keyboard-interactions.test.e2e.js +581 -0
- package/src/simple-single-select/features/menu-positioning.test.e2e.js +187 -0
- package/src/simple-single-select/index.js +2 -0
- package/src/simple-single-select/is-option-hidden.js +21 -0
- package/src/simple-single-select/menu/empty.js +27 -0
- package/src/simple-single-select/menu/filter.js +61 -0
- package/src/simple-single-select/menu/index.js +1 -0
- package/src/simple-single-select/menu/loading.js +38 -0
- package/src/simple-single-select/menu/menu.js +171 -0
- package/src/simple-single-select/menu/no-match.js +28 -0
- package/src/simple-single-select/menu/option.js +161 -0
- package/src/simple-single-select/menu/options-list.js +107 -0
- package/src/simple-single-select/selected-value/clear-button.js +71 -0
- package/src/simple-single-select/selected-value/container.js +146 -0
- package/src/simple-single-select/selected-value/index.js +1 -0
- package/src/simple-single-select/selected-value/placeholder.js +24 -0
- package/src/simple-single-select/selected-value/prefix.js +26 -0
- package/src/simple-single-select/selected-value/selected-value.js +174 -0
- package/src/simple-single-select/shared-prop-types.js +8 -0
- package/src/simple-single-select/simple-single-select.e2e.stories.js +216 -0
- package/src/simple-single-select/simple-single-select.js +389 -0
- package/src/simple-single-select/simple-single-select.prod.stories.js +41 -0
- package/src/simple-single-select/simple-single-select.test.js +1136 -0
- package/src/simple-single-select/use-handle-key-press/index.js +2 -0
- package/src/simple-single-select/use-handle-key-press/use-focus-option.js +24 -0
- package/src/simple-single-select/use-handle-key-press/use-handle-key-press-on-combobox.js +259 -0
- package/src/simple-single-select/use-handle-key-press/use-handle-key-press-on-filter-input.js +147 -0
- package/src/simple-single-select/use-handle-key-press/use-handle-typing.js +79 -0
- package/src/simple-single-select/use-handle-key-press/use-highlight-first-option-on-previous-page.js +62 -0
- package/src/simple-single-select/use-handle-key-press/use-highlight-first-visible-option.js +38 -0
- package/src/simple-single-select/use-handle-key-press/use-highlight-last-option-on-next-page.js +60 -0
- package/src/simple-single-select/use-handle-key-press/use-highlight-last-visible-option.js +52 -0
- package/src/simple-single-select/use-handle-key-press/use-page-down.js +50 -0
- package/src/simple-single-select/use-handle-key-press/use-page-up.js +50 -0
- package/src/simple-single-select/use-handle-key-press/utils.js +23 -0
- package/src/simple-single-select-field/index.js +1 -0
- package/src/simple-single-select-field/simple-single-select-field.js +198 -0
- package/src/simple-single-select-field/simple-single-select-field.prod.stories.js +188 -0
- package/src/simple-single-select-field/simple-single-select-field.test.js +144 -0
- package/src/single-select/__tests__/selection.test.js +102 -0
- package/src/single-select/__tests__/single-select.test.js +23 -0
- package/src/single-select/features/accepts_blur_cb/index.js +14 -0
- package/src/single-select/features/accepts_blur_cb.feature +8 -0
- package/src/single-select/features/accepts_focus_cb/index.js +14 -0
- package/src/single-select/features/accepts_focus_cb.feature +6 -0
- package/src/single-select/features/accepts_initial_focus/index.js +5 -0
- package/src/single-select/features/accepts_initial_focus.feature +5 -0
- package/src/single-select/features/accepts_loading/index.js +22 -0
- package/src/single-select/features/accepts_loading.feature +14 -0
- package/src/single-select/features/accepts_max_height/index.js +31 -0
- package/src/single-select/features/accepts_max_height.feature +11 -0
- package/src/single-select/features/accepts_placeholder/index.js +25 -0
- package/src/single-select/features/accepts_placeholder.feature +10 -0
- package/src/single-select/features/accepts_prefix/index.js +19 -0
- package/src/single-select/features/accepts_prefix.feature +10 -0
- package/src/single-select/features/allows_invalid_options/index.js +28 -0
- package/src/single-select/features/allows_invalid_options.feature +12 -0
- package/src/single-select/features/allows_selecting/index.js +38 -0
- package/src/single-select/features/allows_selecting.feature +21 -0
- package/src/single-select/features/can_be_cleared/index.js +22 -0
- package/src/single-select/features/can_be_cleared.feature +6 -0
- package/src/single-select/features/can_be_disabled/index.js +39 -0
- package/src/single-select/features/can_be_disabled.feature +32 -0
- package/src/single-select/features/can_be_empty/index.js +28 -0
- package/src/single-select/features/can_be_empty.feature +16 -0
- package/src/single-select/features/can_be_filtered/index.js +23 -0
- package/src/single-select/features/can_be_filtered.feature +14 -0
- package/src/single-select/features/can_be_opened_and_closed/index.js +32 -0
- package/src/single-select/features/can_be_opened_and_closed.feature +41 -0
- package/src/single-select/features/common/index.js +44 -0
- package/src/single-select/features/duplicate_option_values/index.js +26 -0
- package/src/single-select/features/duplicate_option_values.feature +7 -0
- package/src/single-select/features/menu_width_matches_input/index.js +53 -0
- package/src/single-select/features/menu_width_matches_input.feature +11 -0
- package/src/single-select/features/position/index.js +111 -0
- package/src/single-select/features/position.feature +26 -0
- package/src/single-select/features/shows_selections/index.js +9 -0
- package/src/single-select/features/shows_selections.feature +5 -0
- package/src/single-select/filterable-menu.js +41 -0
- package/src/single-select/index.js +1 -0
- package/src/single-select/input.js +101 -0
- package/src/single-select/menu.js +75 -0
- package/src/single-select/selection.js +60 -0
- package/src/single-select/single-select.e2e.stories.js +376 -0
- package/src/single-select/single-select.js +146 -0
- package/src/single-select/single-select.prod.stories.js +358 -0
- package/src/single-select-field/__tests__/single-select-field.test.js +29 -0
- package/src/single-select-field/features/accepts_help_text/index.js +9 -0
- package/src/single-select-field/features/accepts_help_text.feature +5 -0
- package/src/single-select-field/features/accepts_label/index.js +9 -0
- package/src/single-select-field/features/accepts_label.feature +5 -0
- package/src/single-select-field/features/accepts_validation_text/index.js +9 -0
- package/src/single-select-field/features/accepts_validation_text.feature +5 -0
- package/src/single-select-field/features/can_be_required/index.js +11 -0
- package/src/single-select-field/features/can_be_required.feature +5 -0
- package/src/single-select-field/features/has_default_clear_text/index.js +16 -0
- package/src/single-select-field/features/has_default_clear_text.feature +6 -0
- package/src/single-select-field/features/has_default_empty_text/index.js +13 -0
- package/src/single-select-field/features/has_default_empty_text.feature +6 -0
- package/src/single-select-field/features/has_default_filter_nomatch_text/index.js +17 -0
- package/src/single-select-field/features/has_default_filter_nomatch_text.feature +7 -0
- package/src/single-select-field/features/has_default_filter_placeholder/index.js +15 -0
- package/src/single-select-field/features/has_default_filter_placeholder.feature +6 -0
- package/src/single-select-field/features/has_default_loading_text/index.js +13 -0
- package/src/single-select-field/features/has_default_loading_text.feature +6 -0
- package/src/single-select-field/index.js +1 -0
- package/src/single-select-field/single-select-field.e2e.stories.js +45 -0
- package/src/single-select-field/single-select-field.js +178 -0
- package/src/single-select-field/single-select-field.prod.stories.js +146 -0
- package/src/single-select-option/index.js +1 -0
- package/src/single-select-option/single-select-option.js +84 -0
|
@@ -0,0 +1,408 @@
|
|
|
1
|
+
import { sharedPropTypes } from '@dhis2/ui-constants'
|
|
2
|
+
import PropTypes from 'prop-types'
|
|
3
|
+
import React, { useEffect } from 'react'
|
|
4
|
+
import { MultiSelectOption } from '../index.js'
|
|
5
|
+
import { MultiSelect } from './index.js'
|
|
6
|
+
|
|
7
|
+
const description = `
|
|
8
|
+
Multiple selection allows the user to select more than one option from the list. Checkboxes are used to highlight the possibility of making more than one selection. Selected options are displayed as chips inside the input. Make sure to communicate clearly to the user if there is a limit to the number of selectable elements.
|
|
9
|
+
|
|
10
|
+
Use multiple selection wherever the user needs to make more than one selection. If the multiple selection is complex, requires a defined order or needs to made from different groups, consider using a transfer component instead.
|
|
11
|
+
|
|
12
|
+
Read more about using \`Select\` components at [Design System: Select](https://github.com/dhis2/design-system/blob/master/molecules/select.md).
|
|
13
|
+
|
|
14
|
+
\`\`\`js
|
|
15
|
+
import { MultiSelect, MultiSelectOption } from '@dhis2/ui'
|
|
16
|
+
\`\`\`
|
|
17
|
+
|
|
18
|
+
_**Note:** Due to demo limitations on this page, only one representative example is rendered here. For more (props-interactive) examples, see individual stories in the 'Canvas' tab._
|
|
19
|
+
`
|
|
20
|
+
|
|
21
|
+
const eventHandler = (handlerName) => (payload, event) => {
|
|
22
|
+
console.log(`${handlerName} payload`, payload)
|
|
23
|
+
console.log(`${handlerName} event`, event)
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
const onChange = eventHandler('onChange')
|
|
27
|
+
const onFocus = eventHandler('onFocus')
|
|
28
|
+
const onBlur = eventHandler('onBlur')
|
|
29
|
+
|
|
30
|
+
const CustomMultiSelectOption = ({ label, onClick }) => (
|
|
31
|
+
<div onClick={(e) => onClick({}, e)}>{label}</div>
|
|
32
|
+
)
|
|
33
|
+
|
|
34
|
+
CustomMultiSelectOption.propTypes = {
|
|
35
|
+
label: PropTypes.string,
|
|
36
|
+
onClick: PropTypes.func,
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
const requiredIfArgType = {
|
|
40
|
+
table: { type: { summary: 'string' }, control: { type: 'string' } },
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export default {
|
|
44
|
+
title: 'Multi Select',
|
|
45
|
+
component: MultiSelect,
|
|
46
|
+
parameters: {
|
|
47
|
+
docs: {
|
|
48
|
+
description: { component: description },
|
|
49
|
+
// Disable stories in docs page by default, then use one representative example
|
|
50
|
+
disable: true,
|
|
51
|
+
// Use iframe to keep dropdown menu inside story for docs page
|
|
52
|
+
inlineStories: false,
|
|
53
|
+
iframeHeight: '300px',
|
|
54
|
+
},
|
|
55
|
+
},
|
|
56
|
+
// Use 'onChange' as a default arg, otherwise components throw an error when interacted with
|
|
57
|
+
// (Maybe this could be handled in the component - as a required prop)
|
|
58
|
+
args: { className: 'select', onChange },
|
|
59
|
+
argTypes: {
|
|
60
|
+
valid: { ...sharedPropTypes.statusArgType },
|
|
61
|
+
warning: { ...sharedPropTypes.statusArgType },
|
|
62
|
+
error: { ...sharedPropTypes.statusArgType },
|
|
63
|
+
clearText: { ...requiredIfArgType },
|
|
64
|
+
noMatchText: { ...requiredIfArgType },
|
|
65
|
+
},
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
const WithOptionsTemplate = (args) => (
|
|
69
|
+
<MultiSelect {...args}>
|
|
70
|
+
<MultiSelectOption value="1" label="option one" />
|
|
71
|
+
<MultiSelectOption value="2" label="option two" />
|
|
72
|
+
<MultiSelectOption value="3" label="option three" />
|
|
73
|
+
</MultiSelect>
|
|
74
|
+
)
|
|
75
|
+
|
|
76
|
+
const EmptyTemplate = (args) => <MultiSelect {...args} />
|
|
77
|
+
|
|
78
|
+
export const WithOptionsAndOnChange = WithOptionsTemplate.bind({})
|
|
79
|
+
WithOptionsAndOnChange.storyName = 'With options and onChange'
|
|
80
|
+
|
|
81
|
+
export const WithOptionsAndASelection = WithOptionsTemplate.bind({})
|
|
82
|
+
WithOptionsAndASelection.args = { selected: ['1'] }
|
|
83
|
+
// Enable this story as the primary for the docs page
|
|
84
|
+
WithOptionsAndASelection.parameters = { docs: { disable: false } }
|
|
85
|
+
WithOptionsAndASelection.storyName = 'With options and a selection'
|
|
86
|
+
|
|
87
|
+
export const WithOnFocus = WithOptionsTemplate.bind({})
|
|
88
|
+
WithOnFocus.args = { onFocus }
|
|
89
|
+
WithOnFocus.storyName = 'With on focus'
|
|
90
|
+
|
|
91
|
+
export const WithOnBlur = WithOptionsTemplate.bind({})
|
|
92
|
+
WithOnBlur.args = { onBlur }
|
|
93
|
+
WithOnBlur.storyName = 'With onBlur'
|
|
94
|
+
|
|
95
|
+
export const WithCustomOptionsAndOnChange = (args) => (
|
|
96
|
+
<MultiSelect {...args}>
|
|
97
|
+
<CustomMultiSelectOption value="1" label="option one" />
|
|
98
|
+
<CustomMultiSelectOption value="2" label="option two" />
|
|
99
|
+
<CustomMultiSelectOption value="3" label="option three" />
|
|
100
|
+
</MultiSelect>
|
|
101
|
+
)
|
|
102
|
+
WithCustomOptionsAndOnChange.storyName = 'With custom options and onChange'
|
|
103
|
+
|
|
104
|
+
export const WithInvalidOptions = (args) => (
|
|
105
|
+
<MultiSelect {...args}>
|
|
106
|
+
<div>invalid one</div>
|
|
107
|
+
<MultiSelectOption value="1" label="option one" />
|
|
108
|
+
<div>invalid two</div>
|
|
109
|
+
<MultiSelectOption value="2" label="option two" />
|
|
110
|
+
<div>invalid three</div>
|
|
111
|
+
<MultiSelectOption value="3" label="option three" />
|
|
112
|
+
{null}
|
|
113
|
+
{undefined}
|
|
114
|
+
{false}
|
|
115
|
+
</MultiSelect>
|
|
116
|
+
)
|
|
117
|
+
|
|
118
|
+
export const WithInvalidFilterableOptions = (args) => (
|
|
119
|
+
<MultiSelect {...args}>
|
|
120
|
+
<div>invalid one</div>
|
|
121
|
+
<MultiSelectOption value="1" label="option one" />
|
|
122
|
+
<div>invalid two</div>
|
|
123
|
+
<MultiSelectOption value="2" label="option two" />
|
|
124
|
+
<div>invalid three</div>
|
|
125
|
+
<MultiSelectOption value="3" label="option three" />
|
|
126
|
+
</MultiSelect>
|
|
127
|
+
)
|
|
128
|
+
WithInvalidFilterableOptions.args = {
|
|
129
|
+
filterable: true,
|
|
130
|
+
noMatchText: 'No match found',
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
export const WithInitialFocus = EmptyTemplate.bind({})
|
|
134
|
+
WithInitialFocus.args = { initialFocus: true }
|
|
135
|
+
WithInitialFocus.parameters = { docs: { disable: true } }
|
|
136
|
+
WithInitialFocus.storyName = 'With initial focus'
|
|
137
|
+
|
|
138
|
+
export const Dense = WithOptionsTemplate.bind({})
|
|
139
|
+
Dense.args = { dense: true, placeholder: 'Dense sized multi select' }
|
|
140
|
+
Dense.storyName = 'Dense'
|
|
141
|
+
|
|
142
|
+
export const DenseWithSelections = WithOptionsTemplate.bind({})
|
|
143
|
+
DenseWithSelections.args = { dense: true, selected: ['1', '2'] }
|
|
144
|
+
DenseWithSelections.storyName = 'Dense with selections'
|
|
145
|
+
|
|
146
|
+
export const Empty = EmptyTemplate.bind({})
|
|
147
|
+
|
|
148
|
+
export const EmptyWithEmptyText = EmptyTemplate.bind({})
|
|
149
|
+
EmptyWithEmptyText.args = { empty: 'Custom empty text' }
|
|
150
|
+
|
|
151
|
+
export const EmptyWithEmptyComponent = EmptyTemplate.bind({})
|
|
152
|
+
EmptyWithEmptyComponent.args = {
|
|
153
|
+
empty: <div className="custom-empty">Custom empty component</div>,
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
export const WithOptionsAndLoading = WithOptionsTemplate.bind({})
|
|
157
|
+
WithOptionsAndLoading.args = { loading: true }
|
|
158
|
+
|
|
159
|
+
export const WithOptionsLoadingAndLoadingText = WithOptionsTemplate.bind({})
|
|
160
|
+
WithOptionsLoadingAndLoadingText.args = {
|
|
161
|
+
...WithOptionsAndLoading.args,
|
|
162
|
+
loadingText: 'Loading options',
|
|
163
|
+
}
|
|
164
|
+
WithOptionsLoadingAndLoadingText.storyName =
|
|
165
|
+
'With options, loading and loading text'
|
|
166
|
+
|
|
167
|
+
export const WithMoreThanTenOptions = (args) => (
|
|
168
|
+
<MultiSelect {...args}>
|
|
169
|
+
<MultiSelectOption value="1" label="option one" />
|
|
170
|
+
<MultiSelectOption value="2" label="option two" />
|
|
171
|
+
<MultiSelectOption value="3" label="option three" />
|
|
172
|
+
<MultiSelectOption value="4" label="option four" />
|
|
173
|
+
<MultiSelectOption value="5" label="option five" />
|
|
174
|
+
<MultiSelectOption value="6" label="option six" />
|
|
175
|
+
<MultiSelectOption value="7" label="option seven" />
|
|
176
|
+
<MultiSelectOption value="8" label="option eight" />
|
|
177
|
+
<MultiSelectOption value="9" label="option nine" />
|
|
178
|
+
<MultiSelectOption value="10" label="option ten" />
|
|
179
|
+
<MultiSelectOption value="11" label="option eleven" />
|
|
180
|
+
<MultiSelectOption value="12" label="option twelve" />
|
|
181
|
+
</MultiSelect>
|
|
182
|
+
)
|
|
183
|
+
|
|
184
|
+
export const WithMoreThanThreeOptionsAndA100PxMaxHeight = (args) => (
|
|
185
|
+
<MultiSelect {...args}>
|
|
186
|
+
<MultiSelectOption value="1" label="option one" />
|
|
187
|
+
<MultiSelectOption value="2" label="option two" />
|
|
188
|
+
<MultiSelectOption value="3" label="option three" />
|
|
189
|
+
<MultiSelectOption value="4" label="option four" />
|
|
190
|
+
<MultiSelectOption value="5" label="option five" />
|
|
191
|
+
<MultiSelectOption value="6" label="option six" />
|
|
192
|
+
<MultiSelectOption value="7" label="option seven" />
|
|
193
|
+
<MultiSelectOption value="8" label="option eight" />
|
|
194
|
+
<MultiSelectOption value="9" label="option nine" />
|
|
195
|
+
<MultiSelectOption value="10" label="option ten" />
|
|
196
|
+
<MultiSelectOption value="11" label="option eleven" />
|
|
197
|
+
<MultiSelectOption value="12" label="option twelve" />
|
|
198
|
+
</MultiSelect>
|
|
199
|
+
)
|
|
200
|
+
WithMoreThanThreeOptionsAndA100PxMaxHeight.args = { maxHeight: '100px' }
|
|
201
|
+
WithMoreThanThreeOptionsAndA100PxMaxHeight.storyName =
|
|
202
|
+
'With more than three options and a 100px max-height'
|
|
203
|
+
|
|
204
|
+
export const WithOptionsAndDisabled = WithOptionsTemplate.bind({})
|
|
205
|
+
WithOptionsAndDisabled.args = { disabled: true }
|
|
206
|
+
WithOptionsAndDisabled.storyName = 'With options and disabled'
|
|
207
|
+
|
|
208
|
+
export const WithOptionsASelectionAndDisabled = WithOptionsTemplate.bind({})
|
|
209
|
+
WithOptionsASelectionAndDisabled.args = {
|
|
210
|
+
...WithOptionsAndDisabled.args,
|
|
211
|
+
...WithOptionsAndASelection.args,
|
|
212
|
+
}
|
|
213
|
+
WithOptionsASelectionAndDisabled.storyName =
|
|
214
|
+
'With options, a selection and disabled'
|
|
215
|
+
|
|
216
|
+
export const WithPrefix = WithOptionsTemplate.bind({})
|
|
217
|
+
WithPrefix.args = { prefix: 'Prefix text' }
|
|
218
|
+
|
|
219
|
+
export const WithPrefixAndSelection = WithOptionsTemplate.bind({})
|
|
220
|
+
WithPrefixAndSelection.args = {
|
|
221
|
+
...WithPrefix.args,
|
|
222
|
+
...WithOptionsAndASelection.args,
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
export const WithPlaceholder = WithOptionsTemplate.bind({})
|
|
226
|
+
WithPlaceholder.args = { placeholder: 'Placeholder text' }
|
|
227
|
+
|
|
228
|
+
export const WithPlaceholderAndSelection = WithOptionsTemplate.bind({})
|
|
229
|
+
WithPlaceholderAndSelection.args = {
|
|
230
|
+
...WithPlaceholder.args,
|
|
231
|
+
...WithOptionsAndASelection.args,
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
export const WithDisabledOptionAndOnChange = (args) => (
|
|
235
|
+
<MultiSelect {...args}>
|
|
236
|
+
<MultiSelectOption value="1" label="option one" />
|
|
237
|
+
<MultiSelectOption value="2" label="option two" />
|
|
238
|
+
<MultiSelectOption value="3" label="option three" />
|
|
239
|
+
<MultiSelectOption value="4" label="disabled option" disabled />
|
|
240
|
+
</MultiSelect>
|
|
241
|
+
)
|
|
242
|
+
WithDisabledOptionAndOnChange.storyName = 'With disabled option and onChange'
|
|
243
|
+
|
|
244
|
+
export const WithOptionsAndMultipleSelections = WithOptionsTemplate.bind({})
|
|
245
|
+
WithOptionsAndMultipleSelections.args = { selected: ['1', '2'] }
|
|
246
|
+
|
|
247
|
+
export const WithMultipleSelectionsWrapped = () => {
|
|
248
|
+
const [selected, setSelected] = React.useState(['1', '2', '4', '6'])
|
|
249
|
+
return (
|
|
250
|
+
<div style={{ maxWidth: 300 }}>
|
|
251
|
+
<MultiSelect
|
|
252
|
+
className="select"
|
|
253
|
+
selected={selected}
|
|
254
|
+
onChange={({ selected }) => {
|
|
255
|
+
console.log({ selected })
|
|
256
|
+
setSelected(selected)
|
|
257
|
+
}}
|
|
258
|
+
inputMaxHeight={'auto'}
|
|
259
|
+
>
|
|
260
|
+
<MultiSelectOption value="1" label="option one" />
|
|
261
|
+
<MultiSelectOption value="2" label="option two" />
|
|
262
|
+
<MultiSelectOption value="3" label="option three" />
|
|
263
|
+
<MultiSelectOption value="4" label="option four" />
|
|
264
|
+
<MultiSelectOption value="5" label="option five" />
|
|
265
|
+
<MultiSelectOption value="6" label="option six" />
|
|
266
|
+
<MultiSelectOption value="7" label="option seven" />
|
|
267
|
+
</MultiSelect>
|
|
268
|
+
</div>
|
|
269
|
+
)
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
export const WithClearButtonSelectionAndOnChange = WithOptionsTemplate.bind({})
|
|
273
|
+
WithClearButtonSelectionAndOnChange.args = {
|
|
274
|
+
...WithOptionsAndASelection.args,
|
|
275
|
+
clearable: true,
|
|
276
|
+
clearText: 'Clear',
|
|
277
|
+
}
|
|
278
|
+
WithClearButtonSelectionAndOnChange.storyName =
|
|
279
|
+
'With clear button, selection and onChange'
|
|
280
|
+
|
|
281
|
+
export const WithFilterField = WithOptionsTemplate.bind({})
|
|
282
|
+
WithFilterField.args = { ...WithInvalidFilterableOptions.args }
|
|
283
|
+
|
|
284
|
+
export const DefaultPosition = (args) => (
|
|
285
|
+
<>
|
|
286
|
+
<MultiSelect {...args}>
|
|
287
|
+
<MultiSelectOption value="1" label="option one" />
|
|
288
|
+
<MultiSelectOption value="2" label="option two" />
|
|
289
|
+
<MultiSelectOption value="3" label="option three" />
|
|
290
|
+
<MultiSelectOption value="4" label="option four" />
|
|
291
|
+
<MultiSelectOption value="5" label="option five" />
|
|
292
|
+
<MultiSelectOption value="6" label="option six" />
|
|
293
|
+
<MultiSelectOption value="7" label="option seven" />
|
|
294
|
+
<MultiSelectOption value="8" label="option eight" />
|
|
295
|
+
<MultiSelectOption value="9" label="option nine" />
|
|
296
|
+
<MultiSelectOption value="10" label="option ten" />
|
|
297
|
+
<MultiSelectOption value="11" label="option eleven" />
|
|
298
|
+
<MultiSelectOption value="12" label="option twelve" />
|
|
299
|
+
</MultiSelect>
|
|
300
|
+
<style jsx>{`
|
|
301
|
+
:global(#root) {
|
|
302
|
+
margin-bottom: 2000px;
|
|
303
|
+
}
|
|
304
|
+
`}</style>
|
|
305
|
+
</>
|
|
306
|
+
)
|
|
307
|
+
|
|
308
|
+
export const FlippedPosition = (args) => (
|
|
309
|
+
<>
|
|
310
|
+
<MultiSelect {...args}>
|
|
311
|
+
<MultiSelectOption value="1" label="option one" />
|
|
312
|
+
<MultiSelectOption value="2" label="option two" />
|
|
313
|
+
<MultiSelectOption value="3" label="option three" />
|
|
314
|
+
<MultiSelectOption value="4" label="option four" />
|
|
315
|
+
<MultiSelectOption value="5" label="option five" />
|
|
316
|
+
<MultiSelectOption value="6" label="option six" />
|
|
317
|
+
<MultiSelectOption value="7" label="option seven" />
|
|
318
|
+
<MultiSelectOption value="8" label="option eight" />
|
|
319
|
+
<MultiSelectOption value="9" label="option nine" />
|
|
320
|
+
<MultiSelectOption value="10" label="option ten" />
|
|
321
|
+
<MultiSelectOption value="11" label="option eleven" />
|
|
322
|
+
<MultiSelectOption value="12" label="option twelve" />
|
|
323
|
+
</MultiSelect>
|
|
324
|
+
<style jsx>{`
|
|
325
|
+
:global(html),
|
|
326
|
+
:global(body),
|
|
327
|
+
:global(#root) {
|
|
328
|
+
position: relative;
|
|
329
|
+
height: 500px;
|
|
330
|
+
max-height: 500px;
|
|
331
|
+
}
|
|
332
|
+
:global(#root) {
|
|
333
|
+
padding-top: 400px !important;
|
|
334
|
+
}
|
|
335
|
+
`}</style>
|
|
336
|
+
</>
|
|
337
|
+
)
|
|
338
|
+
|
|
339
|
+
export const ShiftedIntoView = (args) => (
|
|
340
|
+
<>
|
|
341
|
+
<MultiSelect {...args}>
|
|
342
|
+
<MultiSelectOption value="1" label="option one" />
|
|
343
|
+
<MultiSelectOption value="2" label="option two" />
|
|
344
|
+
<MultiSelectOption value="3" label="option three" />
|
|
345
|
+
<MultiSelectOption value="4" label="option four" />
|
|
346
|
+
<MultiSelectOption value="5" label="option five" />
|
|
347
|
+
<MultiSelectOption value="6" label="option six" />
|
|
348
|
+
<MultiSelectOption value="7" label="option seven" />
|
|
349
|
+
<MultiSelectOption value="8" label="option eight" />
|
|
350
|
+
<MultiSelectOption value="9" label="option nine" />
|
|
351
|
+
<MultiSelectOption value="10" label="option ten" />
|
|
352
|
+
<MultiSelectOption value="11" label="option eleven" />
|
|
353
|
+
<MultiSelectOption value="12" label="option twelve" />
|
|
354
|
+
</MultiSelect>
|
|
355
|
+
<style jsx>{`
|
|
356
|
+
:global(html),
|
|
357
|
+
:global(body),
|
|
358
|
+
:global(#root) {
|
|
359
|
+
position: relative;
|
|
360
|
+
height: 300px !important;
|
|
361
|
+
max-height: 300px;
|
|
362
|
+
}
|
|
363
|
+
:global(#root) {
|
|
364
|
+
padding-top: 130px !important;
|
|
365
|
+
}
|
|
366
|
+
`}</style>
|
|
367
|
+
</>
|
|
368
|
+
)
|
|
369
|
+
|
|
370
|
+
export const CollapseSelectionAfterThreshold = () => {
|
|
371
|
+
const [selected, setSelected] = React.useState(['1', '3', '5'])
|
|
372
|
+
return (
|
|
373
|
+
<div style={{ maxWidth: 400 }}>
|
|
374
|
+
<MultiSelect
|
|
375
|
+
className="select"
|
|
376
|
+
selected={selected}
|
|
377
|
+
onChange={({ selected }) => setSelected(selected)}
|
|
378
|
+
collapseSelectionAfter={2}
|
|
379
|
+
prefix="Prefix text"
|
|
380
|
+
clearable
|
|
381
|
+
clearText="Clear all"
|
|
382
|
+
>
|
|
383
|
+
<MultiSelectOption value="1" label="option one" />
|
|
384
|
+
<MultiSelectOption value="2" label="option two" />
|
|
385
|
+
<MultiSelectOption value="3" label="option three" />
|
|
386
|
+
<MultiSelectOption value="4" label="option four" />
|
|
387
|
+
<MultiSelectOption value="5" label="option five" />
|
|
388
|
+
<MultiSelectOption value="6" label="option six" />
|
|
389
|
+
</MultiSelect>
|
|
390
|
+
</div>
|
|
391
|
+
)
|
|
392
|
+
}
|
|
393
|
+
CollapseSelectionAfterThreshold.storyName = 'Collapse selection after threshold'
|
|
394
|
+
|
|
395
|
+
export const RTL = (args) => {
|
|
396
|
+
useEffect(() => {
|
|
397
|
+
document.body.dir = 'rtl'
|
|
398
|
+
return () => {
|
|
399
|
+
document.body.dir = 'ltr'
|
|
400
|
+
}
|
|
401
|
+
}, [])
|
|
402
|
+
return (
|
|
403
|
+
<div dir="rtl">
|
|
404
|
+
<WithOptionsTemplate {...args} />
|
|
405
|
+
</div>
|
|
406
|
+
)
|
|
407
|
+
}
|
|
408
|
+
RTL.args = { selected: ['1', '2'], prefix: 'RTL text' }
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import { Chip } from '@dhis2-ui/chip'
|
|
2
|
+
import PropTypes from 'prop-types'
|
|
3
|
+
import React from 'react'
|
|
4
|
+
import { removeOption, findOptionChild } from '../select/index.js'
|
|
5
|
+
|
|
6
|
+
const createRemoveHandler =
|
|
7
|
+
({ selected, onChange, value }) =>
|
|
8
|
+
(_, e) => {
|
|
9
|
+
const filtered = removeOption(value, selected)
|
|
10
|
+
const data = { selected: filtered }
|
|
11
|
+
|
|
12
|
+
onChange(data, e)
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
const SelectionList = ({ selected, onChange, disabled, options }) => (
|
|
16
|
+
<React.Fragment>
|
|
17
|
+
{selected.map((value) => {
|
|
18
|
+
const isProduction = process.env.NODE_ENV === 'production'
|
|
19
|
+
const selectedOption = findOptionChild(value, options)
|
|
20
|
+
|
|
21
|
+
if (!selectedOption) {
|
|
22
|
+
const message =
|
|
23
|
+
`There is no option with the value: "${value}". ` +
|
|
24
|
+
'Make sure that all the values passed to the selected ' +
|
|
25
|
+
'prop match the value of an existing option.'
|
|
26
|
+
|
|
27
|
+
if (isProduction) {
|
|
28
|
+
// Don't crash the app if in production
|
|
29
|
+
console.error(message)
|
|
30
|
+
} else {
|
|
31
|
+
// Throw error if not in production for maximum visibility
|
|
32
|
+
throw new Error(message)
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
const isDisabled = selectedOption
|
|
37
|
+
? // The chip should be disabled if the option or the select are disabled
|
|
38
|
+
selectedOption.props.disabled || disabled
|
|
39
|
+
: // If there is no selected option, just look at the select
|
|
40
|
+
disabled
|
|
41
|
+
// Use the selected value if we do not have a label
|
|
42
|
+
const label = selectedOption ? selectedOption.props.label : value
|
|
43
|
+
|
|
44
|
+
// Create an onRemove handler, but only if it's not disabled
|
|
45
|
+
const onRemove = isDisabled
|
|
46
|
+
? undefined
|
|
47
|
+
: createRemoveHandler({
|
|
48
|
+
selected,
|
|
49
|
+
onChange,
|
|
50
|
+
value,
|
|
51
|
+
})
|
|
52
|
+
|
|
53
|
+
return (
|
|
54
|
+
<Chip
|
|
55
|
+
key={value}
|
|
56
|
+
onRemove={onRemove}
|
|
57
|
+
disabled={isDisabled}
|
|
58
|
+
marginBottom={0}
|
|
59
|
+
marginLeft={0}
|
|
60
|
+
marginTop={0}
|
|
61
|
+
marginRight={0}
|
|
62
|
+
overflow
|
|
63
|
+
dense
|
|
64
|
+
>
|
|
65
|
+
{label}
|
|
66
|
+
</Chip>
|
|
67
|
+
)
|
|
68
|
+
})}
|
|
69
|
+
</React.Fragment>
|
|
70
|
+
)
|
|
71
|
+
|
|
72
|
+
SelectionList.propTypes = {
|
|
73
|
+
disabled: PropTypes.bool,
|
|
74
|
+
options: PropTypes.node,
|
|
75
|
+
selected: PropTypes.arrayOf(PropTypes.string),
|
|
76
|
+
onChange: PropTypes.func,
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
export { SelectionList }
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { render, fireEvent, screen } from '@testing-library/react'
|
|
2
|
+
import React from 'react'
|
|
3
|
+
import { MultiSelectField } from '../multi-select-field.js'
|
|
4
|
+
|
|
5
|
+
describe('<MultiSelect />', () => {
|
|
6
|
+
it('should call the onKeyDown callback when provided', () => {
|
|
7
|
+
const onKeyDown = jest.fn()
|
|
8
|
+
|
|
9
|
+
render(
|
|
10
|
+
<MultiSelectField
|
|
11
|
+
label="label"
|
|
12
|
+
placeholder="placeholder"
|
|
13
|
+
onKeyDown={onKeyDown}
|
|
14
|
+
/>
|
|
15
|
+
)
|
|
16
|
+
|
|
17
|
+
fireEvent.keyDown(
|
|
18
|
+
screen.getByTestId('dhis2-uicore-multiselect-placeholder'),
|
|
19
|
+
{ key: 'Enter', code: 'Enter', charCode: 13 }
|
|
20
|
+
)
|
|
21
|
+
|
|
22
|
+
expect(onKeyDown).toHaveBeenCalledWith(
|
|
23
|
+
{ selected: [] },
|
|
24
|
+
expect.objectContaining({})
|
|
25
|
+
)
|
|
26
|
+
|
|
27
|
+
expect(onKeyDown).toHaveBeenCalledTimes(1)
|
|
28
|
+
})
|
|
29
|
+
})
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { Given, Then } from '@badeball/cypress-cucumber-preprocessor'
|
|
2
|
+
|
|
3
|
+
Given('a MultiSelectField with help text is rendered', () => {
|
|
4
|
+
cy.visitStory('MultiSelectField', 'With help text')
|
|
5
|
+
})
|
|
6
|
+
|
|
7
|
+
Then('the help text is visible', () => {
|
|
8
|
+
cy.contains('The help text').should('be.visible')
|
|
9
|
+
})
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { Given, Then } from '@badeball/cypress-cucumber-preprocessor'
|
|
2
|
+
|
|
3
|
+
Given('a MultiSelectField with a label is rendered', () => {
|
|
4
|
+
cy.visitStory('MultiSelectField', 'With label')
|
|
5
|
+
})
|
|
6
|
+
|
|
7
|
+
Then('the label is visible', () => {
|
|
8
|
+
cy.contains('The label').should('be.visible')
|
|
9
|
+
})
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { Given, Then } from '@badeball/cypress-cucumber-preprocessor'
|
|
2
|
+
|
|
3
|
+
Given('a MultiSelectField with validation text is rendered', () => {
|
|
4
|
+
cy.visitStory('MultiSelectField', 'With validation text')
|
|
5
|
+
})
|
|
6
|
+
|
|
7
|
+
Then('the validation text is visible', () => {
|
|
8
|
+
cy.contains('The validation text').should('be.visible')
|
|
9
|
+
})
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { Given, Then } from '@badeball/cypress-cucumber-preprocessor'
|
|
2
|
+
|
|
3
|
+
Given('a MultiSelectField with label and a required flag is rendered', () => {
|
|
4
|
+
cy.visitStory('MultiSelectField', 'With label and required status')
|
|
5
|
+
})
|
|
6
|
+
|
|
7
|
+
Then('the required indicator is visible', () => {
|
|
8
|
+
cy.get(
|
|
9
|
+
'[data-test="dhis2-uiwidgets-multiselectfield-label-required"]'
|
|
10
|
+
).should('be.visible')
|
|
11
|
+
})
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { Given, When, Then } from '@badeball/cypress-cucumber-preprocessor'
|
|
2
|
+
|
|
3
|
+
Given('a clearable MultiSelectField with selected option is rendered', () => {
|
|
4
|
+
cy.visitStory('MultiSelectField', 'With clearable and selected option')
|
|
5
|
+
})
|
|
6
|
+
|
|
7
|
+
When('the clear button is hovered', () => {
|
|
8
|
+
cy.get('[data-test="dhis2-uicore-multiselect-clear"]').trigger(
|
|
9
|
+
'mouseover',
|
|
10
|
+
'top'
|
|
11
|
+
)
|
|
12
|
+
})
|
|
13
|
+
|
|
14
|
+
Then('the clear text is visible', () => {
|
|
15
|
+
cy.contains('Clear').should('be.visible')
|
|
16
|
+
})
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { Given, Then, When } from '@badeball/cypress-cucumber-preprocessor'
|
|
2
|
+
|
|
3
|
+
Given('an empty MultiSelectField is rendered', () => {
|
|
4
|
+
cy.visitStory('MultiSelectField', 'Without options')
|
|
5
|
+
})
|
|
6
|
+
|
|
7
|
+
When('the Select is opened', () => {
|
|
8
|
+
cy.get('[data-test="dhis2-uicore-select-input"]').click()
|
|
9
|
+
})
|
|
10
|
+
|
|
11
|
+
Then('the empty text is visible', () => {
|
|
12
|
+
cy.contains('No data found').should('be.visible')
|
|
13
|
+
})
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { Given, Then, When } from '@badeball/cypress-cucumber-preprocessor'
|
|
2
|
+
|
|
3
|
+
Given('a filterable MultiSelectField is rendered', () => {
|
|
4
|
+
cy.visitStory('MultiSelectField', 'With filterable')
|
|
5
|
+
})
|
|
6
|
+
|
|
7
|
+
When('the Select is opened', () => {
|
|
8
|
+
cy.get('[data-test="dhis2-uicore-select-input"]').click()
|
|
9
|
+
})
|
|
10
|
+
|
|
11
|
+
When('a filter that does not match any options is entered', () => {
|
|
12
|
+
cy.focused().type('Two')
|
|
13
|
+
})
|
|
14
|
+
|
|
15
|
+
Then('the no match text is visible', () => {
|
|
16
|
+
cy.contains('No options found').should('be.visible')
|
|
17
|
+
})
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
Feature: Nomatchtext for the MultiSelectField
|
|
2
|
+
|
|
3
|
+
Scenario: Rendering a filterable MultiSelectField
|
|
4
|
+
Given a filterable MultiSelectField is rendered
|
|
5
|
+
When the Select is opened
|
|
6
|
+
And a filter that does not match any options is entered
|
|
7
|
+
Then the no match text is visible
|