Skip to content

Commit 2347971

Browse files
committed
SHARED(Frontend): More intuitive autocomplete behaviour.
1 parent b82c28b commit 2347971

File tree

3 files changed

+24
-2
lines changed

3 files changed

+24
-2
lines changed

frontend/packages/shared/CHANGELOG.MD

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,12 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
99

1010
## [Released]
1111

12+
## [1.9.29] - 2023-10-20
13+
14+
### Changed
15+
16+
- Changed behaviour of ComboBox autocomplete: spaces are trimmed from search input and matching is only performed against the start of option labels
17+
1218
## [1.9.28] - 2023-10-05
1319

1420
### Changed

frontend/packages/shared/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@opetushallitus/kieli-ja-kaantajatutkinnot.shared",
3-
"version": "1.9.28",
3+
"version": "1.9.29",
44
"description": "Shared Frontend Package",
55
"exports": {
66
"./components": "./src/components/index.tsx",

frontend/packages/shared/src/components/ComboBox/ComboBox.tsx

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import {
22
Autocomplete,
33
AutocompleteProps,
4+
createFilterOptions,
5+
FilterOptionsState,
46
FormControl,
57
FormHelperText,
68
TextField,
@@ -23,7 +25,11 @@ interface ComboBoxProps {
2325

2426
type AutoCompleteComboBox = Omit<
2527
AutocompleteProps<AutocompleteValue, false, false, false>,
26-
'options' | 'renderInput'
28+
| 'options'
29+
| 'renderInput'
30+
| 'getOptionLabel'
31+
| 'isOptionEqualToValue'
32+
| 'filterOptions'
2733
>;
2834

2935
const compareOptionLabels = (a: ComboBoxOption, b: ComboBoxOption) => {
@@ -47,6 +53,14 @@ const isOptionEqualToValue = (
4753
}
4854
};
4955

56+
const filterOptions: (
57+
options: Array<AutocompleteValue>,
58+
state: FilterOptionsState<AutocompleteValue>
59+
) => Array<AutocompleteValue> = createFilterOptions({
60+
matchFrom: 'start',
61+
trim: true,
62+
});
63+
5064
export const valueAsOption = (value: string) => ({
5165
value: value,
5266
label: value,
@@ -74,6 +88,7 @@ export const ComboBox = ({
7488
getOptionLabel={getOptionLabel}
7589
isOptionEqualToValue={isOptionEqualToValue}
7690
options={values}
91+
filterOptions={filterOptions}
7792
renderInput={(params) => (
7893
<TextField
7994
{...params}
@@ -119,6 +134,7 @@ export const LabeledComboBox = ({
119134
getOptionLabel={getOptionLabel}
120135
isOptionEqualToValue={isOptionEqualToValue}
121136
options={values}
137+
filterOptions={filterOptions}
122138
renderInput={(params) => (
123139
<TextField
124140
{...params}

0 commit comments

Comments
 (0)