@inseefr/lunatic 3.12.2 → 3.12.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/components/Dropdown/Dropdown.js +1 -2
- package/components/Dropdown/Dropdown.js.map +1 -1
- package/components/Dropdown/Dropdown.spec.js +13 -5
- package/components/Dropdown/Dropdown.spec.js.map +1 -1
- package/components/Suggester/CustomSuggester.d.ts +6 -0
- package/components/Suggester/CustomSuggester.js +1 -1
- package/components/Suggester/CustomSuggester.js.map +1 -1
- package/components/shared/Combobox/Combobox.js +5 -6
- package/components/shared/Combobox/Combobox.js.map +1 -1
- package/components/shared/Combobox/ComboboxType.d.ts +1 -0
- package/components/shared/Combobox/Panel/ComboboxOption.d.ts +1 -0
- package/components/shared/Combobox/Panel/ComboboxOption.js +4 -4
- package/components/shared/Combobox/Panel/ComboboxOption.js.map +1 -1
- package/components/shared/Combobox/Panel/ComboboxOption.spec.js +18 -5
- package/components/shared/Combobox/Panel/ComboboxOption.spec.js.map +1 -1
- package/components/shared/Combobox/Panel/ComboboxPanel.d.ts +1 -1
- package/components/shared/Combobox/Panel/ComboboxPanel.js +2 -2
- package/components/shared/Combobox/Panel/ComboboxPanel.js.map +1 -1
- package/components/type.d.ts +6 -0
- package/esm/components/Dropdown/Dropdown.js +1 -2
- package/esm/components/Dropdown/Dropdown.js.map +1 -1
- package/esm/components/Dropdown/Dropdown.spec.js +14 -6
- package/esm/components/Dropdown/Dropdown.spec.js.map +1 -1
- package/esm/components/Suggester/CustomSuggester.d.ts +6 -0
- package/esm/components/Suggester/CustomSuggester.js +1 -1
- package/esm/components/Suggester/CustomSuggester.js.map +1 -1
- package/esm/components/shared/Combobox/Combobox.js +5 -6
- package/esm/components/shared/Combobox/Combobox.js.map +1 -1
- package/esm/components/shared/Combobox/ComboboxType.d.ts +1 -0
- package/esm/components/shared/Combobox/Panel/ComboboxOption.d.ts +1 -0
- package/esm/components/shared/Combobox/Panel/ComboboxOption.js +5 -5
- package/esm/components/shared/Combobox/Panel/ComboboxOption.js.map +1 -1
- package/esm/components/shared/Combobox/Panel/ComboboxOption.spec.js +18 -5
- package/esm/components/shared/Combobox/Panel/ComboboxOption.spec.js.map +1 -1
- package/esm/components/shared/Combobox/Panel/ComboboxPanel.d.ts +1 -1
- package/esm/components/shared/Combobox/Panel/ComboboxPanel.js +2 -2
- package/esm/components/shared/Combobox/Panel/ComboboxPanel.js.map +1 -1
- package/esm/components/type.d.ts +6 -0
- package/package.json +2 -9
- package/src/components/Dropdown/Dropdown.spec.tsx +22 -6
- package/src/components/Dropdown/Dropdown.tsx +1 -2
- package/src/components/Dropdown/__snapshots__/Dropdown.spec.tsx.snap +2 -2
- package/src/components/Suggester/CustomSuggester.tsx +7 -0
- package/src/components/shared/Combobox/Combobox.tsx +5 -4
- package/src/components/shared/Combobox/ComboboxType.ts +1 -0
- package/src/components/shared/Combobox/Panel/ComboboxOption.spec.tsx +27 -5
- package/src/components/shared/Combobox/Panel/ComboboxOption.tsx +10 -6
- package/src/components/shared/Combobox/Panel/ComboboxPanel.tsx +3 -1
- package/src/components/type.ts +6 -0
- package/tsconfig.build.tsbuildinfo +1 -1
- package/components/Dropdown/renderer/SimpleOptionRenderer.d.ts +0 -7
- package/components/Dropdown/renderer/SimpleOptionRenderer.js +0 -16
- package/components/Dropdown/renderer/SimpleOptionRenderer.js.map +0 -1
- package/esm/components/Dropdown/renderer/SimpleOptionRenderer.d.ts +0 -7
- package/esm/components/Dropdown/renderer/SimpleOptionRenderer.js +0 -10
- package/esm/components/Dropdown/renderer/SimpleOptionRenderer.js.map +0 -1
- package/src/components/Dropdown/renderer/SimpleOptionRenderer.tsx +0 -26
|
@@ -11,13 +11,26 @@ describe('DefaultOptionRenderer', () => {
|
|
|
11
11
|
expect(idElement).toBeInTheDocument();
|
|
12
12
|
expect(labelElement).toBeNull();
|
|
13
13
|
});
|
|
14
|
-
it('renders with label', () => {
|
|
14
|
+
it('renders with label and displays id by default', () => {
|
|
15
15
|
const option = { id: '1', value: 'Value', label: 'Label' };
|
|
16
16
|
const { getByText } = render(_jsx(ComboboxOption, { option: option }));
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
expect(
|
|
20
|
-
|
|
17
|
+
expect(getByText(option.id)).toBeInTheDocument();
|
|
18
|
+
expect(getByText('-')).toBeInTheDocument();
|
|
19
|
+
expect(getByText(option.label)).toBeInTheDocument();
|
|
20
|
+
});
|
|
21
|
+
it('renders with label and displays id when prop is true', () => {
|
|
22
|
+
const option = { id: '1', value: 'Value', label: 'Label' };
|
|
23
|
+
const { getByText } = render(_jsx(ComboboxOption, { option: option, shouldDisplayOptionId: true }));
|
|
24
|
+
expect(getByText(option.id)).toBeInTheDocument();
|
|
25
|
+
expect(getByText('-')).toBeInTheDocument();
|
|
26
|
+
expect(getByText(option.label)).toBeInTheDocument();
|
|
27
|
+
});
|
|
28
|
+
it('renders with label and does not display id when prop is false', () => {
|
|
29
|
+
const option = { id: '1', value: 'Value', label: 'Label' };
|
|
30
|
+
const { getByText, queryByText } = render(_jsx(ComboboxOption, { option: option, shouldDisplayOptionId: false }));
|
|
31
|
+
expect(queryByText(option.id)).not.toBeInTheDocument();
|
|
32
|
+
expect(queryByText('-')).not.toBeInTheDocument();
|
|
33
|
+
expect(getByText(option.label)).toBeInTheDocument();
|
|
21
34
|
});
|
|
22
35
|
it('renders with selected class', () => {
|
|
23
36
|
const option = { id: '1', value: 'Value', label: 'Label' };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ComboboxOption.spec.js","sourceRoot":"","sources":["../../../../../src/components/shared/Combobox/Panel/ComboboxOption.spec.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,wBAAwB,CAAC;AAChD,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAClD,OAAO,EAAE,QAAQ,EAAE,EAAE,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAE9C,QAAQ,CAAC,uBAAuB,EAAE,GAAG,EAAE;IACtC,EAAE,CAAC,uBAAuB,EAAE,GAAG,EAAE;QAChC,MAAM,MAAM,GAAG,EAAE,EAAE,EAAE,GAAG,EAAE,KAAK,EAAE,OAAO,EAAE,CAAC;QAC3C,MAAM,EAAE,SAAS,EAAE,WAAW,EAAE,GAAG,MAAM,CACxC,KAAC,cAAc,IAAC,MAAM,EAAE,MAAM,GAAI,CAClC,CAAC;QACF,MAAM,SAAS,GAAG,SAAS,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC;QACvC,MAAM,YAAY,GAAG,WAAW,CAAC,GAAG,CAAC,CAAC;QACtC,MAAM,CAAC,SAAS,CAAC,CAAC,iBAAiB,EAAE,CAAC;QACtC,MAAM,CAAC,YAAY,CAAC,CAAC,QAAQ,EAAE,CAAC;IACjC,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,
|
|
1
|
+
{"version":3,"file":"ComboboxOption.spec.js","sourceRoot":"","sources":["../../../../../src/components/shared/Combobox/Panel/ComboboxOption.spec.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,wBAAwB,CAAC;AAChD,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAClD,OAAO,EAAE,QAAQ,EAAE,EAAE,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAE9C,QAAQ,CAAC,uBAAuB,EAAE,GAAG,EAAE;IACtC,EAAE,CAAC,uBAAuB,EAAE,GAAG,EAAE;QAChC,MAAM,MAAM,GAAG,EAAE,EAAE,EAAE,GAAG,EAAE,KAAK,EAAE,OAAO,EAAE,CAAC;QAC3C,MAAM,EAAE,SAAS,EAAE,WAAW,EAAE,GAAG,MAAM,CACxC,KAAC,cAAc,IAAC,MAAM,EAAE,MAAM,GAAI,CAClC,CAAC;QACF,MAAM,SAAS,GAAG,SAAS,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC;QACvC,MAAM,YAAY,GAAG,WAAW,CAAC,GAAG,CAAC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,CAAC,SAAS,CAAC,UAAU,CAAC,CAAC,GAAG,CAAC,WAAW,CAAC,UAAU,CAAC,CAAC;IAC1D,CAAC,CAAC,CAAC;AACJ,CAAC,CAAC,CAAC"}
|
|
@@ -2,4 +2,4 @@ import type { ComboboxPanelProps } from '../ComboboxType';
|
|
|
2
2
|
/**
|
|
3
3
|
* Floating menu containing selectable options
|
|
4
4
|
*/
|
|
5
|
-
export declare function ComboboxPanel({ optionRenderer: OptionRender, options, focused, selectedIndex, expanded, id, search, onSelect, isLoading, }: ComboboxPanelProps): import("react/jsx-runtime").JSX.Element | null;
|
|
5
|
+
export declare function ComboboxPanel({ optionRenderer: OptionRender, options, shouldDisplayOptionsId, focused, selectedIndex, expanded, id, search, onSelect, isLoading, }: Readonly<ComboboxPanelProps>): import("react/jsx-runtime").JSX.Element | null;
|
|
@@ -6,7 +6,7 @@ import D from '../../../../i18n';
|
|
|
6
6
|
/**
|
|
7
7
|
* Floating menu containing selectable options
|
|
8
8
|
*/
|
|
9
|
-
export function ComboboxPanel({ optionRenderer: OptionRender, options = [], focused, selectedIndex, expanded, id, search, onSelect, isLoading, }) {
|
|
9
|
+
export function ComboboxPanel({ optionRenderer: OptionRender, options = [], shouldDisplayOptionsId, focused, selectedIndex, expanded, id, search, onSelect, isLoading, }) {
|
|
10
10
|
const visibleOptions = expanded ? options : [];
|
|
11
11
|
const ComboBoxOptionComponent = OptionRender !== null && OptionRender !== void 0 ? OptionRender : ComboboxOption;
|
|
12
12
|
// Do not display the panel if it's empty
|
|
@@ -24,7 +24,7 @@ export function ComboboxPanel({ optionRenderer: OptionRender, options = [], focu
|
|
|
24
24
|
}
|
|
25
25
|
return (_jsx(ComboboxPanelContainer, { expanded: expanded, focused: focused, id: `${id}-list`, children: visibleOptions.map((option, index) => {
|
|
26
26
|
var _a;
|
|
27
|
-
return (_jsx(ComboboxOptionContainer, { index: index.toString(), selected: selectedIndex === index, onSelect: onSelect, children: _jsx(ComboBoxOptionComponent, { option: option, selected: selectedIndex === index, search: search }) }, (_a = option.id) !== null && _a !== void 0 ? _a : option.value));
|
|
27
|
+
return (_jsx(ComboboxOptionContainer, { index: index.toString(), selected: selectedIndex === index, onSelect: onSelect, children: _jsx(ComboBoxOptionComponent, { option: option, shouldDisplayOptionId: shouldDisplayOptionsId, selected: selectedIndex === index, search: search }) }, (_a = option.id) !== null && _a !== void 0 ? _a : option.value));
|
|
28
28
|
}) }));
|
|
29
29
|
}
|
|
30
30
|
//# sourceMappingURL=ComboboxPanel.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ComboboxPanel.js","sourceRoot":"","sources":["../../../../../src/components/shared/Combobox/Panel/ComboboxPanel.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,uBAAuB,EAAE,MAAM,2BAA2B,CAAC;AAEpE,OAAO,EAAE,sBAAsB,EAAE,MAAM,0BAA0B,CAAC;AAClE,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAClD,OAAO,CAAC,MAAM,kBAAkB,CAAC;AAEjC;;GAEG;AACH,MAAM,UAAU,aAAa,CAAC,EAC7B,cAAc,EAAE,YAAY,EAC5B,OAAO,GAAG,EAAE,EACZ,OAAO,EACP,aAAa,EACb,QAAQ,EACR,EAAE,EACF,MAAM,EACN,QAAQ,EACR,SAAS,
|
|
1
|
+
{"version":3,"file":"ComboboxPanel.js","sourceRoot":"","sources":["../../../../../src/components/shared/Combobox/Panel/ComboboxPanel.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,uBAAuB,EAAE,MAAM,2BAA2B,CAAC;AAEpE,OAAO,EAAE,sBAAsB,EAAE,MAAM,0BAA0B,CAAC;AAClE,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAClD,OAAO,CAAC,MAAM,kBAAkB,CAAC;AAEjC;;GAEG;AACH,MAAM,UAAU,aAAa,CAAC,EAC7B,cAAc,EAAE,YAAY,EAC5B,OAAO,GAAG,EAAE,EACZ,sBAAsB,EAC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Q,GACjD,GACkB,CACzB,CAAC;IACH,CAAC;IAED,OAAO,CACN,KAAC,sBAAsB,IACtB,QAAQ,EAAE,QAAQ,EAClB,OAAO,EAAE,OAAO,EAChB,EAAE,EAAE,GAAG,EAAE,OAAO,YAEf,cAAc,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,KAAK,EAAE,EAAE;;YAAC,OAAA,CACtC,KAAC,uBAAuB,IAEvB,KAAK,EAAE,KAAK,CAAC,QAAQ,EAAE,EACvB,QAAQ,EAAE,aAAa,KAAK,KAAK,EACjC,QAAQ,EAAE,QAAQ,YAElB,KAAC,uBAAuB,IACvB,MAAM,EAAE,MAAM,EACd,qBAAqB,EAAE,sBAAsB,EAC7C,QAAQ,EAAE,aAAa,KAAK,KAAK,EACjC,MAAM,EAAE,MAAM,GACb,IAVG,MAAA,MAAM,CAAC,EAAE,mCAAI,MAAM,CAAC,KAAK,CAWL,CAC1B,CAAA;SAAA,CAAC,GACsB,CACzB,CAAC;AACH,CAAC"}
|
package/esm/components/type.d.ts
CHANGED
|
@@ -265,11 +265,17 @@ export type ComponentPropsByType = {
|
|
|
265
265
|
Suggester: LunaticBaseProps<string | null> & {
|
|
266
266
|
componentType?: 'Suggester';
|
|
267
267
|
storeName: string;
|
|
268
|
+
/**
|
|
269
|
+
* @deprecated use createCustomizableField with ComboboxOptionRenderer as name.
|
|
270
|
+
*/
|
|
268
271
|
optionRenderer: FunctionComponent<{
|
|
269
272
|
option: SuggesterOption;
|
|
270
273
|
placeholder?: string;
|
|
271
274
|
search?: string;
|
|
272
275
|
}>;
|
|
276
|
+
/**
|
|
277
|
+
* @deprecated use createCustomizableField with ComboboxLabelRenderer as name.
|
|
278
|
+
*/
|
|
273
279
|
labelRenderer: FunctionComponent<{
|
|
274
280
|
option?: SuggesterOption;
|
|
275
281
|
selected?: boolean;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@inseefr/lunatic",
|
|
3
|
-
"version": "3.12.
|
|
3
|
+
"version": "3.12.3",
|
|
4
4
|
"description": "Library of questionnaire components",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -51,7 +51,6 @@
|
|
|
51
51
|
"src/components/Dropdown/Dropdown.tsx",
|
|
52
52
|
"src/components/Dropdown/__snapshots__/Dropdown.spec.tsx.snap",
|
|
53
53
|
"src/components/Dropdown/renderer/SimpleLabelRenderer.tsx",
|
|
54
|
-
"src/components/Dropdown/renderer/SimpleOptionRenderer.tsx",
|
|
55
54
|
"src/components/Duration/Duration.test.tsx",
|
|
56
55
|
"src/components/Duration/Duration.tsx",
|
|
57
56
|
"src/components/Duration/durationUtils.ts",
|
|
@@ -511,9 +510,6 @@
|
|
|
511
510
|
"components/Dropdown/renderer/SimpleLabelRenderer.d.ts",
|
|
512
511
|
"components/Dropdown/renderer/SimpleLabelRenderer.js",
|
|
513
512
|
"components/Dropdown/renderer/SimpleLabelRenderer.js.map",
|
|
514
|
-
"components/Dropdown/renderer/SimpleOptionRenderer.d.ts",
|
|
515
|
-
"components/Dropdown/renderer/SimpleOptionRenderer.js",
|
|
516
|
-
"components/Dropdown/renderer/SimpleOptionRenderer.js.map",
|
|
517
513
|
"components/Duration/Duration.d.ts",
|
|
518
514
|
"components/Duration/Duration.js",
|
|
519
515
|
"components/Duration/Duration.js.map",
|
|
@@ -946,9 +942,6 @@
|
|
|
946
942
|
"esm/components/Dropdown/renderer/SimpleLabelRenderer.d.ts",
|
|
947
943
|
"esm/components/Dropdown/renderer/SimpleLabelRenderer.js",
|
|
948
944
|
"esm/components/Dropdown/renderer/SimpleLabelRenderer.js.map",
|
|
949
|
-
"esm/components/Dropdown/renderer/SimpleOptionRenderer.d.ts",
|
|
950
|
-
"esm/components/Dropdown/renderer/SimpleOptionRenderer.js",
|
|
951
|
-
"esm/components/Dropdown/renderer/SimpleOptionRenderer.js.map",
|
|
952
945
|
"esm/components/Duration/Duration.d.ts",
|
|
953
946
|
"esm/components/Duration/Duration.js",
|
|
954
947
|
"esm/components/Duration/Duration.js.map",
|
|
@@ -2111,4 +2104,4 @@
|
|
|
2111
2104
|
"node": "20.16.0",
|
|
2112
2105
|
"pnpm": "9.15.0"
|
|
2113
2106
|
}
|
|
2114
|
-
}
|
|
2107
|
+
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { render } from '@testing-library/react';
|
|
1
|
+
import { fireEvent, render } from '@testing-library/react';
|
|
2
2
|
import { beforeEach, describe, expect, it, vi } from 'vitest';
|
|
3
3
|
import { Dropdown } from './Dropdown';
|
|
4
4
|
|
|
@@ -6,14 +6,14 @@ describe('Dropdown', () => {
|
|
|
6
6
|
const mockOnSelect = vi.fn();
|
|
7
7
|
|
|
8
8
|
const baseProps = {
|
|
9
|
-
value: '
|
|
9
|
+
value: 'value1',
|
|
10
10
|
id: 'dropdown',
|
|
11
11
|
'aria-labelledby': 'dropdown',
|
|
12
12
|
options: [
|
|
13
13
|
{
|
|
14
|
-
value: '
|
|
15
|
-
description: '
|
|
16
|
-
label: '
|
|
14
|
+
value: 'value1',
|
|
15
|
+
description: 'description 1',
|
|
16
|
+
label: 'option 1',
|
|
17
17
|
},
|
|
18
18
|
],
|
|
19
19
|
response: { name: 'demo' },
|
|
@@ -37,6 +37,22 @@ describe('Dropdown', () => {
|
|
|
37
37
|
(selection as HTMLElement).focus();
|
|
38
38
|
expect(selection).toHaveFocus();
|
|
39
39
|
const span = selection?.querySelector('span');
|
|
40
|
-
expect(span).toHaveTextContent('
|
|
40
|
+
expect(span).toHaveTextContent('option 1');
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
it('should display only options label in dropdown selection', () => {
|
|
44
|
+
const { container, queryByText, getByText } = render(
|
|
45
|
+
<Dropdown
|
|
46
|
+
{...baseProps}
|
|
47
|
+
value={null}
|
|
48
|
+
/>
|
|
49
|
+
);
|
|
50
|
+
|
|
51
|
+
const selection = container.querySelector('.lunatic-combo-box-content');
|
|
52
|
+
fireEvent.focus(selection as HTMLElement);
|
|
53
|
+
|
|
54
|
+
expect(getByText('option 1')).toBeInTheDocument();
|
|
55
|
+
expect(queryByText('value1')).not.toBeInTheDocument();
|
|
56
|
+
expect(queryByText('description 1')).not.toBeInTheDocument();
|
|
41
57
|
});
|
|
42
58
|
});
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import type { LunaticComponentProps } from '../type';
|
|
2
2
|
import { getComponentErrors } from '../shared/ComponentErrors/ComponentErrors';
|
|
3
3
|
import { slottableComponent } from '../shared/HOC/slottableComponent';
|
|
4
|
-
import { SimpleOptionRenderer } from './renderer/SimpleOptionRenderer';
|
|
5
4
|
import { SimpleLabelRenderer } from './renderer/SimpleLabelRenderer';
|
|
6
5
|
import { Combobox } from '../shared/Combobox/Combobox';
|
|
7
6
|
import classNames from 'classnames';
|
|
@@ -54,9 +53,9 @@ export const CustomDropdown = slottableComponent<CustomProps>(
|
|
|
54
53
|
disabled={disabled}
|
|
55
54
|
readOnly={readOnly}
|
|
56
55
|
options={options}
|
|
56
|
+
shouldDisplayOptionsId={false}
|
|
57
57
|
editable={false}
|
|
58
58
|
onSelect={onChange}
|
|
59
|
-
optionRenderer={SimpleOptionRenderer}
|
|
60
59
|
labelRenderer={SimpleLabelRenderer}
|
|
61
60
|
value={value}
|
|
62
61
|
label={label}
|
|
@@ -27,7 +27,7 @@ exports[`Dropdown > renders without crashing 1`] = `
|
|
|
27
27
|
<span
|
|
28
28
|
class="selection"
|
|
29
29
|
>
|
|
30
|
-
|
|
30
|
+
option 1
|
|
31
31
|
</span>
|
|
32
32
|
</div>
|
|
33
33
|
</div>
|
|
@@ -63,7 +63,7 @@ exports[`Dropdown > should handle readOnly 1`] = `
|
|
|
63
63
|
<span
|
|
64
64
|
class="selection"
|
|
65
65
|
>
|
|
66
|
-
|
|
66
|
+
option 1
|
|
67
67
|
</span>
|
|
68
68
|
</div>
|
|
69
69
|
</div>
|
|
@@ -15,7 +15,13 @@ type Props = {
|
|
|
15
15
|
onBlur: () => void;
|
|
16
16
|
onFocus: () => void;
|
|
17
17
|
value: [SuggesterOptionType] | [];
|
|
18
|
+
/**
|
|
19
|
+
* @deprecated use createCustomizableField with ComboboxLabelRenderer as name.
|
|
20
|
+
*/
|
|
18
21
|
labelRenderer: LunaticComponentProps<'Suggester'>['labelRenderer'];
|
|
22
|
+
/**
|
|
23
|
+
* @deprecated use createCustomizableField with ComboboxOptionRenderer as name.
|
|
24
|
+
*/
|
|
19
25
|
optionRenderer: LunaticComponentProps<'Suggester'>['optionRenderer'];
|
|
20
26
|
disabled?: boolean;
|
|
21
27
|
readOnly?: boolean;
|
|
@@ -74,6 +80,7 @@ export const CustomSuggester = slottableComponent<Props>(
|
|
|
74
80
|
disabled={disabled}
|
|
75
81
|
readOnly={readOnly}
|
|
76
82
|
options={options.map((o) => ({ value: o.id, ...o }))}
|
|
83
|
+
shouldDisplayOptionsId={true}
|
|
77
84
|
editable={true}
|
|
78
85
|
onBlur={onBlur}
|
|
79
86
|
onFocus={onFocus}
|
|
@@ -57,6 +57,7 @@ function LunaticComboBox({
|
|
|
57
57
|
onSelect,
|
|
58
58
|
value,
|
|
59
59
|
options,
|
|
60
|
+
shouldDisplayOptionsId = true,
|
|
60
61
|
messageError,
|
|
61
62
|
search = EMPTY_SEARCH,
|
|
62
63
|
getOptionValue = getDefaultOptionValue,
|
|
@@ -184,6 +185,7 @@ function LunaticComboBox({
|
|
|
184
185
|
isLoading={isLoading}
|
|
185
186
|
optionRenderer={optionRenderer}
|
|
186
187
|
options={options}
|
|
188
|
+
shouldDisplayOptionsId={shouldDisplayOptionsId}
|
|
187
189
|
focused={focused}
|
|
188
190
|
selectedIndex={selectedIndex}
|
|
189
191
|
expanded={expanded}
|
|
@@ -212,15 +214,14 @@ function getIndexFromOptions(
|
|
|
212
214
|
if (!Array.isArray(options)) {
|
|
213
215
|
return undefined;
|
|
214
216
|
}
|
|
215
|
-
return options.map(getOptionValue).
|
|
217
|
+
return options.map(getOptionValue).indexOf(value ?? '');
|
|
216
218
|
}
|
|
217
219
|
|
|
218
220
|
/**
|
|
219
221
|
* Extract value from an option item
|
|
220
222
|
*/
|
|
221
|
-
function getDefaultOptionValue(option
|
|
222
|
-
|
|
223
|
-
return id || value;
|
|
223
|
+
function getDefaultOptionValue(option?: ComboboxOptionType) {
|
|
224
|
+
return option?.id || option?.value || '';
|
|
224
225
|
}
|
|
225
226
|
|
|
226
227
|
export const Combobox = slottableComponent('Combobox', LunaticComboBox);
|
|
@@ -14,13 +14,35 @@ describe('DefaultOptionRenderer', () => {
|
|
|
14
14
|
expect(labelElement).toBeNull();
|
|
15
15
|
});
|
|
16
16
|
|
|
17
|
-
it('renders with label', () => {
|
|
17
|
+
it('renders with label and displays id by default', () => {
|
|
18
18
|
const option = { id: '1', value: 'Value', label: 'Label' };
|
|
19
19
|
const { getByText } = render(<ComboboxOption option={option} />);
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
expect(
|
|
23
|
-
expect(
|
|
20
|
+
|
|
21
|
+
expect(getByText(option.id)).toBeInTheDocument();
|
|
22
|
+
expect(getByText('-')).toBeInTheDocument();
|
|
23
|
+
expect(getByText(option.label)).toBeInTheDocument();
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
it('renders with label and displays id when prop is true', () => {
|
|
27
|
+
const option = { id: '1', value: 'Value', label: 'Label' };
|
|
28
|
+
const { getByText } = render(
|
|
29
|
+
<ComboboxOption option={option} shouldDisplayOptionId={true} />
|
|
30
|
+
);
|
|
31
|
+
|
|
32
|
+
expect(getByText(option.id)).toBeInTheDocument();
|
|
33
|
+
expect(getByText('-')).toBeInTheDocument();
|
|
34
|
+
expect(getByText(option.label)).toBeInTheDocument();
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
it('renders with label and does not display id when prop is false', () => {
|
|
38
|
+
const option = { id: '1', value: 'Value', label: 'Label' };
|
|
39
|
+
const { getByText, queryByText } = render(
|
|
40
|
+
<ComboboxOption option={option} shouldDisplayOptionId={false} />
|
|
41
|
+
);
|
|
42
|
+
|
|
43
|
+
expect(queryByText(option.id)).not.toBeInTheDocument();
|
|
44
|
+
expect(queryByText('-')).not.toBeInTheDocument();
|
|
45
|
+
expect(getByText(option.label)).toBeInTheDocument();
|
|
24
46
|
});
|
|
25
47
|
|
|
26
48
|
it('renders with selected class', () => {
|
|
@@ -5,12 +5,13 @@ import D from '../../../../i18n';
|
|
|
5
5
|
|
|
6
6
|
type Props = {
|
|
7
7
|
option: ComboboxOptionType;
|
|
8
|
+
shouldDisplayOptionId?: boolean;
|
|
8
9
|
selected?: boolean;
|
|
9
10
|
};
|
|
10
11
|
|
|
11
12
|
export const ComboboxOption = slottableComponent(
|
|
12
13
|
'ComboboxOption',
|
|
13
|
-
({ option, selected }: Props) => {
|
|
14
|
+
({ option, shouldDisplayOptionId = true, selected }: Props) => {
|
|
14
15
|
const { id, value, label } = option;
|
|
15
16
|
|
|
16
17
|
if (value === 'OTHER') {
|
|
@@ -22,19 +23,22 @@ export const ComboboxOption = slottableComponent(
|
|
|
22
23
|
</div>
|
|
23
24
|
);
|
|
24
25
|
}
|
|
25
|
-
|
|
26
|
-
if (label && typeof label === 'string' && label.length) {
|
|
26
|
+
if (label) {
|
|
27
27
|
return (
|
|
28
28
|
<div className={classnames('lunatic-combo-box-option', { selected })}>
|
|
29
|
-
|
|
30
|
-
|
|
29
|
+
{shouldDisplayOptionId && (
|
|
30
|
+
<>
|
|
31
|
+
<span className="id">{id || value}</span>
|
|
32
|
+
<span> - </span>
|
|
33
|
+
</>
|
|
34
|
+
)}
|
|
31
35
|
<span className="label">{label}</span>
|
|
32
36
|
</div>
|
|
33
37
|
);
|
|
34
38
|
}
|
|
35
39
|
return (
|
|
36
40
|
<div className={classnames('lunatic-combo-box-option', { selected })}>
|
|
37
|
-
<span className="id">{id}</span>
|
|
41
|
+
<span className="id">{id || value}</span>
|
|
38
42
|
</div>
|
|
39
43
|
);
|
|
40
44
|
}
|
|
@@ -10,6 +10,7 @@ import D from '../../../../i18n';
|
|
|
10
10
|
export function ComboboxPanel({
|
|
11
11
|
optionRenderer: OptionRender,
|
|
12
12
|
options = [],
|
|
13
|
+
shouldDisplayOptionsId,
|
|
13
14
|
focused,
|
|
14
15
|
selectedIndex,
|
|
15
16
|
expanded,
|
|
@@ -17,7 +18,7 @@ export function ComboboxPanel({
|
|
|
17
18
|
search,
|
|
18
19
|
onSelect,
|
|
19
20
|
isLoading,
|
|
20
|
-
}: ComboboxPanelProps) {
|
|
21
|
+
}: Readonly<ComboboxPanelProps>) {
|
|
21
22
|
const visibleOptions = expanded ? options : [];
|
|
22
23
|
|
|
23
24
|
const ComboBoxOptionComponent = OptionRender ?? ComboboxOption;
|
|
@@ -84,6 +85,7 @@ export function ComboboxPanel({
|
|
|
84
85
|
>
|
|
85
86
|
<ComboBoxOptionComponent
|
|
86
87
|
option={option}
|
|
88
|
+
shouldDisplayOptionId={shouldDisplayOptionsId}
|
|
87
89
|
selected={selectedIndex === index}
|
|
88
90
|
search={search}
|
|
89
91
|
/>
|
package/src/components/type.ts
CHANGED
|
@@ -261,11 +261,17 @@ export type ComponentPropsByType = {
|
|
|
261
261
|
Suggester: LunaticBaseProps<string | null> & {
|
|
262
262
|
componentType?: 'Suggester';
|
|
263
263
|
storeName: string;
|
|
264
|
+
/**
|
|
265
|
+
* @deprecated use createCustomizableField with ComboboxOptionRenderer as name.
|
|
266
|
+
*/
|
|
264
267
|
optionRenderer: FunctionComponent<{
|
|
265
268
|
option: SuggesterOption;
|
|
266
269
|
placeholder?: string;
|
|
267
270
|
search?: string;
|
|
268
271
|
}>;
|
|
272
|
+
/**
|
|
273
|
+
* @deprecated use createCustomizableField with ComboboxLabelRenderer as name.
|
|
274
|
+
*/
|
|
269
275
|
labelRenderer: FunctionComponent<{
|
|
270
276
|
option?: SuggesterOption;
|
|
271
277
|
selected?: boolean;
|